mirror of
https://github.com/amark/gun.git
synced 2025-03-30 15:08:33 +00:00
console.debug -> console.only & unbuild
This commit is contained in:
parent
4fb04b8f53
commit
99ed43f5c4
2
gun.js
2
gun.js
@ -858,7 +858,7 @@
|
||||
var state_lex = Gun.state.lex, _soul = Gun.val.link._, _has = '.', node_ = Gun.node._, rel_is = Gun.val.link.is;
|
||||
var empty = {}, u;
|
||||
|
||||
console.debug = function(i, s){ return (console.debug.i && i === console.debug.i && console.debug.i++) && (console.log.apply(console, arguments) || s) };
|
||||
console.only = function(i, s){ return (console.only.i && i === console.only.i && console.only.i++) && (console.log.apply(console, arguments) || s) };
|
||||
|
||||
Gun.log = function(){ return (!Gun.log.off && console.log.apply(console, arguments)), [].slice.call(arguments).join(' ') }
|
||||
Gun.log.once = function(w,s,o){ return (o = Gun.log.once)[w] = o[w] || 0, o[w]++ || Gun.log(s) }
|
||||
|
2
gun.min.js
vendored
2
gun.min.js
vendored
File diff suppressed because one or more lines are too long
@ -1,6 +1,5 @@
|
||||
function btoa(b) {
|
||||
return new Buffer(b).toString('base64');
|
||||
};
|
||||
|
||||
require('./base64');
|
||||
// This is Array extended to have .toString(['utf8'|'hex'|'base64'])
|
||||
function SeaArray() {}
|
||||
Object.assign(SeaArray, { from: Array.from })
|
||||
|
7
sea/base64.js
Normal file
7
sea/base64.js
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
if(typeof global !== "undefined"){
|
||||
var g = global;
|
||||
g.btoa = function (data) { return Buffer.from(data, "binary").toString("base64"); };
|
||||
g.atob = function (data) { return Buffer.from(data, "base64").toString("binary"); };
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
function atob(a) {
|
||||
return new Buffer(a, 'base64').toString('binary');
|
||||
};
|
||||
|
||||
require('./base64');
|
||||
// This is Buffer implementation used in SEA. Functionality is mostly
|
||||
// compatible with NodeJS 'safe-buffer' and is used for encoding conversions
|
||||
// between binary and 'hex' | 'utf8' | 'base64'
|
||||
|
@ -13,7 +13,7 @@
|
||||
var epriv = pair.epriv;
|
||||
var ecdhSubtle = shim.ossl || shim.subtle;
|
||||
var pubKeyData = keysToEcdhJwk(pub);
|
||||
var props = Object.assign({ public: await ecdhSubtle.importKey(...pubKeyData, true, []) },S.ecdh);
|
||||
var props = Object.assign({ public: await ecdhSubtle.importKey(...pubKeyData, true, []) },S.ecdh); // Thanks to @sirpy !
|
||||
var privKeyData = keysToEcdhJwk(epub, epriv);
|
||||
var derived = await ecdhSubtle.importKey(...privKeyData, false, ['deriveKey']).then(async (privKey) => {
|
||||
// privateKey scope doesn't leak out from here!
|
||||
@ -47,4 +47,4 @@
|
||||
}
|
||||
|
||||
module.exports = SEA.secret;
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
random: (len) => Buffer.from(crypto.randomBytes(len))
|
||||
});
|
||||
//try{
|
||||
const { Crypto: WebCrypto } = USE('@peculiar/webcrypto', 1);
|
||||
const { Crypto: WebCrypto } = require('@peculiar/webcrypto', 1);
|
||||
api.ossl = api.subtle = new WebCrypto({directory: 'ossl'}).subtle // ECDH
|
||||
//}catch(e){
|
||||
//console.log("node-webcrypto-ossl is optionally needed for ECDH, please install if needed.");
|
||||
|
@ -17,7 +17,7 @@ Gun.on('create', function(root){
|
||||
// See the next 'opt' code below for actual saving of data.
|
||||
var ev = this.to, opt = root.opt;
|
||||
if(root.once){ return ev.next(root) }
|
||||
//if(false === opt.localStorage){ return ev.next(root) } // we want offline resynce queue regardless!
|
||||
if(false === opt.localStorage){ return ev.next(root) } // we want offline resynce queue regardless! // actually, this doesn't help, per @go1dfish 's observation. Disabling for now, will need better solution later.
|
||||
opt.prefix = opt.file || 'gun/';
|
||||
var gap = Gun.obj.ify(store.getItem('gap/'+opt.prefix)) || {};
|
||||
var empty = Gun.obj.empty, id, to, go;
|
||||
|
19
src/get.js
19
src/get.js
@ -11,7 +11,7 @@ Gun.chain.get = function(key, cb, as){
|
||||
gun = gun.$;
|
||||
} else
|
||||
if(key instanceof Function){
|
||||
if(true === cb){ return soul(this, key, cb, as) }
|
||||
if(true === cb){ return soul(this, key, cb, as), this }
|
||||
gun = this;
|
||||
var at = gun._, root = at.root, tmp = root.now, ev;
|
||||
as = cb || {};
|
||||
@ -68,15 +68,22 @@ function cache(key, back){
|
||||
}
|
||||
function soul(gun, cb, opt, as){
|
||||
var cat = gun._, acks = 0, tmp;
|
||||
if(tmp = cat.soul || cat.link || cat.dub){ return cb(tmp, as, cat), gun }
|
||||
gun.get(function(msg, ev){
|
||||
if(tmp = cat.soul || cat.link || cat.dub){ return cb(tmp, as, cat) }
|
||||
if(cat.jam){ return cat.jam.push([cb, as]) }
|
||||
cat.jam = [[cb,as]];
|
||||
gun.get(function(msg, eve){
|
||||
if(u === msg.put && (tmp = Object.keys(cat.root.opt.peers).length) && ++acks < tmp){
|
||||
return;
|
||||
}
|
||||
ev.rid(msg);
|
||||
eve.rid(msg);
|
||||
var at = ((at = msg.$) && at._) || {};
|
||||
tmp = at.link || at.soul || rel.is(msg.put) || node_soul(msg.put) || at.dub;
|
||||
cb(tmp, as, msg, ev);
|
||||
tmp = cat.jam; Gun.obj.del(cat, 'jam');
|
||||
Gun.obj.map(tmp, function(as, cb){
|
||||
cb = as[0]; as = as[1];
|
||||
if(!cb){ return }
|
||||
var id = at.link || at.soul || rel.is(msg.put) || node_soul(msg.put) || at.dub;
|
||||
cb(id, as, msg, eve);
|
||||
});
|
||||
}, {out: {get: {'.':true}}});
|
||||
return gun;
|
||||
}
|
||||
|
@ -3,9 +3,9 @@ var Gun = require('./root');
|
||||
Gun.chain.put = function(data, cb, as){
|
||||
// #soul.has=value>state
|
||||
// ~who#where.where=what>when@was
|
||||
// TODO: BUG! Put probably cannot handle plural chains!
|
||||
// TODO: BUG! Put probably cannot handle plural chains! `!as` is quickfix test.
|
||||
var gun = this, at = (gun._), root = at.root.$, ctx = root._, M = 100, tmp;
|
||||
if(!ctx.puta){ if(tmp = ctx.puts){ if(tmp > M){ // without this, when synchronous, writes to a 'not found' pile up, when 'not found' resolves it recursively calls `put` which incrementally resolves each write. Stack overflow limits can be as low as 10K, so this limit is hardcoded to 1% of 10K.
|
||||
/*if(!ctx.puta && !as){ if(tmp = ctx.puts){ if(tmp > M){ // without this, when synchronous, writes to a 'not found' pile up, when 'not found' resolves it recursively calls `put` which incrementally resolves each write. Stack overflow limits can be as low as 10K, so this limit is hardcoded to 1% of 10K.
|
||||
(ctx.stack || (ctx.stack = [])).push([gun, data, cb, as]);
|
||||
if(ctx.puto){ return }
|
||||
ctx.puto = setTimeout(function drain(){
|
||||
@ -15,7 +15,7 @@ Gun.chain.put = function(data, cb, as){
|
||||
ctx.stack = ctx.puts = ctx.puto = null;
|
||||
}, 0);
|
||||
return gun;
|
||||
} ++ctx.puts } else { ctx.puts = 1 } }
|
||||
} ++ctx.puts } else { ctx.puts = 1 } }*/
|
||||
as = as || {};
|
||||
as.data = data;
|
||||
as.via = as.$ = as.via || as.$ || gun;
|
||||
@ -138,6 +138,7 @@ function map(v,k,n, at){ var as = this;
|
||||
ref = ref.get(path[i]);
|
||||
}
|
||||
if(is){ ref = v }
|
||||
//if(as.not){ (ref._).dub = Gun.text.random() } // This might optimize stuff? Maybe not needed anymore. Make sure it doesn't introduce bugs.
|
||||
var id = (ref._).dub;
|
||||
if(id || (id = Gun.node.soul(at.obj))){
|
||||
ref.back(-1).get(id);
|
||||
@ -198,6 +199,7 @@ function any(soul, as, msg, eve){
|
||||
if(at.link || at.soul){ return at.link || at.soul }
|
||||
as.data = obj_put({}, at.get, as.data);
|
||||
});
|
||||
as.not = true; // maybe consider this?
|
||||
}
|
||||
tmp = tmp || at.soul || at.link || at.dub;// || at.get;
|
||||
at = tmp? (at.root.$.get(tmp)._) : at;
|
||||
|
@ -209,7 +209,7 @@ var obj = Gun.obj, obj_is = obj.is, obj_has = obj.has, obj_to = obj.to, obj_map
|
||||
var state_lex = Gun.state.lex, _soul = Gun.val.link._, _has = '.', node_ = Gun.node._, rel_is = Gun.val.link.is;
|
||||
var empty = {}, u;
|
||||
|
||||
console.debug = function(i, s){ return (console.debug.i && i === console.debug.i && console.debug.i++) && (console.log.apply(console, arguments) || s) };
|
||||
console.only = function(i, s){ return (console.only.i && i === console.only.i && console.only.i++) && (console.log.apply(console, arguments) || s) };
|
||||
|
||||
Gun.log = function(){ return (!Gun.log.off && console.log.apply(console, arguments)), [].slice.call(arguments).join(' ') }
|
||||
Gun.log.once = function(w,s,o){ return (o = Gun.log.once)[w] = o[w] || 0, o[w]++ || Gun.log(s) }
|
||||
|
Loading…
x
Reference in New Issue
Block a user