truffle
Version:
Truffle - Simple development framework for Ethereum
1,972 lines (1,699 loc) • 760 kB
JavaScript
#!/usr/bin/env node
exports.id = 2088;
exports.ids = [2088];
exports.modules = {
/***/ 27680:
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
// Copyright 2010-2011 Mikeal Rogers
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
var sys = __webpack_require__(73837)
, fs = __webpack_require__(57147)
, path = __webpack_require__(71017)
, events = __webpack_require__(82361)
;
function walk (dir, options, callback) {
if (!callback) {callback = options; options = {}}
if (!callback.files) callback.files = {};
if (!callback.pending) callback.pending = 0;
callback.pending += 1;
fs.stat(dir, function (err, stat) {
if (err) return callback(err);
callback.files[dir] = stat;
fs.readdir(dir, function (err, files) {
if (err) {
if(err.code === 'EACCES' && options.ignoreUnreadableDir) return callback();
return callback(err);
}
callback.pending -= 1;
files.forEach(function (f, index) {
f = path.join(dir, f);
callback.pending += 1;
fs.stat(f, function (err, stat) {
var enoent = false
, done = false;
if (err) {
if (err.code !== 'ENOENT' && (err.code !== 'EPERM' && options.ignoreNotPermitted)) {
return callback(err);
} else {
enoent = true;
}
}
callback.pending -= 1;
done = callback.pending === 0;
if (!enoent) {
if (options.ignoreDotFiles && path.basename(f)[0] === '.') return done && callback(null, callback.files);
if (options.filter && !options.filter(f, stat)) return done && callback(null, callback.files);
callback.files[f] = stat;
if (stat.isDirectory() && !(options.ignoreDirectoryPattern && options.ignoreDirectoryPattern.test(f))) walk(f, options, callback);
done = callback.pending === 0;
if (done) callback(null, callback.files);
}
})
})
if (callback.pending === 0) callback(null, callback.files);
})
if (callback.pending === 0) callback(null, callback.files);
})
}
var watchedFiles = Object.create(null);
exports.watchTree = function ( root, options, callback ) {
if (!callback) {callback = options; options = {}}
walk(root, options, function (err, files) {
if (err) throw err;
var fileWatcher = function (f) {
var fsOptions = {};
if (options.interval) {
fsOptions.interval = options.interval * 1000;
}
fs.watchFile(f, fsOptions, function (c, p) {
// Check if anything actually changed in stat
if (files[f] && !files[f].isDirectory() && c.nlink !== 0 && files[f].mtime.getTime() == c.mtime.getTime()) return;
files[f] = c;
if (!files[f].isDirectory()) callback(f, c, p);
else {
fs.readdir(f, function (err, nfiles) {
if (err) return;
nfiles.forEach(function (b) {
var file = path.join(f, b);
if (!files[file] && (options.ignoreDotFiles !== true || b[0] != '.')) {
fs.stat(file, function (err, stat) {
if (options.filter && !options.filter(file, stat)) return;
callback(file, stat, null);
files[file] = stat;
fileWatcher(file);
})
}
})
})
}
if (c.nlink === 0) {
// unwatch removed files.
delete files[f]
fs.unwatchFile(f);
}
})
}
fileWatcher(root);
for (var i in files) {
fileWatcher(i);
}
watchedFiles[root] = files;
callback(files, null, null);
})
}
exports.unwatchTree = function (root) {
if (!watchedFiles[root]) return;
Object.keys(watchedFiles[root]).forEach(fs.unwatchFile);
watchedFiles[root] = false;
};
exports.createMonitor = function (root, options, cb) {
if (!cb) {cb = options; options = {}}
var monitor = new events.EventEmitter();
monitor.stop = exports.unwatchTree.bind(null, root);
var prevFile = {file: null,action: null,stat: null};
exports.watchTree(root, options, function (f, curr, prev) {
// if not curr, prev, but f is an object
if (typeof f == "object" && prev == null && curr === null) {
monitor.files = f;
return cb(monitor);
}
// if not prev and either prevFile.file is not f or prevFile.action is not created
if (!prev) {
if (prevFile.file != f || prevFile.action != "created") {
prevFile = { file: f, action: "created", stat: curr };
return monitor.emit("created", f, curr);
}
}
// if curr.nlink is 0 and either prevFile.file is not f or prevFile.action is not removed
if (curr) {
if (curr.nlink === 0) {
if (prevFile.file != f || prevFile.action != "removed") {
prevFile = { file: f, action: "removed", stat: curr };
return monitor.emit("removed", f, curr);
}
}
}
// if prevFile.file is null or prevFile.stat.mtime is not the same as curr.mtime
if (prevFile.file === null) {
return monitor.emit("changed", f, curr, prev);
}
// stat might return null, so catch errors
try {
if (prevFile.stat.mtime.getTime() !== curr.mtime.getTime()) {
return monitor.emit("changed", f, curr, prev);
}
} catch(e) {
return monitor.emit("changed", f, curr, prev);
}
})
}
exports.walk = walk;
/***/ }),
/***/ 99909:
/***/ ((module) => {
"use strict";
/*!
* arr-diff <https://github.com/jonschlinkert/arr-diff>
*
* Copyright (c) 2014-2017, Jon Schlinkert.
* Released under the MIT License.
*/
module.exports = function diff(arr/*, arrays*/) {
var len = arguments.length;
var idx = 0;
while (++idx < len) {
arr = diffArray(arr, arguments[idx]);
}
return arr;
};
function diffArray(one, two) {
if (!Array.isArray(two)) {
return one.slice();
}
var tlen = two.length
var olen = one.length;
var idx = -1;
var arr = [];
while (++idx < olen) {
var ele = one[idx];
var hasEle = false;
for (var i = 0; i < tlen; i++) {
var val = two[i];
if (ele === val) {
hasEle = true;
break;
}
}
if (hasEle === false) {
arr.push(ele);
}
}
return arr;
}
/***/ }),
/***/ 98123:
/***/ ((module) => {
"use strict";
/*!
* arr-flatten <https://github.com/jonschlinkert/arr-flatten>
*
* Copyright (c) 2014-2017, Jon Schlinkert.
* Released under the MIT License.
*/
module.exports = function (arr) {
return flat(arr, []);
};
function flat(arr, res) {
var i = 0, cur;
var len = arr.length;
for (; i < len; i++) {
cur = arr[i];
Array.isArray(cur) ? flat(cur, res) : res.push(cur);
}
return res;
}
/***/ }),
/***/ 3287:
/***/ ((module) => {
"use strict";
module.exports = function union(init) {
if (!Array.isArray(init)) {
throw new TypeError('arr-union expects the first argument to be an array.');
}
var len = arguments.length;
var i = 0;
while (++i < len) {
var arg = arguments[i];
if (!arg) continue;
if (!Array.isArray(arg)) {
arg = [arg];
}
for (var j = 0; j < arg.length; j++) {
var ele = arg[j];
if (init.indexOf(ele) >= 0) {
continue;
}
init.push(ele);
}
}
return init;
};
/***/ }),
/***/ 85302:
/***/ ((module) => {
"use strict";
/*!
* array-unique <https://github.com/jonschlinkert/array-unique>
*
* Copyright (c) 2014-2015, Jon Schlinkert.
* Licensed under the MIT License.
*/
module.exports = function unique(arr) {
if (!Array.isArray(arr)) {
throw new TypeError('array-unique expects an array.');
}
var len = arr.length;
var i = -1;
while (i++ < len) {
var j = i + 1;
for (; j < arr.length; ++j) {
if (arr[i] === arr[j]) {
arr.splice(j--, 1);
}
}
}
return arr;
};
module.exports.immutable = function uniqueImmutable(arr) {
if (!Array.isArray(arr)) {
throw new TypeError('array-unique expects an array.');
}
var arrLen = arr.length;
var newArr = new Array(arrLen);
for (var i = 0; i < arrLen; i++) {
newArr[i] = arr[i];
}
return module.exports(newArr);
};
/***/ }),
/***/ 1052:
/***/ ((module) => {
"use strict";
/*!
* assign-symbols <https://github.com/jonschlinkert/assign-symbols>
*
* Copyright (c) 2015, Jon Schlinkert.
* Licensed under the MIT License.
*/
module.exports = function(receiver, objects) {
if (receiver === null || typeof receiver === 'undefined') {
throw new TypeError('expected first argument to be an object.');
}
if (typeof objects === 'undefined' || typeof Symbol === 'undefined') {
return receiver;
}
if (typeof Object.getOwnPropertySymbols !== 'function') {
return receiver;
}
var isEnumerable = Object.prototype.propertyIsEnumerable;
var target = Object(receiver);
var len = arguments.length, i = 0;
while (++i < len) {
var provider = Object(arguments[i]);
var names = Object.getOwnPropertySymbols(provider);
for (var j = 0; j < names.length; j++) {
var key = names[j];
if (isEnumerable.call(provider, key)) {
target[key] = provider[key];
}
}
}
return target;
};
/***/ }),
/***/ 73825:
/***/ ((module) => {
"use strict";
function atob(str) {
return Buffer.from(str, 'base64').toString('binary');
}
module.exports = atob.atob = atob;
/***/ }),
/***/ 64166:
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
"use strict";
var util = __webpack_require__(73837);
var define = __webpack_require__(74857);
var CacheBase = __webpack_require__(93613);
var Emitter = __webpack_require__(98767);
var isObject = __webpack_require__(37682);
var merge = __webpack_require__(89386);
var pascal = __webpack_require__(58339);
var cu = __webpack_require__(8803);
/**
* Optionally define a custom `cache` namespace to use.
*/
function namespace(name) {
var Cache = name ? CacheBase.namespace(name) : CacheBase;
var fns = [];
/**
* Create an instance of `Base` with the given `config` and `options`.
*
* ```js
* // initialize with `config` and `options`
* var app = new Base({isApp: true}, {abc: true});
* app.set('foo', 'bar');
*
* // values defined with the given `config` object will be on the root of the instance
* console.log(app.baz); //=> undefined
* console.log(app.foo); //=> 'bar'
* // or use `.get`
* console.log(app.get('isApp')); //=> true
* console.log(app.get('foo')); //=> 'bar'
*
* // values defined with the given `options` object will be on `app.options
* console.log(app.options.abc); //=> true
* ```
*
* @param {Object} `config` If supplied, this object is passed to [cache-base][] to merge onto the the instance upon instantiation.
* @param {Object} `options` If supplied, this object is used to initialize the `base.options` object.
* @api public
*/
function Base(config, options) {
if (!(this instanceof Base)) {
return new Base(config, options);
}
Cache.call(this, config);
this.is('base');
this.initBase(config, options);
}
/**
* Inherit cache-base
*/
util.inherits(Base, Cache);
/**
* Add static emitter methods
*/
Emitter(Base);
/**
* Initialize `Base` defaults with the given `config` object
*/
Base.prototype.initBase = function(config, options) {
this.options = merge({}, this.options, options);
this.cache = this.cache || {};
this.define('registered', {});
if (name) this[name] = {};
// make `app._callbacks` non-enumerable
this.define('_callbacks', this._callbacks);
if (isObject(config)) {
this.visit('set', config);
}
Base.run(this, 'use', fns);
};
/**
* Set the given `name` on `app._name` and `app.is*` properties. Used for doing
* lookups in plugins.
*
* ```js
* app.is('foo');
* console.log(app._name);
* //=> 'foo'
* console.log(app.isFoo);
* //=> true
* app.is('bar');
* console.log(app.isFoo);
* //=> true
* console.log(app.isBar);
* //=> true
* console.log(app._name);
* //=> 'bar'
* ```
* @name .is
* @param {String} `name`
* @return {Boolean}
* @api public
*/
Base.prototype.is = function(name) {
if (typeof name !== 'string') {
throw new TypeError('expected name to be a string');
}
this.define('is' + pascal(name), true);
this.define('_name', name);
this.define('_appname', name);
return this;
};
/**
* Returns true if a plugin has already been registered on an instance.
*
* Plugin implementors are encouraged to use this first thing in a plugin
* to prevent the plugin from being called more than once on the same
* instance.
*
* ```js
* var base = new Base();
* base.use(function(app) {
* if (app.isRegistered('myPlugin')) return;
* // do stuff to `app`
* });
*
* // to also record the plugin as being registered
* base.use(function(app) {
* if (app.isRegistered('myPlugin', true)) return;
* // do stuff to `app`
* });
* ```
* @name .isRegistered
* @emits `plugin` Emits the name of the plugin being registered. Useful for unit tests, to ensure plugins are only registered once.
* @param {String} `name` The plugin name.
* @param {Boolean} `register` If the plugin if not already registered, to record it as being registered pass `true` as the second argument.
* @return {Boolean} Returns true if a plugin is already registered.
* @api public
*/
Base.prototype.isRegistered = function(name, register) {
if (this.registered.hasOwnProperty(name)) {
return true;
}
if (register !== false) {
this.registered[name] = true;
this.emit('plugin', name);
}
return false;
};
/**
* Define a plugin function to be called immediately upon init. Plugins are chainable
* and expose the following arguments to the plugin function:
*
* - `app`: the current instance of `Base`
* - `base`: the [first ancestor instance](#base) of `Base`
*
* ```js
* var app = new Base()
* .use(foo)
* .use(bar)
* .use(baz)
* ```
* @name .use
* @param {Function} `fn` plugin function to call
* @return {Object} Returns the item instance for chaining.
* @api public
*/
Base.prototype.use = function(fn) {
fn.call(this, this);
return this;
};
/**
* The `.define` method is used for adding non-enumerable property on the instance.
* Dot-notation is **not supported** with `define`.
*
* ```js
* // arbitrary `render` function using lodash `template`
* app.define('render', function(str, locals) {
* return _.template(str)(locals);
* });
* ```
* @name .define
* @param {String} `key` The name of the property to define.
* @param {any} `value`
* @return {Object} Returns the instance for chaining.
* @api public
*/
Base.prototype.define = function(key, val) {
if (isObject(key)) {
return this.visit('define', key);
}
define(this, key, val);
return this;
};
/**
* Mix property `key` onto the Base prototype. If base is inherited using
* `Base.extend` this method will be overridden by a new `mixin` method that will
* only add properties to the prototype of the inheriting application.
*
* ```js
* app.mixin('foo', function() {
* // do stuff
* });
* ```
* @name .mixin
* @param {String} `key`
* @param {Object|Array} `val`
* @return {Object} Returns the `base` instance for chaining.
* @api public
*/
Base.prototype.mixin = function(key, val) {
Base.prototype[key] = val;
return this;
};
/**
* Non-enumberable mixin array, used by the static [Base.mixin]() method.
*/
Base.prototype.mixins = Base.prototype.mixins || [];
/**
* Getter/setter used when creating nested instances of `Base`, for storing a reference
* to the first ancestor instance. This works by setting an instance of `Base` on the `parent`
* property of a "child" instance. The `base` property defaults to the current instance if
* no `parent` property is defined.
*
* ```js
* // create an instance of `Base`, this is our first ("base") instance
* var first = new Base();
* first.foo = 'bar'; // arbitrary property, to make it easier to see what's happening later
*
* // create another instance
* var second = new Base();
* // create a reference to the first instance (`first`)
* second.parent = first;
*
* // create another instance
* var third = new Base();
* // create a reference to the previous instance (`second`)
* // repeat this pattern every time a "child" instance is created
* third.parent = second;
*
* // we can always access the first instance using the `base` property
* console.log(first.base.foo);
* //=> 'bar'
* console.log(second.base.foo);
* //=> 'bar'
* console.log(third.base.foo);
* //=> 'bar'
* // and now you know how to get to third base ;)
* ```
* @name .base
* @api public
*/
Object.defineProperty(Base.prototype, 'base', {
configurable: true,
get: function() {
return this.parent ? this.parent.base : this;
}
});
/**
* Static method for adding global plugin functions that will
* be added to an instance when created.
*
* ```js
* Base.use(function(app) {
* app.foo = 'bar';
* });
* var app = new Base();
* console.log(app.foo);
* //=> 'bar'
* ```
* @name #use
* @param {Function} `fn` Plugin function to use on each instance.
* @return {Object} Returns the `Base` constructor for chaining
* @api public
*/
define(Base, 'use', function(fn) {
fns.push(fn);
return Base;
});
/**
* Run an array of functions by passing each function
* to a method on the given object specified by the given property.
*
* @param {Object} `obj` Object containing method to use.
* @param {String} `prop` Name of the method on the object to use.
* @param {Array} `arr` Array of functions to pass to the method.
*/
define(Base, 'run', function(obj, prop, arr) {
var len = arr.length, i = 0;
while (len--) {
obj[prop](arr[i++]);
}
return Base;
});
/**
* Static method for inheriting the prototype and static methods of the `Base` class.
* This method greatly simplifies the process of creating inheritance-based applications.
* See [static-extend][] for more details.
*
* ```js
* var extend = cu.extend(Parent);
* Parent.extend(Child);
*
* // optional methods
* Parent.extend(Child, {
* foo: function() {},
* bar: function() {}
* });
* ```
* @name #extend
* @param {Function} `Ctor` constructor to extend
* @param {Object} `methods` Optional prototype properties to mix in.
* @return {Object} Returns the `Base` constructor for chaining
* @api public
*/
define(Base, 'extend', cu.extend(Base, function(Ctor, Parent) {
Ctor.prototype.mixins = Ctor.prototype.mixins || [];
define(Ctor, 'mixin', function(fn) {
var mixin = fn(Ctor.prototype, Ctor);
if (typeof mixin === 'function') {
Ctor.prototype.mixins.push(mixin);
}
return Ctor;
});
define(Ctor, 'mixins', function(Child) {
Base.run(Child, 'mixin', Ctor.prototype.mixins);
return Ctor;
});
Ctor.prototype.mixin = function(key, value) {
Ctor.prototype[key] = value;
return this;
};
return Base;
}));
/**
* Used for adding methods to the `Base` prototype, and/or to the prototype of child instances.
* When a mixin function returns a function, the returned function is pushed onto the `.mixins`
* array, making it available to be used on inheriting classes whenever `Base.mixins()` is
* called (e.g. `Base.mixins(Child)`).
*
* ```js
* Base.mixin(function(proto) {
* proto.foo = function(msg) {
* return 'foo ' + msg;
* };
* });
* ```
* @name #mixin
* @param {Function} `fn` Function to call
* @return {Object} Returns the `Base` constructor for chaining
* @api public
*/
define(Base, 'mixin', function(fn) {
var mixin = fn(Base.prototype, Base);
if (typeof mixin === 'function') {
Base.prototype.mixins.push(mixin);
}
return Base;
});
/**
* Static method for running global mixin functions against a child constructor.
* Mixins must be registered before calling this method.
*
* ```js
* Base.extend(Child);
* Base.mixins(Child);
* ```
* @name #mixins
* @param {Function} `Child` Constructor function of a child class
* @return {Object} Returns the `Base` constructor for chaining
* @api public
*/
define(Base, 'mixins', function(Child) {
Base.run(Child, 'mixin', Base.prototype.mixins);
return Base;
});
/**
* Similar to `util.inherit`, but copies all static properties, prototype properties, and
* getters/setters from `Provider` to `Receiver`. See [class-utils][]{#inherit} for more details.
*
* ```js
* Base.inherit(Foo, Bar);
* ```
* @name #inherit
* @param {Function} `Receiver` Receiving (child) constructor
* @param {Function} `Provider` Providing (parent) constructor
* @return {Object} Returns the `Base` constructor for chaining
* @api public
*/
define(Base, 'inherit', cu.inherit);
define(Base, 'bubble', cu.bubble);
return Base;
}
/**
* Expose `Base` with default settings
*/
module.exports = namespace();
/**
* Allow users to define a namespace
*/
module.exports.namespace = namespace;
/***/ }),
/***/ 74857:
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
"use strict";
/*!
* define-property <https://github.com/jonschlinkert/define-property>
*
* Copyright (c) 2015, 2017, Jon Schlinkert.
* Released under the MIT License.
*/
var isDescriptor = __webpack_require__(59497);
module.exports = function defineProperty(obj, prop, val) {
if (typeof obj !== 'object' && typeof obj !== 'function') {
throw new TypeError('expected an object or function.');
}
if (typeof prop !== 'string') {
throw new TypeError('expected `prop` to be a string.');
}
if (isDescriptor(val) && ('set' in val || 'get' in val)) {
return Object.defineProperty(obj, prop, val);
}
return Object.defineProperty(obj, prop, {
configurable: true,
enumerable: false,
writable: true,
value: val
});
};
/***/ }),
/***/ 12857:
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
/* Copyright 2015-present Facebook, Inc.
* Licensed under the Apache License, Version 2.0 */
var EE = (__webpack_require__(82361).EventEmitter);
var util = __webpack_require__(73837);
var os = __webpack_require__(22037);
var assert = __webpack_require__(39491);
var Int64 = __webpack_require__(50135);
// BSER uses the local endianness to reduce byte swapping overheads
// (the protocol is expressly local IPC only). We need to tell node
// to use the native endianness when reading various native values.
var isBigEndian = os.endianness() == 'BE';
// Find the next power-of-2 >= size
function nextPow2(size) {
return Math.pow(2, Math.ceil(Math.log(size) / Math.LN2));
}
// Expandable buffer that we can provide a size hint for
function Accumulator(initsize) {
this.buf = Buffer.alloc(nextPow2(initsize || 8192));
this.readOffset = 0;
this.writeOffset = 0;
}
// For testing
exports.Accumulator = Accumulator
// How much we can write into this buffer without allocating
Accumulator.prototype.writeAvail = function() {
return this.buf.length - this.writeOffset;
}
// How much we can read
Accumulator.prototype.readAvail = function() {
return this.writeOffset - this.readOffset;
}
// Ensure that we have enough space for size bytes
Accumulator.prototype.reserve = function(size) {
if (size < this.writeAvail()) {
return;
}
// If we can make room by shunting down, do so
if (this.readOffset > 0) {
this.buf.copy(this.buf, 0, this.readOffset, this.writeOffset);
this.writeOffset -= this.readOffset;
this.readOffset = 0;
}
// If we made enough room, no need to allocate more
if (size < this.writeAvail()) {
return;
}
// Allocate a replacement and copy it in
var buf = Buffer.alloc(nextPow2(this.buf.length + size - this.writeAvail()));
this.buf.copy(buf);
this.buf = buf;
}
// Append buffer or string. Will resize as needed
Accumulator.prototype.append = function(buf) {
if (Buffer.isBuffer(buf)) {
this.reserve(buf.length);
buf.copy(this.buf, this.writeOffset, 0, buf.length);
this.writeOffset += buf.length;
} else {
var size = Buffer.byteLength(buf);
this.reserve(size);
this.buf.write(buf, this.writeOffset);
this.writeOffset += size;
}
}
Accumulator.prototype.assertReadableSize = function(size) {
if (this.readAvail() < size) {
throw new Error("wanted to read " + size +
" bytes but only have " + this.readAvail());
}
}
Accumulator.prototype.peekString = function(size) {
this.assertReadableSize(size);
return this.buf.toString('utf-8', this.readOffset, this.readOffset + size);
}
Accumulator.prototype.readString = function(size) {
var str = this.peekString(size);
this.readOffset += size;
return str;
}
Accumulator.prototype.peekInt = function(size) {
this.assertReadableSize(size);
switch (size) {
case 1:
return this.buf.readInt8(this.readOffset, size);
case 2:
return isBigEndian ?
this.buf.readInt16BE(this.readOffset, size) :
this.buf.readInt16LE(this.readOffset, size);
case 4:
return isBigEndian ?
this.buf.readInt32BE(this.readOffset, size) :
this.buf.readInt32LE(this.readOffset, size);
case 8:
var big = this.buf.slice(this.readOffset, this.readOffset + 8);
if (isBigEndian) {
// On a big endian system we can simply pass the buffer directly
return new Int64(big);
}
// Otherwise we need to byteswap
return new Int64(byteswap64(big));
default:
throw new Error("invalid integer size " + size);
}
}
Accumulator.prototype.readInt = function(bytes) {
var ival = this.peekInt(bytes);
if (ival instanceof Int64 && isFinite(ival.valueOf())) {
ival = ival.valueOf();
}
this.readOffset += bytes;
return ival;
}
Accumulator.prototype.peekDouble = function() {
this.assertReadableSize(8);
return isBigEndian ?
this.buf.readDoubleBE(this.readOffset) :
this.buf.readDoubleLE(this.readOffset);
}
Accumulator.prototype.readDouble = function() {
var dval = this.peekDouble();
this.readOffset += 8;
return dval;
}
Accumulator.prototype.readAdvance = function(size) {
if (size > 0) {
this.assertReadableSize(size);
} else if (size < 0 && this.readOffset + size < 0) {
throw new Error("advance with negative offset " + size +
" would seek off the start of the buffer");
}
this.readOffset += size;
}
Accumulator.prototype.writeByte = function(value) {
this.reserve(1);
this.buf.writeInt8(value, this.writeOffset);
++this.writeOffset;
}
Accumulator.prototype.writeInt = function(value, size) {
this.reserve(size);
switch (size) {
case 1:
this.buf.writeInt8(value, this.writeOffset);
break;
case 2:
if (isBigEndian) {
this.buf.writeInt16BE(value, this.writeOffset);
} else {
this.buf.writeInt16LE(value, this.writeOffset);
}
break;
case 4:
if (isBigEndian) {
this.buf.writeInt32BE(value, this.writeOffset);
} else {
this.buf.writeInt32LE(value, this.writeOffset);
}
break;
default:
throw new Error("unsupported integer size " + size);
}
this.writeOffset += size;
}
Accumulator.prototype.writeDouble = function(value) {
this.reserve(8);
if (isBigEndian) {
this.buf.writeDoubleBE(value, this.writeOffset);
} else {
this.buf.writeDoubleLE(value, this.writeOffset);
}
this.writeOffset += 8;
}
var BSER_ARRAY = 0x00;
var BSER_OBJECT = 0x01;
var BSER_STRING = 0x02;
var BSER_INT8 = 0x03;
var BSER_INT16 = 0x04;
var BSER_INT32 = 0x05;
var BSER_INT64 = 0x06;
var BSER_REAL = 0x07;
var BSER_TRUE = 0x08;
var BSER_FALSE = 0x09;
var BSER_NULL = 0x0a;
var BSER_TEMPLATE = 0x0b;
var BSER_SKIP = 0x0c;
var ST_NEED_PDU = 0; // Need to read and decode PDU length
var ST_FILL_PDU = 1; // Know the length, need to read whole content
var MAX_INT8 = 127;
var MAX_INT16 = 32767;
var MAX_INT32 = 2147483647;
function BunserBuf() {
EE.call(this);
this.buf = new Accumulator();
this.state = ST_NEED_PDU;
}
util.inherits(BunserBuf, EE);
exports.BunserBuf = BunserBuf;
BunserBuf.prototype.append = function(buf, synchronous) {
if (synchronous) {
this.buf.append(buf);
return this.process(synchronous);
}
try {
this.buf.append(buf);
} catch (err) {
this.emit('error', err);
return;
}
// Arrange to decode later. This allows the consuming
// application to make progress with other work in the
// case that we have a lot of subscription updates coming
// in from a large tree.
this.processLater();
}
BunserBuf.prototype.processLater = function() {
var self = this;
process.nextTick(function() {
try {
self.process(false);
} catch (err) {
self.emit('error', err);
}
});
}
// Do something with the buffer to advance our state.
// If we're running synchronously we'll return either
// the value we've decoded or undefined if we don't
// yet have enought data.
// If we're running asynchronously, we'll emit the value
// when it becomes ready and schedule another invocation
// of process on the next tick if we still have data we
// can process.
BunserBuf.prototype.process = function(synchronous) {
if (this.state == ST_NEED_PDU) {
if (this.buf.readAvail() < 2) {
return;
}
// Validate BSER header
this.expectCode(0);
this.expectCode(1);
this.pduLen = this.decodeInt(true /* relaxed */);
if (this.pduLen === false) {
// Need more data, walk backwards
this.buf.readAdvance(-2);
return;
}
// Ensure that we have a big enough buffer to read the rest of the PDU
this.buf.reserve(this.pduLen);
this.state = ST_FILL_PDU;
}
if (this.state == ST_FILL_PDU) {
if (this.buf.readAvail() < this.pduLen) {
// Need more data
return;
}
// We have enough to decode it
var val = this.decodeAny();
if (synchronous) {
return val;
}
this.emit('value', val);
this.state = ST_NEED_PDU;
}
if (!synchronous && this.buf.readAvail() > 0) {
this.processLater();
}
}
BunserBuf.prototype.raise = function(reason) {
throw new Error(reason + ", in Buffer of length " +
this.buf.buf.length + " (" + this.buf.readAvail() +
" readable) at offset " + this.buf.readOffset + " buffer: " +
JSON.stringify(this.buf.buf.slice(
this.buf.readOffset, this.buf.readOffset + 32).toJSON()));
}
BunserBuf.prototype.expectCode = function(expected) {
var code = this.buf.readInt(1);
if (code != expected) {
this.raise("expected bser opcode " + expected + " but got " + code);
}
}
BunserBuf.prototype.decodeAny = function() {
var code = this.buf.peekInt(1);
switch (code) {
case BSER_INT8:
case BSER_INT16:
case BSER_INT32:
case BSER_INT64:
return this.decodeInt();
case BSER_REAL:
this.buf.readAdvance(1);
return this.buf.readDouble();
case BSER_TRUE:
this.buf.readAdvance(1);
return true;
case BSER_FALSE:
this.buf.readAdvance(1);
return false;
case BSER_NULL:
this.buf.readAdvance(1);
return null;
case BSER_STRING:
return this.decodeString();
case BSER_ARRAY:
return this.decodeArray();
case BSER_OBJECT:
return this.decodeObject();
case BSER_TEMPLATE:
return this.decodeTemplate();
default:
this.raise("unhandled bser opcode " + code);
}
}
BunserBuf.prototype.decodeArray = function() {
this.expectCode(BSER_ARRAY);
var nitems = this.decodeInt();
var arr = [];
for (var i = 0; i < nitems; ++i) {
arr.push(this.decodeAny());
}
return arr;
}
BunserBuf.prototype.decodeObject = function() {
this.expectCode(BSER_OBJECT);
var nitems = this.decodeInt();
var res = {};
for (var i = 0; i < nitems; ++i) {
var key = this.decodeString();
var val = this.decodeAny();
res[key] = val;
}
return res;
}
BunserBuf.prototype.decodeTemplate = function() {
this.expectCode(BSER_TEMPLATE);
var keys = this.decodeArray();
var nitems = this.decodeInt();
var arr = [];
for (var i = 0; i < nitems; ++i) {
var obj = {};
for (var keyidx = 0; keyidx < keys.length; ++keyidx) {
if (this.buf.peekInt(1) == BSER_SKIP) {
this.buf.readAdvance(1);
continue;
}
var val = this.decodeAny();
obj[keys[keyidx]] = val;
}
arr.push(obj);
}
return arr;
}
BunserBuf.prototype.decodeString = function() {
this.expectCode(BSER_STRING);
var len = this.decodeInt();
return this.buf.readString(len);
}
// This is unusual compared to the other decode functions in that
// we may not have enough data available to satisfy the read, and
// we don't want to throw. This is only true when we're reading
// the PDU length from the PDU header; we'll set relaxSizeAsserts
// in that case.
BunserBuf.prototype.decodeInt = function(relaxSizeAsserts) {
if (relaxSizeAsserts && (this.buf.readAvail() < 1)) {
return false;
} else {
this.buf.assertReadableSize(1);
}
var code = this.buf.peekInt(1);
var size = 0;
switch (code) {
case BSER_INT8:
size = 1;
break;
case BSER_INT16:
size = 2;
break;
case BSER_INT32:
size = 4;
break;
case BSER_INT64:
size = 8;
break;
default:
this.raise("invalid bser int encoding " + code);
}
if (relaxSizeAsserts && (this.buf.readAvail() < 1 + size)) {
return false;
}
this.buf.readAdvance(1);
return this.buf.readInt(size);
}
// synchronously BSER decode a string and return the value
function loadFromBuffer(input) {
var buf = new BunserBuf();
var result = buf.append(input, true);
if (buf.buf.readAvail()) {
throw Error(
'excess data found after input buffer, use BunserBuf instead');
}
if (typeof result === 'undefined') {
throw Error(
'no bser found in string and no error raised!?');
}
return result;
}
exports.loadFromBuffer = loadFromBuffer
// Byteswap an arbitrary buffer, flipping from one endian
// to the other, returning a new buffer with the resultant data
function byteswap64(buf) {
var swap = Buffer.alloc(buf.length);
for (var i = 0; i < buf.length; i++) {
swap[i] = buf[buf.length -1 - i];
}
return swap;
}
function dump_int64(buf, val) {
// Get the raw bytes. The Int64 buffer is big endian
var be = val.toBuffer();
if (isBigEndian) {
// We're a big endian system, so the buffer is exactly how we
// want it to be
buf.writeByte(BSER_INT64);
buf.append(be);
return;
}
// We need to byte swap to get the correct representation
var le = byteswap64(be);
buf.writeByte(BSER_INT64);
buf.append(le);
}
function dump_int(buf, val) {
var abs = Math.abs(val);
if (abs <= MAX_INT8) {
buf.writeByte(BSER_INT8);
buf.writeInt(val, 1);
} else if (abs <= MAX_INT16) {
buf.writeByte(BSER_INT16);
buf.writeInt(val, 2);
} else if (abs <= MAX_INT32) {
buf.writeByte(BSER_INT32);
buf.writeInt(val, 4);
} else {
dump_int64(buf, new Int64(val));
}
}
function dump_any(buf, val) {
switch (typeof(val)) {
case 'number':
// check if it is an integer or a float
if (isFinite(val) && Math.floor(val) === val) {
dump_int(buf, val);
} else {
buf.writeByte(BSER_REAL);
buf.writeDouble(val);
}
return;
case 'string':
buf.writeByte(BSER_STRING);
dump_int(buf, Buffer.byteLength(val));
buf.append(val);
return;
case 'boolean':
buf.writeByte(val ? BSER_TRUE : BSER_FALSE);
return;
case 'object':
if (val === null) {
buf.writeByte(BSER_NULL);
return;
}
if (val instanceof Int64) {
dump_int64(buf, val);
return;
}
if (Array.isArray(val)) {
buf.writeByte(BSER_ARRAY);
dump_int(buf, val.length);
for (var i = 0; i < val.length; ++i) {
dump_any(buf, val[i]);
}
return;
}
buf.writeByte(BSER_OBJECT);
var keys = Object.keys(val);
// First pass to compute number of defined keys
var num_keys = keys.length;
for (var i = 0; i < keys.length; ++i) {
var key = keys[i];
var v = val[key];
if (typeof(v) == 'undefined') {
num_keys--;
}
}
dump_int(buf, num_keys);
for (var i = 0; i < keys.length; ++i) {
var key = keys[i];
var v = val[key];
if (typeof(v) == 'undefined') {
// Don't include it
continue;
}
dump_any(buf, key);
try {
dump_any(buf, v);
} catch (e) {
throw new Error(
e.message + ' (while serializing object property with name `' +
key + "')");
}
}
return;
default:
throw new Error('cannot serialize type ' + typeof(val) + ' to BSER');
}
}
// BSER encode value and return a buffer of the contents
function dumpToBuffer(val) {
var buf = new Accumulator();
// Build out the header
buf.writeByte(0);
buf.writeByte(1);
// Reserve room for an int32 to hold our PDU length
buf.writeByte(BSER_INT32);
buf.writeInt(0, 4); // We'll come back and fill this in at the end
dump_any(buf, val);
// Compute PDU length
var off = buf.writeOffset;
var len = off - 7 /* the header length */;
buf.writeOffset = 3; // The length value to fill in
buf.writeInt(len, 4); // write the length in the space we reserved
buf.writeOffset = off;
return buf.buf.slice(0, off);
}
exports.dumpToBuffer = dumpToBuffer
/***/ }),
/***/ 93613:
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
"use strict";
var isObject = __webpack_require__(37682);
var Emitter = __webpack_require__(98767);
var visit = __webpack_require__(46239);
var toPath = __webpack_require__(20986);
var union = __webpack_require__(41106);
var del = __webpack_require__(12602);
var get = __webpack_require__(43200);
var has = __webpack_require__(4786);
var set = __webpack_require__(41086);
/**
* Create a `Cache` constructor that when instantiated will
* store values on the given `prop`.
*
* ```js
* var Cache = require('cache-base').namespace('data');
* var cache = new Cache();
*
* cache.set('foo', 'bar');
* //=> {data: {foo: 'bar'}}
* ```
* @param {String} `prop` The property name to use for storing values.
* @return {Function} Returns a custom `Cache` constructor
* @api public
*/
function namespace(prop) {
/**
* Create a new `Cache`. Internally the `Cache` constructor is created using
* the `namespace` function, with `cache` defined as the storage object.
*
* ```js
* var app = new Cache();
* ```
* @param {Object} `cache` Optionally pass an object to initialize with.
* @constructor
* @api public
*/
function Cache(cache) {
if (prop) {
this[prop] = {};
}
if (cache) {
this.set(cache);
}
}
/**
* Inherit Emitter
*/
Emitter(Cache.prototype);
/**
* Assign `value` to `key`. Also emits `set` with
* the key and value.
*
* ```js
* app.on('set', function(key, val) {
* // do something when `set` is emitted
* });
*
* app.set(key, value);
*
* // also takes an object or array
* app.set({name: 'Halle'});
* app.set([{foo: 'bar'}, {baz: 'quux'}]);
* console.log(app);
* //=> {name: 'Halle', foo: 'bar', baz: 'quux'}
* ```
*
* @name .set
* @emits `set` with `key` and `value` as arguments.
* @param {String} `key`
* @param {any} `value`
* @return {Object} Returns the instance for chaining.
* @api public
*/
Cache.prototype.set = function(key, val) {
if (Array.isArray(key) && arguments.length === 2) {
key = toPath(key);
}
if (isObject(key) || Array.isArray(key)) {
this.visit('set', key);
} else {
set(prop ? this[prop] : this, key, val);
this.emit('set', key, val);
}
return this;
};
/**
* Union `array` to `key`. Also emits `set` with
* the key and value.
*
* ```js
* app.union('a.b', ['foo']);
* app.union('a.b', ['bar']);
* console.log(app.get('a'));
* //=> {b: ['foo', 'bar']}
* ```
* @name .union
* @param {String} `key`
* @param {any} `value`
* @return {Object} Returns the instance for chaining.
* @api public
*/
Cache.prototype.union = function(key, val) {
if (Array.isArray(key) && arguments.length === 2) {
key = toPath(key);
}
var ctx = prop ? this[prop] : this;
union(ctx, key, arrayify(val));
this.emit('union', val);
return this;
};
/**
* Return the value of `key`. Dot notation may be used
* to get [nested property values][get-value].
*
* ```js
* app.set('a.b.c', 'd');
* app.get('a.b');
* //=> {c: 'd'}
*
* app.get(['a', 'b']);
* //=> {c: 'd'}
* ```
*
* @name .get
* @emits `get` with `key` and `value` as arguments.
* @param {String} `key` The name of the property to get. Dot-notation may be used.
* @return {any} Returns the value of `key`
* @api public
*/
Cache.prototype.get = function(key) {
key = toPath(arguments);
var ctx = prop ? this[prop] : this;
var val = get(ctx, key);
this.emit('get', key, val);
return val;
};
/**
* Return true if app has a stored value for `key`,
* false only if value is `undefined`.
*
* ```js
* app.set('foo', 'bar');
* app.has('foo');
* //=> true
* ```
*
* @name .has
* @emits `has` with `key` and true or false as arguments.
* @param {String} `key`
* @return {Boolean}
* @api public
*/
Cache.prototype.has = function(key) {
key = toPath(arguments);
var ctx = prop ? this[prop] : this;
var val = get(ctx, key);
var has = typeof val !== 'undefined';
this.emit('has', key, has);
return has;
};
/**
* Delete one or more properties from the instance.
*
* ```js
* app.del(); // delete all
* // or
* app.del('foo');
* // or
* app.del(['foo', 'bar']);
* ```
* @name .del
* @emits `del` with the `key` as the only argument.
* @param {String|Array} `key` Property name or array of property names.
* @return {Object} Returns the instance for chaining.
* @api public
*/
Cache.prototype.del = function(key) {
if (Array.isArray(key)) {
this.visit('del', key);
} else {
del(prop ? this[prop] : this, key);
this.emit('del', key);
}
return this;
};
/**
* Reset the entire cache to an empty object.
*
* ```js
* app.clear();
* ```
* @api public
*/
Cache.prototype.clear = function() {
if (prop) {
this[prop] = {};
}
};
/**
* Visit `method` over the properties in the given object, or map
* visit over the object-elements in an array.
*
* @name .visit
* @param {String} `method` The name of the `base` method to call.
* @param {Object|Array} `val` The object or array to iterate over.
* @return {Object} Returns the instance for chaining.
* @api public
*/
Cache.prototype.visit = function(method, val) {
visit(this, method, val);
return this;
};
return Cache;
}
/**
* Cast val to an array
*/
function arrayify(val) {
return val ? (Array.isArray(val) ? val : [val]) : [];
}
/**
* Expose `Cache`
*/
module.exports = namespace();
/**
* Expose `Cache.namespace`
*/
module.exports.namespace = namespace;
/***/ }),
/***/ 46668:
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
var RSVP = __webpack_require__(15176);
var exit;
var handlers = [];
var lastTime;
var isExiting = false;
process.on('beforeExit', function (code) {
if (handlers.length === 0) { return; }
var own = lastTime = module.exports._flush(lastTime, code)
.finally(function () {
// if an onExit handler has called process.exit, do not disturb
// `lastTime`.
//
// Otherwise, clear `lastTime` so that we know to synchronously call the
// real `process.exit` with the given exit code, when our captured
// `process.exit` is called during a `process.on('exit')` handler
//
// This is impossible to reason about, don't feel bad. Just look at
// test-natural-exit-subprocess-error.js
if (own === lastTime) {
lastTime = undefined;
}
});
});
// This exists only for testing
module.exports._reset = function () {
module.exports.releaseExit();
handlers = [];
lastTime = undefined;
isExiting = false;
firstExitCode = undefined;
}
/*
* To allow cooperative async exit handlers, we unfortunately must hijack
* process.exit.
*
* It allows a handler to ensure exit, without that exit handler impeding other
* similar handlers
*
* for example, see: https://github.com/sindresorhus/ora/issues/27
*
*/
module.exports.releaseExit = function() {
if (exit) {
process.exit = exit;
exit = null;
}
};
var firstExitCode;
module.exports.captureExit = function() {
if (exit) {
// already captured, no need to do more work
return;
}
exit = process.exit;
process.exit = function(code) {
if (handlers.length === 0 && lastTime === undefined) {
// synchronously exit.
//
// We do this brecause either
//
// 1. The process exited due to a call to `process.exit` but we have no
// async work to do because no handlers had been attached. It
// doesn't really matter whether we take this branch or not in this
// case.
//
// 2. The process exited naturally. We did our async work during
// `beforeExit` and are in this function because someone else has
// called `process.exit` during an `on('exit')` hook. The only way
// for us to preserve the exit code in this case is to exit
// synchronously.
//
return exit.call(process, code);
}
if (firstExitCode === undefined) {
firstExitCode = code;
}
var own = lastTime = module.exports._flush(lastTime, firstExitCode)
.then(function() {
// if another chain has started, let it exit
if (own !== lastTime) { return; }
exit.call(process, firstExitCode);
})
.catch(function(error) {
// if another chain has started, let it exit
if (own !== lastTime) {
throw error;
}
console.error(error);
exit.call(process, 1);
});
};
};
module.exports._handlers = handlers;
module.exports._flush = function(lastTime, code) {
isExiting = true;
var work = handlers.splice(0, handlers.length);
return RSVP.Promise.resolve(lastTime).
then(function() {
var firstRejected;
return RSVP.allSettled(work.map(function(handler) {
return RSVP.resolve(handler.call(null, code)).catch(function(e) {
if (!firstRejected) {
firstRejected = e;
}
throw e;
});
})).then(function(results) {
if (firstRejected) {
throw firstRejected;
}
});
});
};
module.exports.onExit = function(cb) {
if (!exit) {
throw new Error('Cannot install handler when exit is not captured. Call `captureExit()` first');
}
if (isExiting) {
throw new Error('Cannot install handler while `onExit` handlers are running.');
}
var index = handlers.indexOf(cb);
if (index > -1) { return; }
handlers.push(cb);
};
module.exports.offExit = function(cb) {
var index = handlers.indexOf(cb);
if (index < 0) { return; }
handlers.splice(index, 1);
};
module.exports.exit = function() {
exit.apply(process, arguments);
};
module.exports.listenerCount = function() {
return handlers.length;
};
/***/ }),
/***/ 8803:
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
"use strict";
var util = __webpack_require__(73837);
var union = __webpack_require__(3287);
var define = __webpack_require__(577);
var staticExtend = __webpack_require__(81308);
var isObj = __webpack_require__(37682);
/**
* Expose class utils
*/
var cu = module.exports;
/**
* Expose class utils: `cu`
*/
cu.isObject = function isObject(val) {
return isObj(val) || typeof val === 'function';
};
/**
* Returns true if an array has any of the given elements, or an
* object has any of the give keys.
*
* ```js
* cu.has(['a', 'b', 'c'], 'c');
* //=> true
*
* cu.has(['a', 'b', 'c'], ['c', 'z']);
* //=> true
*
* cu.has({a: 'b', c: 'd'}, ['c', 'z']);
* //=> true
* ```
* @param {Object} `obj`
* @param {String|Array} `val`
* @return {Boolean}
* @api public
*/
cu.has = function has(obj, val) {
val = cu.arrayify(val);
var len = val.length;
if (cu.isObject(ob