var OrbitDB = /******/ (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__) { 'use strict'; var _promise = __webpack_require__(1); var _promise2 = _interopRequireDefault(_promise); var _assign = __webpack_require__(69); var _assign2 = _interopRequireDefault(_assign); var _classCallCheck2 = __webpack_require__(74); var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); var _createClass2 = __webpack_require__(75); var _createClass3 = _interopRequireDefault(_createClass2); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var EventEmitter = __webpack_require__(79).EventEmitter; var logger = __webpack_require__(80).create("orbit-db.Client"); var EventStore = __webpack_require__(87); var FeedStore = __webpack_require__(103); var KeyValueStore = __webpack_require__(105); var CounterStore = __webpack_require__(107); var PubSub = __webpack_require__(111); var OrbitDB = function () { function OrbitDB(ipfs) { (0, _classCallCheck3.default)(this, OrbitDB); this._ipfs = ipfs; this._pubsub = null; this.user = null; this.network = null; this.events = new EventEmitter(); this.stores = {}; } /* Databases */ (0, _createClass3.default)(OrbitDB, [{ key: 'feed', value: function feed(dbname, options) { return this._createStore(FeedStore, dbname, options); } }, { key: 'eventlog', value: function eventlog(dbname, options) { return this._createStore(EventStore, dbname, options); } }, { key: 'kvstore', value: function kvstore(dbname, options) { return this._createStore(KeyValueStore, dbname, options); } }, { key: 'counter', value: function counter(dbname, options) { return this._createStore(CounterStore, dbname, options); } }, { key: 'disconnect', value: function disconnect() { this._pubsub.disconnect(); this.stores = {}; this.user = null; this.network = null; } }, { key: '_createStore', value: function _createStore(Store, dbname, options) { var _this = this; if (!options) options = {}; if (options.subscribe === undefined) (0, _assign2.default)(options, { subscribe: true }); var store = new Store(this._ipfs, this.user.username, dbname, options); return this._subscribe(store, dbname, options.subscribe).then(function () { return _this.stores[dbname] = store; }).then(function () { return store; }); } }, { key: '_subscribe', value: function _subscribe(store, dbname, subscribe, callback) { var _this2 = this; if (subscribe === undefined) subscribe = true; return store.use(this.user.username).then(function (events) { events.on('readable', _this2._onSync.bind(_this2)); events.on('data', _this2._onWrite.bind(_this2)); events.on('load', _this2._onLoad.bind(_this2)); events.on('close', _this2._onClose.bind(_this2)); if (subscribe) _this2._pubsub.subscribe(dbname, '', _this2._onMessage.bind(_this2)); return; }); } }, { key: '_onMessage', value: function _onMessage(dbname, message) { var store = this.stores[dbname]; store.sync(message).catch(function (e) { return logger.error(e.stack); }); } }, { key: '_onWrite', value: function _onWrite(dbname, hash) { if (!hash) throw new Error("Hash can't be null!"); this._pubsub.publish(dbname, hash); this.events.emit('data', dbname, hash); } }, { key: '_onSync', value: function _onSync(dbname, hash) { this.events.emit('readable', dbname, hash); } }, { key: '_onLoad', value: function _onLoad(dbname, hash) { this.events.emit('load', dbname, hash); } }, { key: '_onClose', value: function _onClose(dbname) { this._pubsub.unsubscribe(dbname); delete this.stores[dbname]; this.events.emit('closed', dbname); } }, { key: '_connect', value: function _connect(hash, username, password, allowOffline) { var _this3 = this; if (allowOffline === undefined) allowOffline = false; var readNetworkInfo = function readNetworkInfo(hash) { return new _promise2.default(function (resolve, reject) { _this3._ipfs.cat(hash).then(function (res) { var buf = ''; res.on('error', function (err) { return reject(err); }).on('data', function (data) { return buf += data; }).on('end', function () { return resolve(buf); }); }); }); }; var host = void 0, port = void 0, name = void 0; return readNetworkInfo(hash).then(function (network) { return JSON.parse(network); }).then(function (network) { _this3.network = network; name = network.name; host = network.publishers[0].split(":")[0]; port = network.publishers[0].split(":")[1]; }).then(function () { _this3._pubsub = new PubSub(); return _this3._pubsub.connect(host, port, username, password); }).then(function () { logger.debug('Connected to Pubsub at \'' + host + ':' + port + '\''); _this3.user = { username: username, id: username }; // TODO: user id from ipfs hash return; }).catch(function (e) { logger.warn("Couldn't connect to Pubsub: " + e.message); if (!allowOffline) { logger.debug("'allowOffline' set to false, terminating"); _this3._pubsub.disconnect(); throw e; } _this3.user = { username: username, id: username }; // TODO: user id from ipfs hash return; }); } }]); return OrbitDB; }(); var OrbitClientFactory = function () { function OrbitClientFactory() { (0, _classCallCheck3.default)(this, OrbitClientFactory); } (0, _createClass3.default)(OrbitClientFactory, null, [{ key: 'connect', value: function connect(network, username, password, ipfs, options) { if (!options) options = { allowOffline: false }; if (!ipfs) { logger.error("IPFS instance not provided"); throw new Error("IPFS instance not provided"); } var client = new OrbitDB(ipfs); return client._connect(network, username, password, options.allowOffline).then(function () { return client; }); } }]); return OrbitClientFactory; }(); module.exports = OrbitClientFactory; /***/ }, /* 1 */ /***/ function(module, exports, __webpack_require__) { module.exports = { "default": __webpack_require__(2), __esModule: true }; /***/ }, /* 2 */ /***/ function(module, exports, __webpack_require__) { __webpack_require__(3); __webpack_require__(4); __webpack_require__(48); __webpack_require__(52); module.exports = __webpack_require__(12).Promise; /***/ }, /* 3 */ /***/ function(module, exports) { /***/ }, /* 4 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; var $at = __webpack_require__(5)(true); // 21.1.3.27 String.prototype[@@iterator]() __webpack_require__(8)(String, 'String', function(iterated){ this._t = String(iterated); // target this._i = 0; // next index // 21.1.5.2.1 %StringIteratorPrototype%.next() }, function(){ var O = this._t , index = this._i , point; if(index >= O.length)return {value: undefined, done: true}; point = $at(O, index); this._i += point.length; return {value: point, done: false}; }); /***/ }, /* 5 */ /***/ function(module, exports, __webpack_require__) { var toInteger = __webpack_require__(6) , defined = __webpack_require__(7); // true -> String#at // false -> String#codePointAt module.exports = function(TO_STRING){ return function(that, pos){ var s = String(defined(that)) , i = toInteger(pos) , l = s.length , a, b; if(i < 0 || i >= l)return TO_STRING ? '' : undefined; a = s.charCodeAt(i); return a < 0xd800 || a > 0xdbff || i + 1 === l || (b = s.charCodeAt(i + 1)) < 0xdc00 || b > 0xdfff ? TO_STRING ? s.charAt(i) : a : TO_STRING ? s.slice(i, i + 2) : (a - 0xd800 << 10) + (b - 0xdc00) + 0x10000; }; }; /***/ }, /* 6 */ /***/ function(module, exports) { // 7.1.4 ToInteger var ceil = Math.ceil , floor = Math.floor; module.exports = function(it){ return isNaN(it = +it) ? 0 : (it > 0 ? floor : ceil)(it); }; /***/ }, /* 7 */ /***/ function(module, exports) { // 7.2.1 RequireObjectCoercible(argument) module.exports = function(it){ if(it == undefined)throw TypeError("Can't call method on " + it); return it; }; /***/ }, /* 8 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; var LIBRARY = __webpack_require__(9) , $export = __webpack_require__(10) , redefine = __webpack_require__(25) , hide = __webpack_require__(15) , has = __webpack_require__(26) , Iterators = __webpack_require__(27) , $iterCreate = __webpack_require__(28) , setToStringTag = __webpack_require__(44) , getPrototypeOf = __webpack_require__(46) , ITERATOR = __webpack_require__(45)('iterator') , BUGGY = !([].keys && 'next' in [].keys()) // Safari has buggy iterators w/o `next` , FF_ITERATOR = '@@iterator' , KEYS = 'keys' , VALUES = 'values'; var returnThis = function(){ return this; }; module.exports = function(Base, NAME, Constructor, next, DEFAULT, IS_SET, FORCED){ $iterCreate(Constructor, NAME, next); var getMethod = function(kind){ if(!BUGGY && kind in proto)return proto[kind]; switch(kind){ case KEYS: return function keys(){ return new Constructor(this, kind); }; case VALUES: return function values(){ return new Constructor(this, kind); }; } return function entries(){ return new Constructor(this, kind); }; }; var TAG = NAME + ' Iterator' , DEF_VALUES = DEFAULT == VALUES , VALUES_BUG = false , proto = Base.prototype , $native = proto[ITERATOR] || proto[FF_ITERATOR] || DEFAULT && proto[DEFAULT] , $default = $native || getMethod(DEFAULT) , $entries = DEFAULT ? !DEF_VALUES ? $default : getMethod('entries') : undefined , $anyNative = NAME == 'Array' ? proto.entries || $native : $native , methods, key, IteratorPrototype; // Fix native if($anyNative){ IteratorPrototype = getPrototypeOf($anyNative.call(new Base)); if(IteratorPrototype !== Object.prototype){ // Set @@toStringTag to native iterators setToStringTag(IteratorPrototype, TAG, true); // fix for some old engines if(!LIBRARY && !has(IteratorPrototype, ITERATOR))hide(IteratorPrototype, ITERATOR, returnThis); } } // fix Array#{values, @@iterator}.name in V8 / FF if(DEF_VALUES && $native && $native.name !== VALUES){ VALUES_BUG = true; $default = function values(){ return $native.call(this); }; } // Define iterator if((!LIBRARY || FORCED) && (BUGGY || VALUES_BUG || !proto[ITERATOR])){ hide(proto, ITERATOR, $default); } // Plug for library Iterators[NAME] = $default; Iterators[TAG] = returnThis; if(DEFAULT){ methods = { values: DEF_VALUES ? $default : getMethod(VALUES), keys: IS_SET ? $default : getMethod(KEYS), entries: $entries }; if(FORCED)for(key in methods){ if(!(key in proto))redefine(proto, key, methods[key]); } else $export($export.P + $export.F * (BUGGY || VALUES_BUG), NAME, methods); } return methods; }; /***/ }, /* 9 */ /***/ function(module, exports) { module.exports = true; /***/ }, /* 10 */ /***/ function(module, exports, __webpack_require__) { var global = __webpack_require__(11) , core = __webpack_require__(12) , ctx = __webpack_require__(13) , hide = __webpack_require__(15) , PROTOTYPE = 'prototype'; var $export = function(type, name, source){ var IS_FORCED = type & $export.F , IS_GLOBAL = type & $export.G , IS_STATIC = type & $export.S , IS_PROTO = type & $export.P , IS_BIND = type & $export.B , IS_WRAP = type & $export.W , exports = IS_GLOBAL ? core : core[name] || (core[name] = {}) , expProto = exports[PROTOTYPE] , target = IS_GLOBAL ? global : IS_STATIC ? global[name] : (global[name] || {})[PROTOTYPE] , key, own, out; if(IS_GLOBAL)source = name; for(key in source){ // contains in native own = !IS_FORCED && target && target[key] !== undefined; if(own && key in exports)continue; // export native or passed out = own ? target[key] : source[key]; // prevent global pollution for namespaces exports[key] = IS_GLOBAL && typeof target[key] != 'function' ? source[key] // bind timers to global for call from export context : IS_BIND && own ? ctx(out, global) // wrap global constructors for prevent change them in library : IS_WRAP && target[key] == out ? (function(C){ var F = function(a, b, c){ if(this instanceof C){ switch(arguments.length){ case 0: return new C; case 1: return new C(a); case 2: return new C(a, b); } return new C(a, b, c); } return C.apply(this, arguments); }; F[PROTOTYPE] = C[PROTOTYPE]; return F; // make static versions for prototype methods })(out) : IS_PROTO && typeof out == 'function' ? ctx(Function.call, out) : out; // export proto methods to core.%CONSTRUCTOR%.methods.%NAME% if(IS_PROTO){ (exports.virtual || (exports.virtual = {}))[key] = out; // export proto methods to core.%CONSTRUCTOR%.prototype.%NAME% if(type & $export.R && expProto && !expProto[key])hide(expProto, key, out); } } }; // type bitmap $export.F = 1; // forced $export.G = 2; // global $export.S = 4; // static $export.P = 8; // proto $export.B = 16; // bind $export.W = 32; // wrap $export.U = 64; // safe $export.R = 128; // real proto method for `library` module.exports = $export; /***/ }, /* 11 */ /***/ function(module, exports) { // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028 var global = module.exports = typeof window != 'undefined' && window.Math == Math ? window : typeof self != 'undefined' && self.Math == Math ? self : Function('return this')(); if(typeof __g == 'number')__g = global; // eslint-disable-line no-undef /***/ }, /* 12 */ /***/ function(module, exports) { var core = module.exports = {version: '2.4.0'}; if(typeof __e == 'number')__e = core; // eslint-disable-line no-undef /***/ }, /* 13 */ /***/ function(module, exports, __webpack_require__) { // optional / simple context binding var aFunction = __webpack_require__(14); module.exports = function(fn, that, length){ aFunction(fn); if(that === undefined)return fn; switch(length){ case 1: return function(a){ return fn.call(that, a); }; case 2: return function(a, b){ return fn.call(that, a, b); }; case 3: return function(a, b, c){ return fn.call(that, a, b, c); }; } return function(/* ...args */){ return fn.apply(that, arguments); }; }; /***/ }, /* 14 */ /***/ function(module, exports) { module.exports = function(it){ if(typeof it != 'function')throw TypeError(it + ' is not a function!'); return it; }; /***/ }, /* 15 */ /***/ function(module, exports, __webpack_require__) { var dP = __webpack_require__(16) , createDesc = __webpack_require__(24); module.exports = __webpack_require__(20) ? function(object, key, value){ return dP.f(object, key, createDesc(1, value)); } : function(object, key, value){ object[key] = value; return object; }; /***/ }, /* 16 */ /***/ function(module, exports, __webpack_require__) { var anObject = __webpack_require__(17) , IE8_DOM_DEFINE = __webpack_require__(19) , toPrimitive = __webpack_require__(23) , dP = Object.defineProperty; exports.f = __webpack_require__(20) ? Object.defineProperty : function defineProperty(O, P, Attributes){ anObject(O); P = toPrimitive(P, true); anObject(Attributes); if(IE8_DOM_DEFINE)try { return dP(O, P, Attributes); } catch(e){ /* empty */ } if('get' in Attributes || 'set' in Attributes)throw TypeError('Accessors not supported!'); if('value' in Attributes)O[P] = Attributes.value; return O; }; /***/ }, /* 17 */ /***/ function(module, exports, __webpack_require__) { var isObject = __webpack_require__(18); module.exports = function(it){ if(!isObject(it))throw TypeError(it + ' is not an object!'); return it; }; /***/ }, /* 18 */ /***/ function(module, exports) { module.exports = function(it){ return typeof it === 'object' ? it !== null : typeof it === 'function'; }; /***/ }, /* 19 */ /***/ function(module, exports, __webpack_require__) { module.exports = !__webpack_require__(20) && !__webpack_require__(21)(function(){ return Object.defineProperty(__webpack_require__(22)('div'), 'a', {get: function(){ return 7; }}).a != 7; }); /***/ }, /* 20 */ /***/ function(module, exports, __webpack_require__) { // Thank's IE8 for his funny defineProperty module.exports = !__webpack_require__(21)(function(){ return Object.defineProperty({}, 'a', {get: function(){ return 7; }}).a != 7; }); /***/ }, /* 21 */ /***/ function(module, exports) { module.exports = function(exec){ try { return !!exec(); } catch(e){ return true; } }; /***/ }, /* 22 */ /***/ function(module, exports, __webpack_require__) { var isObject = __webpack_require__(18) , document = __webpack_require__(11).document // in old IE typeof document.createElement is 'object' , is = isObject(document) && isObject(document.createElement); module.exports = function(it){ return is ? document.createElement(it) : {}; }; /***/ }, /* 23 */ /***/ function(module, exports, __webpack_require__) { // 7.1.1 ToPrimitive(input [, PreferredType]) var isObject = __webpack_require__(18); // instead of the ES6 spec version, we didn't implement @@toPrimitive case // and the second argument - flag - preferred type is a string module.exports = function(it, S){ if(!isObject(it))return it; var fn, val; if(S && typeof (fn = it.toString) == 'function' && !isObject(val = fn.call(it)))return val; if(typeof (fn = it.valueOf) == 'function' && !isObject(val = fn.call(it)))return val; if(!S && typeof (fn = it.toString) == 'function' && !isObject(val = fn.call(it)))return val; throw TypeError("Can't convert object to primitive value"); }; /***/ }, /* 24 */ /***/ function(module, exports) { module.exports = function(bitmap, value){ return { enumerable : !(bitmap & 1), configurable: !(bitmap & 2), writable : !(bitmap & 4), value : value }; }; /***/ }, /* 25 */ /***/ function(module, exports, __webpack_require__) { module.exports = __webpack_require__(15); /***/ }, /* 26 */ /***/ function(module, exports) { var hasOwnProperty = {}.hasOwnProperty; module.exports = function(it, key){ return hasOwnProperty.call(it, key); }; /***/ }, /* 27 */ /***/ function(module, exports) { module.exports = {}; /***/ }, /* 28 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; var create = __webpack_require__(29) , descriptor = __webpack_require__(24) , setToStringTag = __webpack_require__(44) , IteratorPrototype = {}; // 25.1.2.1.1 %IteratorPrototype%[@@iterator]() __webpack_require__(15)(IteratorPrototype, __webpack_require__(45)('iterator'), function(){ return this; }); module.exports = function(Constructor, NAME, next){ Constructor.prototype = create(IteratorPrototype, {next: descriptor(1, next)}); setToStringTag(Constructor, NAME + ' Iterator'); }; /***/ }, /* 29 */ /***/ function(module, exports, __webpack_require__) { // 19.1.2.2 / 15.2.3.5 Object.create(O [, Properties]) var anObject = __webpack_require__(17) , dPs = __webpack_require__(30) , enumBugKeys = __webpack_require__(42) , IE_PROTO = __webpack_require__(39)('IE_PROTO') , Empty = function(){ /* empty */ } , PROTOTYPE = 'prototype'; // Create object with fake `null` prototype: use iframe Object with cleared prototype var createDict = function(){ // Thrash, waste and sodomy: IE GC bug var iframe = __webpack_require__(22)('iframe') , i = enumBugKeys.length , gt = '>' , iframeDocument; iframe.style.display = 'none'; __webpack_require__(43).appendChild(iframe); iframe.src = 'javascript:'; // eslint-disable-line no-script-url // createDict = iframe.contentWindow.Object; // html.removeChild(iframe); iframeDocument = iframe.contentWindow.document; iframeDocument.open(); iframeDocument.write('