|
436 | 436 | var ERR = "Error: Invalid graph!"; |
437 | 437 | var cut = function(s){ return " '"+(''+s).slice(0,9)+"...' " } |
438 | 438 | var L = JSON.stringify, MD = 2147483647, State = Gun.state; |
439 | | - var C = 0, CT, CF = function(){if(C>999 && (C/-(CT - (CT = +new Date))>1)){Gun.window && console.log("Warning: You're syncing 1K+ records a second, faster than DOM can update - consider limiting query.");CF=function(){C=0}}}; |
| 439 | + var C = 0, CT, CF = function(){if(C>999 && (C/-(CT - (CT = +new Date))>1)){Gun.window && console.warn("You're syncing 1K+ records a second, faster than DOM can update - consider limiting query.");CF=function(){C=0}}}; |
440 | 440 |
|
441 | 441 | }()); |
442 | 442 |
|
|
540 | 540 | var obj_each = function(o,f){ Object.keys(o).forEach(f,o) }, text_rand = String.random, turn = setTimeout.turn, valid = Gun.valid, state_is = Gun.state.is, state_ify = Gun.state.ify, u, empty = {}, C; |
541 | 541 |
|
542 | 542 | Gun.log = function(){ return (!Gun.log.off && C.log.apply(C, arguments)), [].slice.call(arguments).join(' ') }; |
| 543 | + Gun.warn = function(){ return (!Gun.log.off && !Gun.warn.off && C.warn.apply(C, arguments)), [].slice.call(arguments).join(' ') }; |
| 544 | + Gun.error = function(){ return (!Gun.log.off && !Gun.error.off && C.error.apply(C, arguments)), [].slice.call(arguments).join(' ') }; |
543 | 545 | Gun.log.once = function(w,s,o){ return (o = Gun.log.once)[w] = o[w] || 0, o[w]++ || Gun.log(s) }; |
| 546 | + Gun.warn.once = function(w,s,o){ return (o = Gun.warn.once)[w] = o[w] || 0, o[w]++ || Gun.warn(s) }; |
| 547 | + Gun.error.once = function(w,s,o){ return (o = Gun.error.once)[w] = o[w] || 0, o[w]++ || Gun.error(s) }; |
544 | 548 |
|
545 | 549 | if(typeof window !== "undefined"){ (window.GUN = window.Gun = Gun).window = window } |
546 | 550 | try{ if(typeof MODULE !== "undefined"){ MODULE.exports = Gun } }catch(e){} |
|
696 | 700 | var root = cat.root, gun = msg.$ || (msg.$ = cat.$), at = (gun||'')._ || empty, tmp = msg.put||'', soul = tmp['#'], key = tmp['.'], change = (u !== tmp['='])? tmp['='] : tmp[':'], state = tmp['>'] || -Infinity, sat; // eve = event, at = data at, cat = chain at, sat = sub at (children chains). |
697 | 701 | if(u !== msg.put && (u === tmp['#'] || u === tmp['.'] || (u === tmp[':'] && u === tmp['=']) || u === tmp['>'])){ // convert from old format |
698 | 702 | if(!valid(tmp)){ |
699 | | - if(!(soul = ((tmp||'')._||'')['#'])){ console.log("chain not yet supported for", tmp, '...', msg, cat); return; } |
| 703 | + if(!(soul = ((tmp||'')._||'')['#'])){ console.warn("chain not yet supported for", tmp, '...', msg, cat); return; } |
700 | 704 | gun = cat.root.$.get(soul); |
701 | 705 | return setTimeout.each(Object.keys(tmp).sort(), function(k){ // TODO: .keys( is slow // BUG? ?Some re-in logic may depend on this being sync? |
702 | 706 | if('_' == k || u === (state = state_is(tmp, k))){ return } |
|
852 | 856 | var gun, tmp; |
853 | 857 | if(typeof key === 'string'){ |
854 | 858 | if(key.length == 0) { |
855 | | - (gun = this.chain())._.err = {err: Gun.log('0 length key!', key)}; |
| 859 | + (gun = this.chain())._.err = {err: Gun.warn('0 length key!', key)}; |
856 | 860 | if(cb){ cb.call(gun, gun._.err) } |
857 | 861 | return gun; |
858 | 862 | } |
|
943 | 947 | gun = tmp(this, key); |
944 | 948 | } |
945 | 949 | if(!gun){ |
946 | | - (gun = this.chain())._.err = {err: Gun.log('Invalid get request!', key)}; // CLEAN UP |
| 950 | + (gun = this.chain())._.err = {err: Gun.warn('Invalid get request!', key)}; // CLEAN UP |
947 | 951 | if(cb){ cb.call(gun, gun._.err) } |
948 | 952 | return gun; |
949 | 953 | } |
|
1254 | 1258 | return gun; |
1255 | 1259 | } |
1256 | 1260 | function none(gun,opt,chain){ |
1257 | | - Gun.log.once("valonce", "Chainable val is experimental, its behavior and API may change moving forward. Please play with it and report bugs and ideas on how to improve it."); |
| 1261 | + Gun.warn.once("valonce", "Chainable val is experimental, its behavior and API may change moving forward. Please play with it and report bugs and ideas on how to improve it."); |
1258 | 1262 | (chain = gun.chain())._.nix = gun.once(function(data, key){ chain._.on('in', this._) }); |
1259 | 1263 | chain._.lex = gun._.lex; // TODO: Better approach in future? This is quick for now. |
1260 | 1264 | return chain; |
|
1329 | 1333 | gun.on('in', map, chain._); |
1330 | 1334 | return chain; |
1331 | 1335 | } |
1332 | | - Gun.log.once("mapfn", "Map functions are experimental, their behavior and API may change moving forward. Please play with it and report bugs and ideas on how to improve it."); |
| 1336 | + Gun.warn.once("mapfn", "Map functions are experimental, their behavior and API may change moving forward. Please play with it and report bugs and ideas on how to improve it."); |
1333 | 1337 | chain = gun.chain(); |
1334 | 1338 | gun.map().on(function(data, key, msg, eve){ |
1335 | 1339 | var next = (cb||noop).call(this, data, key, msg, eve); |
|
1366 | 1370 | } |
1367 | 1371 | gun.put(function(go){ |
1368 | 1372 | item.get(function(soul, o, msg){ // TODO: BUG! We no longer have this option? & go error not handled? |
1369 | | - if(!soul){ return cb.call(gun, {err: Gun.log('Only a node can be linked! Not "' + msg.put + '"!')}) } |
| 1373 | + if(!soul){ return cb.call(gun, {err: Gun.warn('Only a node can be linked! Not "' + msg.put + '"!')}) } |
1370 | 1374 | (tmp = {})[soul] = {'#': soul}; go(tmp); |
1371 | 1375 | },true); |
1372 | 1376 | }) |
|
1380 | 1384 | var noop = function(){} |
1381 | 1385 | var parse = JSON.parseAsync || function(t,cb,r){ var u, d = +new Date; try{ cb(u, JSON.parse(t,r), json.sucks(+new Date - d)) }catch(e){ cb(e) } } |
1382 | 1386 | var json = JSON.stringifyAsync || function(v,cb,r,s){ var u, d = +new Date; try{ cb(u, JSON.stringify(v,r,s), json.sucks(+new Date - d)) }catch(e){ cb(e) } } |
1383 | | - json.sucks = function(d){ if(d > 99){ console.log("Warning: JSON blocking CPU detected. Add `gun/lib/yson.js` to fix."); json.sucks = noop } } |
| 1387 | + json.sucks = function(d){ if(d > 99){ console.warn("JSON blocking CPU detected. Add `gun/lib/yson.js` to fix."); json.sucks = noop } } |
1384 | 1388 |
|
1385 | 1389 | function Mesh(root){ |
1386 | 1390 | var mesh = function(){}; |
1387 | 1391 | var opt = root.opt || {}; |
1388 | 1392 | opt.log = opt.log || console.log; |
| 1393 | + opt.warn = opt.warn || console.warn; |
| 1394 | + opt.error = opt.error || console.error; |
1389 | 1395 | opt.gap = opt.gap || opt.wait || 0; |
1390 | 1396 | opt.max = opt.max || (opt.memory? (opt.memory * 999 * 999) : 300000000) * 0.3; |
1391 | 1397 | opt.pack = opt.pack || (opt.max * 0.01 * 0.01); |
|
1619 | 1625 | if(!tmp){ return } |
1620 | 1626 | if(t? 3 > tmp.length : !tmp.length){ return } // TODO: ^ |
1621 | 1627 | if(!t){try{tmp = (1 === tmp.length? tmp[0] : JSON.stringify(tmp)); |
1622 | | - }catch(e){return opt.log('DAM JSON stringify error', e)}} |
| 1628 | + }catch(e){return opt.error('DAM JSON stringify error', e)}} |
1623 | 1629 | if(!tmp){ return } |
1624 | 1630 | send(tmp, peer); |
1625 | 1631 | } |
|
1667 | 1673 | var tmp = +(new Date); tmp = (tmp - (peer.met||tmp)); |
1668 | 1674 | mesh.bye.time = ((mesh.bye.time || tmp) + tmp) / 2; |
1669 | 1675 | } |
1670 | | - mesh.hear['!'] = function(msg, peer){ opt.log('Error:', msg.err) } |
| 1676 | + mesh.hear['!'] = function(msg, peer){ opt.error('Error:', msg.err) } |
1671 | 1677 | mesh.hear['?'] = function(msg, peer){ |
1672 | 1678 | if(msg.pid){ |
1673 | 1679 | if(!peer.pid){ peer.pid = msg.pid } |
|
1708 | 1714 | if(tmp = console.STAT){ tmp.peers = mesh.near } |
1709 | 1715 | if(opt.super){ return } // temporary (?) until we have better fix/solution? |
1710 | 1716 | var souls = Object.keys(root.next||''); // TODO: .keys( is slow |
1711 | | - if(souls.length > 9999 && !console.SUBS){ console.log(console.SUBS = "Warning: You have more than 10K live GETs, which might use more bandwidth than your screen can show - consider `.off()`.") } |
| 1717 | + if(souls.length > 9999 && !console.SUBS){ console.warn(console.SUBS = "You have more than 10K live GETs, which might use more bandwidth than your screen can show - consider `.off()`.") } |
1712 | 1718 | setTimeout.each(souls, function(soul){ var node = root.next[soul]; |
1713 | 1719 | if(opt.super || (node.ask||'')['']){ mesh.say({get: {'#': soul}}, peer); return } |
1714 | 1720 | setTimeout.each(Object.keys(node.ask||''), function(key){ if(!key){ return } |
|
1794 | 1800 | var noop = function(){}, store, u; |
1795 | 1801 | try{store = (Gun.window||noop).localStorage}catch(e){} |
1796 | 1802 | if(!store){ |
1797 | | - Gun.log("Warning: No localStorage exists to persist data to!"); |
| 1803 | + Gun.warn("No localStorage exists to persist data to!"); |
1798 | 1804 | store = {setItem: function(k,v){this[k]=v}, removeItem: function(k){delete this[k]}, getItem: function(k){return this[k]}}; |
1799 | 1805 | } |
1800 | 1806 |
|
|
1841 | 1847 | try{!err && store.setItem(opt.prefix, tmp); |
1842 | 1848 | }catch(e){ err = stop = e || "localStorage failure" } |
1843 | 1849 | if(err){ |
1844 | | - Gun.log(err + " Consider using GUN's IndexedDB plugin for RAD for more storage space, https://gun.eco/docs/RAD#install"); |
| 1850 | + Gun.error(err + " Consider using GUN's IndexedDB plugin for RAD for more storage space, https://gun.eco/docs/RAD#install"); |
1845 | 1851 | root.on('localStorage:error', {err: err, get: opt.prefix, put: disk}); |
1846 | 1852 | } |
1847 | 1853 | size = tmp.length; |
|
1862 | 1868 | ;(function(){ |
1863 | 1869 | var u; |
1864 | 1870 | if(''+u == typeof Gun){ return } |
1865 | | - var DEP = function(n){ console.warn("Warning! Deprecated internal utility will break in next version:", n) } |
| 1871 | + var DEP = function(n){ console.warn("Deprecated internal utility will break in next version:", n) } |
1866 | 1872 | // Generic javascript utilities. |
1867 | 1873 | var Type = Gun; |
1868 | 1874 | //Type.fns = Type.fn = {is: function(fn){ return (!!fn && fn instanceof Function) }} |
|
0 commit comments