smarter SEA parsing, fix broken heroku deplou

This commit is contained in:
Mark Nadal 2018-05-10 22:02:02 -07:00
parent a4d559900d
commit 32befdc1e6
4 changed files with 911 additions and 343 deletions

View File

@ -1,17 +1,27 @@
;(function(){ ;(function(){
var ify = Gun.node.ify, u; var ify = Gun.node.ify, u;
Gun.chain.time = function(data, cb, opt){ Gun.chain.time = function(data, a, b){
if(Gun.is(data)){
var soul = data._.soul;
if(!soul){ return cb({err: "Only root level node references supported currently, hopefully will change this in the future."}), this }
data = Gun.val.rel.ify(soul);
}
if(data instanceof Function){ if(data instanceof Function){
return travel(data, cb, opt, this); return travel(data, a, b, this);
} }
opt = opt || {};
var t = new Date(Gun.state()).toISOString().split(/[\-t\:\.z]/ig);
var gun = this, root = gun.back(-1); var gun = this, root = gun.back(-1);
var cb = (a instanceof Function && a) || (b instanceof Function && b);
if(Gun.is(data)){
data = data._.soul;
if(!data){
/*data.get('_', function(msg, ev){
ev.off();
})
return gun;*/
cb && cb({err: "Only root level node references supported currently, hopefully will change this in the future."});
return gun;
}
data = Gun.val.rel.ify(data);
}
opt = (cb === a)? b : a;
opt = Gun.text.is(opt)? {key: opt} : opt || {};
var t = new Date(Gun.state()).toISOString().split(/[\-t\:\.z]/ig);
var p, tmp = t.pop(); var p, tmp = t.pop();
//gun.get('_', function(msg, ev){ ev.off(); //gun.get('_', function(msg, ev){ ev.off();
//var id = (msg.put && msg.put['#']) || (((gun._).soul || (root.back('opt.uuid') || Gun.text.random)(6)) + ':'); // TODO: BUG! THIS SHOULD NOT BE HARDCODED. //var id = (msg.put && msg.put['#']) || (((gun._).soul || (root.back('opt.uuid') || Gun.text.random)(6)) + ':'); // TODO: BUG! THIS SHOULD NOT BE HARDCODED.
@ -20,7 +30,7 @@
if(!p){ return cb({err: "For now, a timegraph can only be saved as a root node."}), this } if(!p){ return cb({err: "For now, a timegraph can only be saved as a root node."}), this }
// could shrink this into a loop. Do later? // could shrink this into a loop. Do later?
t = [p].concat(t); t = [p].concat(t);
var rid = (root.back('opt.uuid') || Gun.text.random)(9); var rid = opt.key || (root.back('opt.uuid') || Gun.text.random)(9);
var milli = ify({}, t.join(':')); var milli = ify({}, t.join(':'));
milli[rid] = data; milli[rid] = data;
tmp = t.pop(); tmp = t.pop();
@ -87,8 +97,9 @@
if(7 < at.length){ if(7 < at.length){
var l = Object.keys(msg.put).length; var l = Object.keys(msg.put).length;
if(l === o.seen[t]){ return } if(l === o.seen[t]){ return }
var when = +(toDate(at));
Gun.node.is(msg.put, function(v, k){ Gun.node.is(msg.put, function(v, k){
cb(v, k, ev); cb(v, k, when, ev);
if(o.last){ --o.last } if(o.last){ --o.last }
}); });
o.seen[t] = l; o.seen[t] = l;
@ -124,4 +135,8 @@
}); });
}) })
} }
function toDate(at){
at = at.slice(-7);
return new Date(Date.UTC(at[0], parseFloat(at[1])-1, at[2], at[3], at[4], at[5], at[6]));
}
}()); }());

1203
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "gun", "name": "gun",
"version": "0.9.995", "version": "0.9.996",
"description": "A realtime, decentralized, offline-first, graph data synchronization engine.", "description": "A realtime, decentralized, offline-first, graph data synchronization engine.",
"main": "index.js", "main": "index.js",
"browser": "gun.min.js", "browser": "gun.min.js",
@ -51,17 +51,11 @@
"ws": "~>4.0.0" "ws": "~>4.0.0"
}, },
"devDependencies": { "devDependencies": {
"@std/esm": "^0.8.3",
"@trust/webcrypto": "^0.7.1", "@trust/webcrypto": "^0.7.1",
"aws-sdk": ">=2.153.0", "aws-sdk": ">=2.153.0",
"express": ">=4.15.2", "express": ">=4.15.2",
"fake-indexeddb": "^2.0.3",
"hapi": "^17.2.0",
"inert": "^5.1.0",
"ip": "^1.1.5", "ip": "^1.1.5",
"mocha": ">=3.2.0", "mocha": ">=3.2.0",
"node-localstorage": "^1.3.0",
"node-webcrypto-ossl": "^1.0.36",
"panic-manager": "^1.2.0", "panic-manager": "^1.2.0",
"panic-server": "^1.1.1", "panic-server": "^1.1.1",
"text-encoding": "^0.6.4", "text-encoding": "^0.6.4",

6
sea.js
View File

@ -407,7 +407,9 @@
SEA.verify = async (data, pair, cb) => { try { SEA.verify = async (data, pair, cb) => { try {
const json = parse(data) const json = parse(data)
if(false === pair){ // don't verify! if(false === pair){ // don't verify!
const raw = (json === data)? json : parse(json.m) const raw = (json !== data)?
(json.s && json.m)? parse(json.m) : data
: json;
if(cb){ cb(raw) } if(cb){ cb(raw) }
return raw; return raw;
} }
@ -1387,7 +1389,7 @@
var to = this.to, vertex = (msg.gun._).put, c = 0, d; var to = this.to, vertex = (msg.gun._).put, c = 0, d;
Gun.node.is(msg.put, function(val, key, node){ c++; // for each property on the node Gun.node.is(msg.put, function(val, key, node){ c++; // for each property on the node
// TODO: consider async/await use here... // TODO: consider async/await use here...
SEA.verify(val, false).then(function(data){ c--; // false just extracts the plain data. SEA.verify(val, false, function(data){ c--; // false just extracts the plain data.
node[key] = val = data; // transform to plain value. node[key] = val = data; // transform to plain value.
if(d && !c && (c = -1)){ to.next(msg) } if(d && !c && (c = -1)){ to.next(msg) }
}); });