UNPKG

base-domain

Version:

simple module to help build Domain-Driven Design

1,950 lines (1,608 loc) 265 kB
/******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) /******/ return installedModules[moduleId].exports; /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ exports: {}, /******/ id: moduleId, /******/ loaded: false /******/ }; /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ // Flag the module as loaded /******/ module.loaded = true; /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ // Load entry module and return exports /******/ return __webpack_require__(0); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ (function(module, exports, __webpack_require__) { module.exports = __webpack_require__(1); /***/ }), /* 1 */ /***/ (function(module, exports, __webpack_require__) { __webpack_require__(2) /***/ }), /* 2 */ /***/ (function(module, exports, __webpack_require__) { var Facade, fsNotFound; Facade = __webpack_require__(3); fsNotFound = function() { throw new Error("module 'fs' is not defined in Browsers."); }; Facade.fs = { existsSync: fsNotFound, readFileSync: fsNotFound, writeFileSync: fsNotFound }; Facade.requireFile = function(file) { throw new Error("requireFile is suppressed in non-node environment. file: " + file); }; Facade.requireJSON = function(file) { throw new Error("requireJSON is suppressed in non-node environment. file: " + file); }; Facade.csvParse = null; module.exports = Facade; /***/ }), /* 3 */ /***/ (function(module, exports, __webpack_require__) { 'use strict'; var BaseModel, BaseModule, CoreModule, Facade, GeneralFactory, MasterDataResource, ModelProps, Util, slice = [].slice; Util = __webpack_require__(4); GeneralFactory = __webpack_require__(14); MasterDataResource = __webpack_require__(27); ModelProps = __webpack_require__(22); BaseModel = __webpack_require__(18); BaseModule = __webpack_require__(34); CoreModule = __webpack_require__(35); /** Facade class of DDD pattern. - create instance of factories - create instance of repositories @class Facade @implements RootInterface @module base-domain */ Facade = (function() { /** is root (to identify RootInterface) @property {Boolean} isRoot @static */ Facade.isRoot = true; /** Get facade @deprecated just use this.facade @method getFacade @return {Facade} @chainable */ Facade.prototype.getFacade = function() { return this; }; /** Latest instance created via @createInstance() This instance will be attached base instances with no @root property. @property {Facade} latestInstance @static */ Facade.latestInstance = null; /** create instance of Facade @method createInstance @static @param {Object} [options] @return {Facade} */ Facade.createInstance = function(options) { var Constructor, instance; if (options == null) { options = {}; } Constructor = this; instance = new Constructor(options); Facade.latestInstance = instance; return instance; }; /** constructor @constructor @param {String} [options] @param {String} [options.dirname="."] path where domain definition files are included @param {Object} [options.preferred={}] @param {Object} [options.preferred.repository] key: firstName, value: repository name used in facade.createPreferredRepository(firstName) @param {Object} [options.preferred.factory] key: firstName, value: factory name used in facade.createPreferredFactory(firstName) @param {Object} [options.preferred.service] key: firstName, value: service name used in facade.createPreferredService(firstName) @param {String|Array(String)} [options.preferred.module] module prefix attached to load preferred class @param {Boolean} [options.master] if true, MasterDataResource is enabled. */ function Facade(options) { var moduleName, path, ref, ref1, ref10, ref2, ref3, ref4, ref5, ref6, ref7, ref8, ref9; if (options == null) { options = {}; } Object.defineProperties(this, { facade: { value: this }, nonExistingClassNames: { value: {} }, classes: { value: {} }, modelProps: { value: {} }, modules: { value: {} }, preferred: { value: { repository: (ref = Util.clone((ref1 = options.preferred) != null ? ref1.repository : void 0)) != null ? ref : {}, factory: (ref2 = Util.clone((ref3 = options.preferred) != null ? ref3.factory : void 0)) != null ? ref2 : {}, service: (ref4 = Util.clone((ref5 = options.preferred) != null ? ref5.service : void 0)) != null ? ref4 : {}, module: (ref6 = options.preferred) != null ? ref6.module : void 0 } } }); this.dirname = (ref7 = options.dirname) != null ? ref7 : '.'; ref9 = Util.clone((ref8 = options.modules) != null ? ref8 : {}); for (moduleName in ref9) { path = ref9[moduleName]; this.modules[moduleName] = new BaseModule(moduleName, path, this); } if (this.modules.core) { throw this.error('invalidModuleName', 'Cannot use "core" as a module name'); } this.modules.core = new CoreModule(this.dirname, this); if (options.master) { /** instance of MasterDataResource Exist only when "master" property is given to Facade's option @property {MasterDataResource} master @optional @readOnly */ this.master = new MasterDataResource(this); } this.init(); if ((ref10 = this.master) != null) { ref10.init(); } } Facade.prototype.init = function() {}; Facade.prototype.initWithPacked = function(packed) { var core, factories, factoryName, klass, klassName, klasses, masterData, modelName, moduleName, modules, ref, ref1; masterData = packed.masterData, core = packed.core, modules = packed.modules, factories = packed.factories; if (masterData && (this.master == null)) { this.master = new MasterDataResource(this); } if ((ref = this.master) != null) { ref.init = function() { return this.initWithData(masterData); }; } for (klassName in core) { klass = core[klassName]; this.addClass(klassName, klass); } for (moduleName in modules) { klasses = modules[moduleName]; for (klassName in klasses) { klass = klasses[klassName]; this.addClass(moduleName + '/' + klassName, klass); } } ref1 = factories != null ? factories : {}; for (modelName in ref1) { factoryName = ref1[modelName]; if (factoryName == null) { this.nonExistingClassNames[modelName + '-factory'] = true; } } return this; }; /** get a model class @method getModel @param {String} firstName @return {Function} */ Facade.prototype.getModel = function(firstName) { return this.require(firstName); }; /** Create instance of given Class. @method create @param {Function|Class} Class @return {Base} */ Facade.prototype.create = function() { var Class, ClassWithConstructor, e, params; Class = arguments[0], params = 2 <= arguments.length ? slice.call(arguments, 1) : []; if (Class.prototype instanceof BaseModel) { try { return this.createModel.apply(this, [Class.className].concat(slice.call(params))); } catch (error) { e = error; throw this.error(e.reason, e.message); } } ClassWithConstructor = Class; while (ClassWithConstructor.length === 0 && ClassWithConstructor !== Object) { ClassWithConstructor = Util.getProto(ClassWithConstructor.prototype).constructor; } while (params.length < ClassWithConstructor.length - 1) { params.push(void 0); } switch (params.length) { case 0: return new Class(this); case 1: return new Class(params[0], this); case 2: return new Class(params[0], params[1], this); case 3: return new Class(params[0], params[1], params[2], this); case 4: return new Class(params[0], params[1], params[2], params[3], this); case 5: return new Class(params[0], params[1], params[2], params[3], params[4], this); case 6: return new Class(params[0], params[1], params[2], params[3], params[4], params[5], this); default: return (function(func, args, ctor) { ctor.prototype = func.prototype; var child = new ctor, result = func.apply(child, args); return Object(result) === result ? result : child; })(Class, slice.call(params).concat([this]), function(){}); } }; /** create an instance of the given modFirstName using obj if obj is null or undefined, empty object will be created. @method createModel @param {String} modFirstName @param {Object} obj @param {Object} [options] @param {RootInterface} [root] @return {BaseModel} */ Facade.prototype.createModel = function(modFirstName, obj, options, root) { return GeneralFactory.createModel(modFirstName, obj, options, root != null ? root : this); }; /** create a factory instance 2nd, 3rd, 4th ... arguments are the params to pass to the constructor of the factory @method createFactory @param {String} modFirstName @return {BaseFactory} */ Facade.prototype.createFactory = function() { var modFirstName, params; modFirstName = arguments[0], params = 2 <= arguments.length ? slice.call(arguments, 1) : []; return this.__create(modFirstName, 'factory', params, this); }; /** create a repository instance 2nd, 3rd, 4th ... arguments are the params to pass to the constructor of the repository @method createRepository @param {String} modFirstName @return {BaseRepository} */ Facade.prototype.createRepository = function() { var modFirstName, params; modFirstName = arguments[0], params = 2 <= arguments.length ? slice.call(arguments, 1) : []; return this.__create(modFirstName, 'repository', params, this); }; /** create a service instance 2nd, 3rd, 4th ... arguments are the params to pass to the constructor of the service @method createService @param {String} modFirstName @return {BaseService} */ Facade.prototype.createService = function() { var modFirstName, params; modFirstName = arguments[0], params = 2 <= arguments.length ? slice.call(arguments, 1) : []; return this.__create(modFirstName, 'service', params, this); }; Facade.prototype.__create = function(modFirstName, type, params, root) { var Class, ClassWithConstructor, modFullName; modFullName = type ? modFirstName + '-' + type : modFirstName; Class = ClassWithConstructor = this.require(modFullName); while (ClassWithConstructor.length === 0 && ClassWithConstructor !== Object) { ClassWithConstructor = Util.getProto(ClassWithConstructor.prototype).constructor; } while (params.length < ClassWithConstructor.length - 1) { params.push(void 0); } switch (params.length) { case 0: return new Class(root != null ? root : this); case 1: return new Class(params[0], root != null ? root : this); case 2: return new Class(params[0], params[1], root != null ? root : this); case 3: return new Class(params[0], params[1], params[2], root != null ? root : this); case 4: return new Class(params[0], params[1], params[2], params[3], root != null ? root : this); case 5: return new Class(params[0], params[1], params[2], params[3], params[4], root != null ? root : this); case 6: return new Class(params[0], params[1], params[2], params[3], params[4], params[5], root != null ? root : this); default: return (function(func, args, ctor) { ctor.prototype = func.prototype; var child = new ctor, result = func.apply(child, args); return Object(result) === result ? result : child; })(Class, slice.call(params).concat([root != null ? root : this]), function(){}); } }; /** create a preferred repository instance 3rd, 4th ... arguments are the params to pass to the constructor of the repository @method createPreferredRepository @param {String} firstName @param {Object} [options] @param {Object} [options.noParent] if true, stop requiring parent class @return {BaseRepository} */ Facade.prototype.createPreferredRepository = function() { var firstName, options, params; firstName = arguments[0], options = arguments[1], params = 3 <= arguments.length ? slice.call(arguments, 2) : []; return this.createPreferred(firstName, 'repository', options, params, this); }; /** create a preferred factory instance 3rd, 4th ... arguments are the params to pass to the constructor of the factory @method createPreferredFactory @param {String} firstName @param {Object} [options] @param {Object} [options.noParent=true] if true, stop requiring parent class @return {BaseFactory} */ Facade.prototype.createPreferredFactory = function() { var firstName, options, params; firstName = arguments[0], options = arguments[1], params = 3 <= arguments.length ? slice.call(arguments, 2) : []; if (options == null) { options = {}; } if (options.noParent == null) { options.noParent = true; } return this.createPreferred(firstName, 'factory', options, params, this); }; /** create a preferred service instance 2nd, 3rd, 4th ... arguments are the params to pass to the constructor of the factory @method createPreferredService @param {String} firstName @param {Object} [options] @param {Object} [options.noParent=true] if true, stop requiring parent class @return {BaseService} */ Facade.prototype.createPreferredService = function() { var firstName, options, params; firstName = arguments[0], options = arguments[1], params = 3 <= arguments.length ? slice.call(arguments, 2) : []; if (options == null) { options = {}; } if (options.noParent == null) { options.noParent = true; } return this.createPreferred(firstName, 'service', options, params, this); }; /** create a preferred factory|repository|service instance @method createPreferred @private @param {String} modFirstName @param {String} type factory|repository|service @param {Object} [options] @param {Object} [params] params pass to constructor of Repository, Factory or Service @param {RootInterface} root @return {BaseFactory} */ Facade.prototype.createPreferred = function(modFirstName, type, options, params, root) { var ParentClass, i, len, modFullName, originalFirstName, ref; if (options == null) { options = {}; } originalFirstName = modFirstName; ref = this.getPreferredNames(modFirstName, type); for (i = 0, len = ref.length; i < len; i++) { modFullName = ref[i]; if (this.hasClass(modFullName)) { return this.__create(modFullName, null, params, root); } } if (!options.noParent) { ParentClass = this.require(modFirstName).getParent(); if (ParentClass.className) { return this.createPreferred(ParentClass.getName(), type, options, params, root); } } throw this.error("preferred" + type + "NotFound", "preferred " + type + " of '" + originalFirstName + "' is not found"); }; /** @method getPreferredNames @private @param {String} modFirstName @param {String} type repository|factory|service @return {String} modFullName */ Facade.prototype.getPreferredNames = function(modFirstName, type) { var names, specific; specific = this.preferred[type][modFirstName]; names = [this.preferred.module, this.moduleName(modFirstName), 'core'].filter(function(v) { return v; }).map((function(_this) { return function(moduleName) { return _this.getModule(moduleName).normalizeName(modFirstName + '-' + type); }; })(this)); if (specific) { names.unshift(specific); } return names; }; /** read a file and returns class @method require @private @param {String} modFullName @return {Function} */ Facade.prototype.require = function(modFullName_o) { var fullName, klass, mod, modFullName, moduleName; modFullName = this.getModule().normalizeName(modFullName_o); if (this.classes[modFullName] != null) { return this.classes[modFullName]; } moduleName = this.moduleName(modFullName); fullName = this.fullName(modFullName); if (!this.nonExistingClassNames[modFullName]) { mod = this.getModule(moduleName); if (mod == null) { throw this.error('moduleNotFound', "module '" + moduleName + "' is not found (requiring '" + fullName + "')"); } klass = mod.requireOwn(fullName); } if (klass == null) { this.nonExistingClassNames[modFullName] = true; modFullName = fullName; klass = this.classes[fullName] || this.getModule().requireOwn(fullName); } if (klass == null) { this.nonExistingClassNames[fullName] = true; throw this.error('modelNotFound', "model '" + modFullName_o + "' is not found"); } this.nonExistingClassNames[modFullName] = false; return this.addClass(modFullName, klass); }; /** @method getModule @param {String} moduleName @return {BaseModule} */ Facade.prototype.getModule = function(moduleName) { if (moduleName == null) { moduleName = 'core'; } return this.modules[moduleName]; }; /** get moduleName from modFullName @method moduleName @private @param {String} modFullName @return {String} */ Facade.prototype.moduleName = function(modFullName) { if (modFullName.match('/')) { return modFullName.split('/')[0]; } else { return 'core'; } }; /** get fullName from modFullName @method fullName @private @param {String} modFullName @return {String} */ Facade.prototype.fullName = function(modFullName) { if (modFullName.match('/')) { return modFullName.split('/')[1]; } else { return modFullName; } }; /** Serialize the given object containing model information @method serialize @param {any} val @return {String} */ Facade.prototype.serialize = function(val) { return Util.serialize(val); }; /** Deserializes serialized string @method deserialize @param {String} str @return {any} */ Facade.prototype.deserialize = function(str) { return Util.deserialize(str, this); }; /** check existence of the class of the given name @method hasClass @param {String} modFullName @return {Function} */ Facade.prototype.hasClass = function(modFullName) { var e; modFullName = this.getModule().normalizeName(modFullName); if (this.nonExistingClassNames[modFullName]) { return false; } try { this.require(modFullName); return true; } catch (error) { e = error; return false; } }; /** add class to facade. the class is acquired by @require(modFullName) @method addClass @private @param {String} modFullName @param {Function} klass @return {Function} */ Facade.prototype.addClass = function(modFullName, klass) { modFullName = this.getModule().normalizeName(modFullName); klass.className = modFullName; klass.moduleName = this.moduleName(modFullName); delete this.nonExistingClassNames[modFullName]; return this.classes[modFullName] = klass; }; /** Get ModelProps by firstName. ModelProps summarizes properties of this class @method getModelProps @param {String} modFullName @return {ModelProps} */ Facade.prototype.getModelProps = function(modFullName) { var Model; if (this.modelProps[modFullName] == null) { Model = this.getModel(modFullName); this.modelProps[modFullName] = new ModelProps(modFullName, Model.properties, this.getModule(this.moduleName(modFullName))); } return this.modelProps[modFullName]; }; /** create instance of DomainError @method error @param {String} reason reason of the error @param {String} [message] @return {Error} */ Facade.prototype.error = function(reason, message) { var DomainError; DomainError = this.constructor.DomainError; return new DomainError(reason, message); }; /** check if given object is instance of DomainError @method isDomainError @param {Error} e @return {Boolean} */ Facade.prototype.isDomainError = function(e) { var DomainError; DomainError = this.constructor.DomainError; return e instanceof DomainError; }; /** insert fixture data (Node.js only) @method insertFixtures @param {Object} [options] @param {String} [options.dataDir='./data'] directory to have fixture data files @param {String} [options.tsvDir='./tsv'] directory to have TSV files @param {Array(String)} [options.models=null] model firstNames to insert. default: all models @return {Promise(EntityPool)} inserted data */ Facade.prototype.insertFixtures = function(options) { var Fixture, fixture; if (options == null) { options = {}; } Fixture = __webpack_require__(36); fixture = new Fixture(this, options); return fixture.insert(options.models); }; Facade.Base = __webpack_require__(20); Facade.BaseModel = __webpack_require__(18); Facade.BaseService = __webpack_require__(37); Facade.ValueObject = __webpack_require__(17); Facade.Entity = __webpack_require__(38); Facade.AggregateRoot = __webpack_require__(39); Facade.Collection = __webpack_require__(16); Facade.BaseList = __webpack_require__(15); Facade.BaseDict = __webpack_require__(26); Facade.BaseFactory = __webpack_require__(40); Facade.BaseRepository = __webpack_require__(41); Facade.BaseSyncRepository = __webpack_require__(42); Facade.BaseAsyncRepository = __webpack_require__(43); Facade.LocalRepository = __webpack_require__(44); Facade.MasterRepository = __webpack_require__(45); Facade.DomainError = __webpack_require__(21); Facade.GeneralFactory = __webpack_require__(14); return Facade; })(); module.exports = Facade; /***/ }), /* 4 */ /***/ (function(module, exports, __webpack_require__) { 'use strict'; var Util, clone, deepEqual; deepEqual = __webpack_require__(5); clone = __webpack_require__(13); /** @method Util */ Util = (function() { function Util() {} /** get __proto__ of the given object @method getProto @static @param {Object} obj @return {Object} __proto__ */ Util.getProto = function(obj) { if (Object.getPrototypeOf != null) { return Object.getPrototypeOf(obj); } else { return obj.__proto__; } }; /** converts hyphenation to camel case 'shinout-no-macbook-pro' => 'ShinoutNoMacbookPro' 'shinout-no-macbook-pro' => 'shinoutNoMacbookPro' # if lowerFirst = true @method camelize @static @param {String} hyphened @param {Boolean} [lowerFirst=false] make capital char lower @return {String} cameled */ Util.camelize = function(hyphened, lowerFirst) { var i, substr; if (lowerFirst == null) { lowerFirst = false; } return ((function() { var j, len, ref, results; ref = hyphened.split('-'); results = []; for (i = j = 0, len = ref.length; j < len; i = ++j) { substr = ref[i]; if (i === 0 && lowerFirst) { results.push(substr); } else { results.push(substr.charAt(0).toUpperCase() + substr.slice(1)); } } return results; })()).join(''); }; /** converts hyphenation to camel case 'ShinoutNoMacbookPro' => 'shinout-no-macbook-pro' 'ABC' => 'a-b-c' # current implementation... FIXME ? @method hyphenize @static @param {String} hyphened @return {String} cameled */ Util.hyphenize = function(cameled) { cameled = cameled.charAt(0).toUpperCase() + cameled.slice(1); return cameled.replace(/([A-Z])/g, function(st) { return '-' + st.charAt(0).toLowerCase(); }).slice(1); }; /** converts instans with toISOString method to ISOString @method modifyDate @static @param {Entity|Object} @return {String} ISOString */ Util.modifyDate = function(data) {}; Util.serialize = function(v) { var attachClassName; return JSON.stringify((attachClassName = function(val, inModel) { var isModel, item, ret; if ((val == null) || typeof val !== 'object') { return val; } if (val.toISOString) { return val.toISOString(); } if (Array.isArray(val)) { return (function() { var j, len, results; results = []; for (j = 0, len = val.length; j < len; j++) { item = val[j]; results.push(attachClassName(item, inModel)); } return results; })(); } ret = {}; isModel = val.constructor.className != null; Object.keys(val).forEach(function(key) { return ret[key] = attachClassName(val[key], isModel || inModel); }); if (val instanceof Error) { ret.stack = val.stack; ret.__errorMessage__ = val.message; } else if (isModel && !inModel) { ret.__className__ = val.constructor.className; } return ret; })(v, false)); }; Util.deserialize = function(str, facade) { var restore; if (str == null) { return str; } return (restore = function(val) { var className, item, key, ret, value; if ((val == null) || typeof val !== 'object') { return val; } if (Array.isArray(val)) { return (function() { var j, len, results; results = []; for (j = 0, len = val.length; j < len; j++) { item = val[j]; results.push(restore(item)); } return results; })(); } if (val.__errorMessage__) { ret = new Error(val.__errorMessage__); for (key in val) { value = val[key]; ret[key] = value; } delete ret.__errorMessage__; return ret; } else if (val.__className__) { className = val.__className__; delete val.__className__; return facade.createModel(className, val); } else { ret = {}; for (key in val) { value = val[key]; ret[key] = restore(value); } return ret; } })(JSON.parse(str)); }; /** in Titanium, "A instanceof B" sometimes fails. this is the alternative. @method isInstance @static @param {Object} instance @param {Function} class @return {Boolean} A is instance of B */ Util.isInstance = function(instance, Class) { var className; if (typeof Ti === "undefined" || Ti === null) { return instance instanceof Class; } if (!(instance != null ? instance.constructor : void 0)) { return false; } if (Class === Object) { return true; } className = Class.name; while (instance.constructor !== Object) { if (instance.constructor.name === className) { return true; } instance = Object.getPrototypeOf(instance); } return false; }; Util.deepEqual = function(a, b) { return deepEqual(a, b); }; Util.clone = function(v) { return clone(v); }; /** Check if the given value is instanceof Promise. "val instanceof Promise" fails when native Promise and its polyfill are mixed */ Util.isPromise = function(val) { return typeof (val != null ? val.then : void 0) === 'function'; }; return Util; })(); module.exports = Util; /***/ }), /* 5 */ /***/ (function(module, exports, __webpack_require__) { module.exports = __webpack_require__(6); /***/ }), /* 6 */ /***/ (function(module, exports, __webpack_require__) { /*! * deep-eql * Copyright(c) 2013 Jake Luer <jake@alogicalparadox.com> * MIT Licensed */ /*! * Module dependencies */ var type = __webpack_require__(7); /*! * Buffer.isBuffer browser shim */ var Buffer; try { Buffer = __webpack_require__(9).Buffer; } catch(ex) { Buffer = {}; Buffer.isBuffer = function() { return false; } } /*! * Primary Export */ module.exports = deepEqual; /** * Assert super-strict (egal) equality between * two objects of any type. * * @param {Mixed} a * @param {Mixed} b * @param {Array} memoised (optional) * @return {Boolean} equal match */ function deepEqual(a, b, m) { if (sameValue(a, b)) { return true; } else if ('date' === type(a)) { return dateEqual(a, b); } else if ('regexp' === type(a)) { return regexpEqual(a, b); } else if (Buffer.isBuffer(a)) { return bufferEqual(a, b); } else if ('arguments' === type(a)) { return argumentsEqual(a, b, m); } else if (!typeEqual(a, b)) { return false; } else if (('object' !== type(a) && 'object' !== type(b)) && ('array' !== type(a) && 'array' !== type(b))) { return sameValue(a, b); } else { return objectEqual(a, b, m); } } /*! * Strict (egal) equality test. Ensures that NaN always * equals NaN and `-0` does not equal `+0`. * * @param {Mixed} a * @param {Mixed} b * @return {Boolean} equal match */ function sameValue(a, b) { if (a === b) return a !== 0 || 1 / a === 1 / b; return a !== a && b !== b; } /*! * Compare the types of two given objects and * return if they are equal. Note that an Array * has a type of `array` (not `object`) and arguments * have a type of `arguments` (not `array`/`object`). * * @param {Mixed} a * @param {Mixed} b * @return {Boolean} result */ function typeEqual(a, b) { return type(a) === type(b); } /*! * Compare two Date objects by asserting that * the time values are equal using `saveValue`. * * @param {Date} a * @param {Date} b * @return {Boolean} result */ function dateEqual(a, b) { if ('date' !== type(b)) return false; return sameValue(a.getTime(), b.getTime()); } /*! * Compare two regular expressions by converting them * to string and checking for `sameValue`. * * @param {RegExp} a * @param {RegExp} b * @return {Boolean} result */ function regexpEqual(a, b) { if ('regexp' !== type(b)) return false; return sameValue(a.toString(), b.toString()); } /*! * Assert deep equality of two `arguments` objects. * Unfortunately, these must be sliced to arrays * prior to test to ensure no bad behavior. * * @param {Arguments} a * @param {Arguments} b * @param {Array} memoize (optional) * @return {Boolean} result */ function argumentsEqual(a, b, m) { if ('arguments' !== type(b)) return false; a = [].slice.call(a); b = [].slice.call(b); return deepEqual(a, b, m); } /*! * Get enumerable properties of a given object. * * @param {Object} a * @return {Array} property names */ function enumerable(a) { var res = []; for (var key in a) res.push(key); return res; } /*! * Simple equality for flat iterable objects * such as Arrays or Node.js buffers. * * @param {Iterable} a * @param {Iterable} b * @return {Boolean} result */ function iterableEqual(a, b) { if (a.length !== b.length) return false; var i = 0; var match = true; for (; i < a.length; i++) { if (a[i] !== b[i]) { match = false; break; } } return match; } /*! * Extension to `iterableEqual` specifically * for Node.js Buffers. * * @param {Buffer} a * @param {Mixed} b * @return {Boolean} result */ function bufferEqual(a, b) { if (!Buffer.isBuffer(b)) return false; return iterableEqual(a, b); } /*! * Block for `objectEqual` ensuring non-existing * values don't get in. * * @param {Mixed} object * @return {Boolean} result */ function isValue(a) { return a !== null && a !== undefined; } /*! * Recursively check the equality of two objects. * Once basic sameness has been established it will * defer to `deepEqual` for each enumerable key * in the object. * * @param {Mixed} a * @param {Mixed} b * @return {Boolean} result */ function objectEqual(a, b, m) { if (!isValue(a) || !isValue(b)) { return false; } if (a.prototype !== b.prototype) { return false; } var i; if (m) { for (i = 0; i < m.length; i++) { if ((m[i][0] === a && m[i][1] === b) || (m[i][0] === b && m[i][1] === a)) { return true; } } } else { m = []; } try { var ka = enumerable(a); var kb = enumerable(b); } catch (ex) { return false; } ka.sort(); kb.sort(); if (!iterableEqual(ka, kb)) { return false; } m.push([ a, b ]); var key; for (i = ka.length - 1; i >= 0; i--) { key = ka[i]; if (!deepEqual(a[key], b[key], m)) { return false; } } return true; } /***/ }), /* 7 */ /***/ (function(module, exports, __webpack_require__) { module.exports = __webpack_require__(8); /***/ }), /* 8 */ /***/ (function(module, exports) { /*! * type-detect * Copyright(c) 2013 jake luer <jake@alogicalparadox.com> * MIT Licensed */ /*! * Primary Exports */ var exports = module.exports = getType; /*! * Detectable javascript natives */ var natives = { '[object Array]': 'array' , '[object RegExp]': 'regexp' , '[object Function]': 'function' , '[object Arguments]': 'arguments' , '[object Date]': 'date' }; /** * ### typeOf (obj) * * Use several different techniques to determine * the type of object being tested. * * * @param {Mixed} object * @return {String} object type * @api public */ function getType (obj) { var str = Object.prototype.toString.call(obj); if (natives[str]) return natives[str]; if (obj === null) return 'null'; if (obj === undefined) return 'undefined'; if (obj === Object(obj)) return 'object'; return typeof obj; } exports.Library = Library; /** * ### Library * * Create a repository for custom type detection. * * ```js * var lib = new type.Library; * ``` * */ function Library () { this.tests = {}; } /** * #### .of (obj) * * Expose replacement `typeof` detection to the library. * * ```js * if ('string' === lib.of('hello world')) { * // ... * } * ``` * * @param {Mixed} object to test * @return {String} type */ Library.prototype.of = getType; /** * #### .define (type, test) * * Add a test to for the `.test()` assertion. * * Can be defined as a regular expression: * * ```js * lib.define('int', /^[0-9]+$/); * ``` * * ... or as a function: * * ```js * lib.define('bln', function (obj) { * if ('boolean' === lib.of(obj)) return true; * var blns = [ 'yes', 'no', 'true', 'false', 1, 0 ]; * if ('string' === lib.of(obj)) obj = obj.toLowerCase(); * return !! ~blns.indexOf(obj); * }); * ``` * * @param {String} type * @param {RegExp|Function} test * @api public */ Library.prototype.define = function (type, test) { if (arguments.length === 1) return this.tests[type]; this.tests[type] = test; return this; }; /** * #### .test (obj, test) * * Assert that an object is of type. Will first * check natives, and if that does not pass it will * use the user defined custom tests. * * ```js * assert(lib.test('1', 'int')); * assert(lib.test('yes', 'bln')); * ``` * * @param {Mixed} object * @param {String} type * @return {Boolean} result * @api public */ Library.prototype.test = function (obj, type) { if (type === getType(obj)) return true; var test = this.tests[type]; if (test && 'regexp' === getType(test)) { return test.test(obj); } else if (test && 'function' === getType(test)) { return test(obj); } else { throw new ReferenceError('Type test "' + type + '" not defined or invalid.'); } }; /***/ }), /* 9 */ /***/ (function(module, exports, __webpack_require__) { /* WEBPACK VAR INJECTION */(function(global) {/*! * The buffer module from node.js, for the browser. * * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org> * @license MIT */ /* eslint-disable no-proto */ 'use strict' var base64 = __webpack_require__(10) var ieee754 = __webpack_require__(11) var isArray = __webpack_require__(12) exports.Buffer = Buffer exports.SlowBuffer = SlowBuffer exports.INSPECT_MAX_BYTES = 50 /** * If `Buffer.TYPED_ARRAY_SUPPORT`: * === true Use Uint8Array implementation (fastest) * === false Use Object implementation (most compatible, even IE6) * * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, * Opera 11.6+, iOS 4.2+. * * Due to various browser bugs, sometimes the Object implementation will be used even * when the browser supports typed arrays. * * Note: * * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances, * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438. * * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function. * * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of * incorrect length in some situations. * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they * get the Object implementation, which is slower but behaves correctly. */ Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined ? global.TYPED_ARRAY_SUPPORT : typedArraySupport() /* * Export kMaxLength after typed array support is determined. */ exports.kMaxLength = kMaxLength() function typedArraySupport () { try { var arr = new Uint8Array(1) arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }} return arr.foo() === 42 && // typed array instances can be augmented typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray` arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray` } catch (e) { return false } } function kMaxLength () { return Buffer.TYPED_ARRAY_SUPPORT ? 0x7fffffff : 0x3fffffff } function createBuffer (that, length) { if (kMaxLength() < length) { throw new RangeError('Invalid typed array length') } if (Buffer.TYPED_ARRAY_SUPPORT) { // Return an augmented `Uint8Array` instance, for best performance that = new Uint8Array(length) that.__proto__ = Buffer.prototype } else { // Fallback: Return an object instance of the Buffer class if (that === null) { that = new Buffer(length) } that.length = length } return that } /** * The Buffer constructor returns instances of `Uint8Array` that have their * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of * `Uint8Array`, so the returned instances will have all the node `Buffer` methods * and the `Uint8Array` methods. Square bracket notation works as expected -- it * returns a single octet. * * The `Uint8Array` prototype remains unmodified. */ function Buffer (arg, encodingOrOffset, length) { if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) { return new Buffer(arg, encodingOrOffset, length) } // Common case. if (typeof arg === 'number') { if (typeof encodingOrOffset === 'string') { throw new Error( 'If encoding is specified then the first argument must be a string' ) } return allocUnsafe(this, arg) } return from(this, arg, encodingOrOffset, length) } Buffer.poolSize = 8192 // not used by this implementation // TODO: Legacy, not needed anymore. Remove in next major version. Buffer._augment = function (arr) { arr.__proto__ = Buffer.prototype return arr } function from (that, value, encodingOrOffset, length) { if (typeof value === 'number') { throw new TypeError('"value" argument must not be a number') } if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) { return fromArrayBuffer(that, value, encodingOrOffset, length) } if (typeof value === 'string') { return fromString(that, value, encodingOrOffset) } return fromObject(that, value) } /** * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError * if value is a number. * Buffer.from(str[, encoding]) * Buffer.from(array) * Buffer.from(buffer) * Buffer.from(arrayBuffer[, byteOffset[, length]]) **/ Buffer.from = function (value, encodingOrOffset, length) { return from(null, value, encodingOrOffset, length) } if (Buffer.TYPED_ARRAY_SUPPORT) { Buffer.prototype.__proto__ = Uint8Array.prototype Buffer.__proto__ = Uint8Array if (typeof Symbol !== 'undefined' && Symbol.species && Buffer[Symbol.species] === Buffer) { // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97 Object.defineProperty(Buffer, Symbol.species, { value: null, configurable: true }) } } function assertSize (size) { if (typeof size !== 'number') { throw new TypeError('"size" argument must be a number') } else if (size < 0) { throw new RangeError('"size" argument must not be negative') } } function alloc (that, size, fill, encoding) { assertSize(size) if (size <= 0) { return createBuffer(that, size) } if (fill !== undefined) { // Only pay attention to encoding if it's a string. This // prevents accidentally sending in a number that would // be interpretted as a start offset. return typeof encoding === 'string' ? createBuffer(that, size).fill(fill, encoding) : createBuffer(that, size).fill(fill) } return createBuffer(that, size) } /** * Creates a new filled Buffer instance. * alloc(size[, fill[, encoding]]) **/ Buffer.alloc = function (size, fill, encoding) { return alloc(null, size, fill, encoding) } function allocUnsafe (that, size) { assertSize(size) that = createBuffer(that, size < 0 ? 0 : checked(size) | 0) if (!Buffer.TYPED_ARRAY_SUPPORT) { for (var i = 0; i < size; ++i) { that[i] = 0 } } return that } /** * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance. * */ Buffer.allocUnsafe = function (size) { return allocUnsafe(null, size) } /** * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. */ Buffer.allocUnsafeSlow = function (size) { return allocUnsafe(null, size) } function fromString (that, string, encoding) { if (typeof encoding !== 'string' || encoding === '') { encoding = 'utf8' } if (!Buffer.isEncoding(encoding)) { throw new TypeError('"encoding" must be a valid string encoding') } var length = byteLength(string, encoding) | 0 that = createBuffer(that, length) var actual = that.write(string, encoding) if (actual !== length) { // Writing a hex string, for example, that contains invalid characters will // cause everything after the first invalid character to be ignored. (e.g. // 'abxxcd' will be treated as 'ab') that = that.slice(0, actual) } return that } function fromArrayLike (that, array) { var length = array.length < 0 ? 0 : checked(array.length) | 0 that = createBuffer(that, length) for (var i = 0; i < length; i += 1) { that[i] = array[i] & 255 } return that } function fromArrayBuffer (that, array, byteOffset, length) { array.byteLength // this throws if `array` is not a valid ArrayBuffer if (byteOffset < 0 || array.byteLength < byteOffset) { throw new RangeError('\'offset\' is out of bounds') } if (array.byteLength < byteOffset + (length || 0)) { throw new RangeError('\'length\' is out of bounds') } if (byteOffset === undefined && length === undefined) { array = new Uint8Array(array) } else if (length === undefined) { array = new Uint8Array(array, byteOffset) } else { array = new Uint8Array(array, byteOffset, length) } if (Buffer.TYPED_ARRAY_SUPPORT) { // Return an augmented `Uint8Array` instance, for best performance that = array that.__proto__ = Buffer.prototype } else { // Fallback: Return an object instance of the Buffer class that = fromArrayLike(that, array) } return that } function fromObject (that, obj) { if (Buffer.isBuffer(obj)) { var len = checked(obj.length) | 0 that = createBuffer(that, len) if (that.length === 0) { return that } obj.copy(that, 0, 0, len) return that } if (obj) { if ((typeof ArrayBuffer !== 'undefined' && obj.buffer instanceof ArrayBuffer) || 'length' in obj) { if (typeof obj.length !== 'number' || isnan(obj.length)) { return createBuffer(that, 0) } return fromArrayLike(that, obj) } if (obj.type === 'Buffer' && isArray(obj.data)) { return fromArrayLike(that, obj.data) } } throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.') } function checked (length) { // Note: cannot use `length < kMaxLength()` here because that fails when // length is NaN (which is otherwise coerced to zero.) if (length >= kMaxLength()) { throw new RangeError('Attempt to allocate Buffer larger than maximum ' + 'size: 0x' + kMaxLength().toString(16) + ' bytes') } return length | 0 } function SlowBuffer (length) { if (+length != length) { // eslint-disable-line eqeqeq length = 0 } return Buffer.alloc(+length) } Buffer.isBuffer = function isBuffer (b) { return !!(b != null && b._isBuffer) } Buffer.compare = function compare (a, b) { if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) { throw new TypeError('Arguments must be Buffers') } if (a === b) return 0 var x = a.length var y = b.length for (var i = 0, len = Math.min(x, y); i < len; ++i) { if (a[i] !== b[i]) { x = a[i] y = b[i] break } } if (x < y) return -1 if (y < x) return 1 return 0 } Buffer.isEncoding = function isEncoding (encoding) { switch (String(encoding).toLowerCase()) { case 'hex': case 'utf8': case 'utf-8': case 'ascii': case 'latin1': case 'binary': case 'base64': case 'ucs2': case 'ucs-2': case 'utf16le': case 'utf-16le': return true default: return false } } Buffer.concat = function concat (list, length) { if (!isArray(list)) { throw new TypeError('"list" argument must be an Array of Buffers') } if (list.length === 0) { return Buffer.alloc(0) } var i if (length === undefined) { length = 0 for (i = 0; i < list.length; ++i) { length += list[i].length } } var buffer = Buffer.allocUnsafe(length) var pos = 0 for (i = 0; i < list.length; ++i) { var buf = list[i] if (!Buffer.isBuffer(buf)) { throw new TypeError('"list" argument must be an Array of Buffers') } buf.copy(buffer, pos) pos += buf.length } return buffer } function byteLength (string, encoding) { if (Buffer.isBuffer(string)) { return string.length } if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' && (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) { return string.byteLength } if (typeof string !== 'string') { string = '' + string } var len = string.length if (len === 0) return 0 // Use a for loop to avoid recursion var loweredCase = false for (;;) { switch (encoding) { case 'ascii': case 'latin1': case 'binary': return len case 'utf8': case 'utf-8': case undefined: return utf8ToBytes(string).length case 'ucs2':