Merge to gun/master 0.9.8 conflicts resolved

This commit is contained in:
mhelander 2018-01-15 20:24:47 +02:00
commit ac31e953c4
19 changed files with 851 additions and 156 deletions

View File

@ -135,7 +135,7 @@ Thanks to:<br/>
This would not be possible without **community contributors**, big shout out to:
**[BrockAtkinson](https://github.com/BrockAtkinson) ([brunch config](https://github.com/BrockAtkinson/brunch-gun))**; **[Brysgo](https://github.com/brysgo) ([GraphQL](https://github.com/brysgo/graphql-gun))**; **[d3x0r](https://github.com/d3x0r) ([SQLite](https://github.com/d3x0r/gun-db))**; **[forrestjt](https://github.com/forrestjt) ([file.js](https://github.com/amark/gun/blob/master/lib/file.js))**; **[hillct](https://github.com/hillct) (Docker)**; **[JosePedroDias](https://github.com/josepedrodias) ([graph visualizer](http://acor.sl.pt:9966))**; **[JuniperChicago](https://github.com/JuniperChicago) ([cycle.js bindings](https://github.com/JuniperChicago/cycle-gun))**; **[jveres](https://github.com/jveres) ([todoMVC](https://github.com/jveres/todomvc))**; **[kristianmandrup](https://github.com/kristianmandrup) ([edge](https://github.com/kristianmandrup/gun-edge))**; [PsychoLlama](https://github.com/PsychoLlama) ([LevelDB](https://github.com/PsychoLlama/gun-level)); **[RangerMauve](https://github.com/RangerMauve) ([schema](https://github.com/gundb/gun-schema))**; **[robertheessels](https://github.com/swifty) ([gun-p2p-auth](https://github.com/swifty/gun-p2p-auth))**; [sbeleidy](https://github.com/sbeleidy); **[Sean Matheson](https://github.com/ctrlplusb) ([Observable/RxJS/Most.js bindings](https://github.com/ctrlplusb/gun-most))**; **[Stefdv](https://github.com/stefdv) (Polymer/web components)**; **[sjones6](https://github.com/sjones6) ([Flint](https://github.com/sjones6/gun-flint))**;
**[anywhichway](https://github.com/anywhichway) ([Block Storage](https://github.com/anywhichway/gun-block))**; **[beebase](https://github.com/beebase) ([Quasar](https://github.com/beebase/gun-vuex-quasar))**; **[BrockAtkinson](https://github.com/BrockAtkinson) ([brunch config](https://github.com/BrockAtkinson/brunch-gun))**; **[Brysgo](https://github.com/brysgo) ([GraphQL](https://github.com/brysgo/graphql-gun))**; **[d3x0r](https://github.com/d3x0r) ([SQLite](https://github.com/d3x0r/gun-db))**; **[forrestjt](https://github.com/forrestjt) ([file.js](https://github.com/amark/gun/blob/master/lib/file.js))**; **[hillct](https://github.com/hillct) (Docker)**; **[JosePedroDias](https://github.com/josepedrodias) ([graph visualizer](http://acor.sl.pt:9966))**; **[JuniperChicago](https://github.com/JuniperChicago) ([cycle.js bindings](https://github.com/JuniperChicago/cycle-gun))**; **[jveres](https://github.com/jveres) ([todoMVC](https://github.com/jveres/todomvc))**; **[kristianmandrup](https://github.com/kristianmandrup) ([edge](https://github.com/kristianmandrup/gun-edge))**; **[lmangani](https://github.com/lmangani) ([Cytoscape Visualizer](https://github.com/lmangani/gun-scape), [Cassandra](https://github.com/lmangani/gun-cassandra), [Fastify](https://github.com/lmangani/fastify-gundb), [LetsEncrypt](https://github.com/lmangani/polyGun-letsencrypt))**; **[mhelander](https://github.com/mhelander) ([SEA](https://github.com/amark/gun/blob/master/sea.js))**; [omarzion](https://github.com/omarzion) ([Sticky Note App](https://github.com/omarzion/stickies)); [PsychoLlama](https://github.com/PsychoLlama) ([LevelDB](https://github.com/PsychoLlama/gun-level)); **[RangerMauve](https://github.com/RangerMauve) ([schema](https://github.com/gundb/gun-schema))**; **[robertheessels](https://github.com/swifty) ([gun-p2p-auth](https://github.com/swifty/gun-p2p-auth))**; [sbeleidy](https://github.com/sbeleidy); **[Sean Matheson](https://github.com/ctrlplusb) ([Observable/RxJS/Most.js bindings](https://github.com/ctrlplusb/gun-most))**; **[Stefdv](https://github.com/stefdv) (Polymer/web components)**; **[sjones6](https://github.com/sjones6) ([Flint](https://github.com/sjones6/gun-flint))**; **[zrrrzzt](https://github.com/zrrrzzt) ([JWT Auth](https://gist.github.com/zrrrzzt/6f88dc3cedee4ee18588236756d2cfce))**; **[88dev](https://github.com/88dev) ([Database Viewer](https://github.com/88dev/gun-show))**;
I am missing many others, apologies, will be adding them soon!

View File

@ -50,7 +50,7 @@
}
.send {
style: margin: 0 0 0.4em 0.4em;
margin: 0 0 0.4em 0.4em;
padding: 0.2em 0.5em;
}

View File

@ -13,7 +13,8 @@
margin: 1em 0;
padding: 1em;
border: none;
background: white;
background: rgba(100%, 100%, 100%, 0.9);
back-ground: white;
}
.sigbut {
display: inline-block;
@ -56,7 +57,7 @@
<ul>
<a href="person" name="#">
<li>
<span name="profile">
<span name="who">
<b name="name"></b>
</span>
<i>~</i><i name="alias"></i>
@ -86,7 +87,7 @@
<div id="person" class="hue3 page">
<div class="pad">
<div name="profile">
<div name="who">
<!-- img src="" -->
<h2 name="name" contenteditable="true">Name</h2>
<i name="born"></i>
@ -97,7 +98,7 @@
</form>
<div>
<ul name="said">
<li name="#"><span name="what"></span></li>
<li name="#" class="shade rim"><div name="what" class="rim"></div></li>
</ul>
</div>
</div>
@ -109,15 +110,21 @@
<p>A mysterious new example app has appeared! It is not finished/ready yet.</p>
</div id="info">
<script src="../jquery.js"></script>
<script src="../../gun.js"></script>
<script src="../../lib/cryptomodules.js"></script>
<script src="../../sea.js"></script>
<script src="../../as.js"></script>
<!-- script src="/Users/mark/Dropbox/Public/gun/db/examples/jquery.js"></script>
<script src="/Users/mark/Dropbox/Public/gun/db/gun.js"></script>
<script src="/Users/mark/Dropbox/Public/gun/db/lib/cryptomodules.js"></script>
<script src="/Users/mark/Dropbox/Public/gun/db/sea.js"></script>
<script src="/Users/mark/Dropbox/Public/gun/db/as.js"></script -->
<script src="/jquery.js"></script>
<script src="/gun.js"></script>
<script src="/gun/lib/cryptomodules.js"></script>
<script src="/gun/sea.js"></script>
<script src="/gun/as.js"></script>
<script>
//var gun = Gun('http://localhost:8080/gun'); // DOESN'T WORK YET :(
var gun = Gun();
var app = gun.get('example/contacts/4');
var gun = Gun(location.origin+'/gun');
//var gun = Gun();
var app = gun.get('example/contacts/6');
var user = gun.user();
var c = window.c = {};
(function(){
@ -203,7 +210,7 @@
(function(){
$(document).on('submit', '#say', function(e){
e.preventDefault();
user.get('profile').get('said').set({
user.get('who').get('said').set({
what: $(this).find('.jot').val()
});
$(this).find('.jot').val('');
@ -219,7 +226,7 @@
as.route.page('person', function(){
if(!user.is){ return as.route('sign') }
var pub = location.hash.split('/').slice(-1)[0];
as('#person', gun.get('pub/'+pub));
as('#person', window.PUB = gun.get('pub/'+pub));
});

View File

@ -69,7 +69,7 @@
}
</style>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script src="https://gunjs.herokuapp.com/gun.js"></script>
<script src="/gun.js"></script>
<script>
function Where(opt, cb){
// a small wrapper around Leaflet for map tracking.

View File

@ -62,6 +62,13 @@ input, textarea {
background: white;
}
.shade {
background: rgba(0%, 0%, 0%, 0.1);
}
.tint {
background: rgba(100%, 100%, 100%, 0.1);
}
.redt {
color: #ea3224;
}
@ -88,6 +95,10 @@ input, textarea {
max-width: 50em;
}
.rim {
margin: 2%;
}
.right {
float: right;
}
@ -125,17 +136,17 @@ input, textarea {
}
@keyframes hue {
0% {background: #4D79D8;}
25% {background: #33cc33;}
50% {background: #f2b919;}
75% {background: #ea3224;}
100% {background: #4D79D8;}
0% {background-color: #4D79D8;}
25% {background-color: #33cc33;}
50% {background-color: #f2b919;}
75% {background-color: #ea3224;}
100% {background-color: #4D79D8;}
} @-webkit-keyframes hue {
0% {background: #4D79D8;}
25% {background: #33cc33;}
50% {background: #f2b919;}
75% {background: #ea3224;}
100% {background: #4D79D8;}
0% {background-color: #4D79D8;}
25% {background-color: #33cc33;}
50% {background-color: #f2b919;}
75% {background-color: #ea3224;}
100% {background-color: #4D79D8;}
}
.huet {
@ -165,17 +176,17 @@ input, textarea {
}
@keyframes hue2 {
0% {background: #ea3224;}
25% {background: #4D79D8;}
50% {background: #33cc33;}
75% {background: #f2b919;}
100% {background: #ea3224;}
0% {background-color: #ea3224;}
25% {background-color: #4D79D8;}
50% {background-color: #33cc33;}
75% {background-color: #f2b919;}
100% {background-color: #ea3224;}
} @-webkit-keyframes hue2 {
0% {background: #ea3224;}
25% {background: #4D79D8;}
50% {background: #33cc33;}
75% {background: #f2b919;}
100% {background: #ea3224;}
0% {background-color: #ea3224;}
25% {background-color: #4D79D8;}
50% {background-color: #33cc33;}
75% {background-color: #f2b919;}
100% {background-color: #ea3224;}
}
.huet2 {
@ -205,17 +216,17 @@ input, textarea {
}
@keyframes hue3 {
0% {background: #33cc33;}
25% {background: #f2b919;}
50% {background: #ea3224;}
75% {background: #4D79D8;}
100% {background: #33cc33;}
0% {background-color: #33cc33;}
25% {background-color: #f2b919;}
50% {background-color: #ea3224;}
75% {background-color: #4D79D8;}
100% {background-color: #33cc33;}
} @-webkit-keyframes hue3 {
0% {background: #33cc33;}
25% {background: #f2b919;}
50% {background: #ea3224;}
75% {background: #4D79D8;}
100% {background: #33cc33;}
0% {background-color: #33cc33;}
25% {background-color: #f2b919;}
50% {background-color: #ea3224;}
75% {background-color: #4D79D8;}
100% {background-color: #33cc33;}
}
.huet3 {
@ -245,17 +256,17 @@ input, textarea {
}
@keyframes hue4 {
0% {background: #f2b919;}
25% {background: #ea3224;}
50% {background: #4D79D8;}
75% {background: #33cc33;}
100% {background: #f2b919;}
0% {background-color: #f2b919;}
25% {background-color: #ea3224;}
50% {background-color: #4D79D8;}
75% {background-color: #33cc33;}
100% {background-color: #f2b919;}
} @-webkit-keyframes hue4 {
0% {background: #f2b919;}
25% {background: #ea3224;}
50% {background: #4D79D8;}
75% {background: #33cc33;}
100% {background: #f2b919;}
0% {background-color: #f2b919;}
25% {background-color: #ea3224;}
50% {background-color: #4D79D8;}
75% {background-color: #33cc33;}
100% {background-color: #f2b919;}
}
.huet4 {

182
gun.js
View File

@ -6,19 +6,19 @@
if(typeof global !== "undefined"){ root = global }
root = root || {};
var console = root.console || {log: function(){}};
function require(arg){
return arg.slice? require[resolve(arg)] : function(mod, path){
function USE(arg){
return arg.slice? USE[R(arg)] : function(mod, path){
arg(mod = {exports: {}});
require[resolve(path)] = mod.exports;
USE[R(path)] = mod.exports;
}
function resolve(path){
return path.split('/').slice(-1).toString().replace('.js','');
function R(p){
return p.split('/').slice(-1).toString().replace('.js','');
}
}
if(typeof module !== "undefined"){ var common = module }
/* UNBUILD */
;require(function(module){
;USE(function(module){
// Generic javascript utilities.
var Type = {};
//Type.fns = Type.fn = {is: function(fn){ return (!!fn && fn instanceof Function) }}
@ -163,9 +163,9 @@
var list_is = Type.list.is;
var obj = Type.obj, obj_is = obj.is, obj_has = obj.has, obj_map = obj.map;
module.exports = Type;
})(require, './type');
})(USE, './type');
;require(function(module){
;USE(function(module){
// On event emitter generic javascript utility.
module.exports = function onto(tag, arg, as){
if(!tag){ return {to: onto} }
@ -203,9 +203,9 @@
(tag = tag.to).next(arg);
return tag;
};
})(require, './onto');
})(USE, './onto');
;require(function(module){
;USE(function(module){
/* Based on the Hypothetical Amnesia Machine thought experiment */
function HAM(machineState, incomingState, currentState, incomingValue, currentValue){
if(machineState < incomingState){
@ -250,10 +250,10 @@
}
var Lexical = JSON.stringify, undefined;
module.exports = HAM;
})(require, './HAM');
})(USE, './HAM');
;require(function(module){
var Type = require('./type');
;USE(function(module){
var Type = USE('./type');
var Val = {};
Val.is = function(v){ // Valid values are a subset of JSON: null, binary, number (!Infinity), text, or a soul relation. Arrays need special algorithms to handle concurrency, so they are not supported directly. Use an extension that supports them if needed but research their problems first.
if(v === u){ return false }
@ -294,11 +294,11 @@
var text_is = Type.text.is;
var obj = Type.obj, obj_is = obj.is, obj_put = obj.put, obj_map = obj.map;
module.exports = Val;
})(require, './val');
})(USE, './val');
;require(function(module){
var Type = require('./type');
var Val = require('./val');
;USE(function(module){
var Type = USE('./type');
var Val = USE('./val');
var Node = {_: '_'};
Node.soul = function(n, o){ return (n && n._ && n._[o || soul_]) } // convenience function to check to see if there is a soul on a node and return it.
Node.soul.ify = function(n, o){ // put a soul on an object.
@ -353,11 +353,11 @@
var soul_ = Node.soul._;
var u;
module.exports = Node;
})(require, './node');
})(USE, './node');
;require(function(module){
var Type = require('./type');
var Node = require('./node');
;USE(function(module){
var Type = USE('./type');
var Node = USE('./node');
function State(){
var t;
if(perf){
@ -437,12 +437,12 @@
var fn = Type.fn, fn_is = fn.is;
var N_ = Node._, u;
module.exports = State;
})(require, './state');
})(USE, './state');
;require(function(module){
var Type = require('./type');
var Val = require('./val');
var Node = require('./node');
;USE(function(module){
var Type = USE('./type');
var Val = USE('./val');
var Node = USE('./node');
var Graph = {};
;(function(){
Graph.is = function(g, cb, fn, as){ // checks to see if an object is a valid graph.
@ -589,11 +589,11 @@
var obj = Type.obj, obj_is = obj.is, obj_del = obj.del, obj_has = obj.has, obj_empty = obj.empty, obj_put = obj.put, obj_map = obj.map, obj_copy = obj.copy;
var u;
module.exports = Graph;
})(require, './graph');
})(USE, './graph');
;require(function(module){
;USE(function(module){
// request / response module, for asking and acking messages.
require('./onto'); // depends upon onto!
USE('./onto'); // depends upon onto!
module.exports = function ask(cb, as){
if(!this.on){ return }
if(!(cb instanceof Function)){
@ -613,10 +613,10 @@
}, (this.opt||{}).lack || 9000);
return id;
}
})(require, './ask');
})(USE, './ask');
;require(function(module){
var Type = require('./type');
;USE(function(module){
var Type = USE('./type');
function Dup(opt){
var dup = {s:{}};
opt = opt || {max: 1000, age: 1000 * 9};//1000 * 60 * 2};
@ -640,9 +640,9 @@
}
var time_is = Type.time.is;
module.exports = Dup;
})(require, './dup');
})(USE, './dup');
;require(function(module){
;USE(function(module){
function Gun(o){
if(o instanceof Gun){ return (this._ = {gun: this}).gun }
@ -657,16 +657,16 @@
Gun.chain = Gun.prototype;
Gun.chain.toJSON = function(){};
var Type = require('./type');
var Type = USE('./type');
Type.obj.to(Type, Gun);
Gun.HAM = require('./HAM');
Gun.val = require('./val');
Gun.node = require('./node');
Gun.state = require('./state');
Gun.graph = require('./graph');
Gun.on = require('./onto');
Gun.ask = require('./ask');
Gun.dup = require('./dup');
Gun.HAM = USE('./HAM');
Gun.val = USE('./val');
Gun.node = USE('./node');
Gun.state = USE('./state');
Gun.graph = USE('./graph');
Gun.on = USE('./onto');
Gun.ask = USE('./ask');
Gun.dup = USE('./dup');
Gun._ = { // some reserved key words, these are not the only ones.
node: Gun.node._ // all metadata of a node is stored in the meta property on the node.
@ -745,7 +745,10 @@
}
function merge(node, soul){
var ctx = this, cat = ctx.gun._, at = (cat.next || empty)[soul];
if(!at){ return }
if(!at){
ctx.souls[soul] = false;
return
}
var msg = ctx.map[soul] = {
put: node,
get: soul,
@ -783,7 +786,6 @@
function map(msg, soul){
if(!msg.gun){ return }
msg.gun._.root._.stop = {};
//console.log("map ->", soul, msg.put);
(msg.gun._).on('in', msg);
msg.gun._.root._.stop = {};
}
@ -864,12 +866,12 @@
//console.log("<<<<<", msg.put);
to.next(msg);
},1);
})
});
});*/
})(require, './root');
})(USE, './root');
;require(function(module){
var Gun = require('./root');
;USE(function(module){
var Gun = USE('./root');
Gun.chain.back = function(n, opt){ var tmp;
n = n || 1;
if(-1 === n || Infinity === n){
@ -908,13 +910,13 @@
return this;
}
var empty = {}, u;
})(require, './back');
})(USE, './back');
;require(function(module){
;USE(function(module){
// WARNING: GUN is very simple, but the JavaScript chaining API around GUN
// is complicated and was extremely hard to build. If you port GUN to another
// language, consider implementing an easier API to build.
var Gun = require('./root');
var Gun = USE('./root');
Gun.chain.chain = function(){
var at = this._, chain = new this.constructor(this), cat = chain._, root;
cat.root = root = at.root;
@ -1162,9 +1164,9 @@
Gun.obj.del(at, 'ask'); // TODO: PERFORMANCE? More elegant way?
}
function ack(msg, ev){
var as = this.as, get = as.get || empty, at = as.gun._;
var as = this.as, get = as.get || empty, at = as.gun._, tmp = (msg.put||empty)[get['#']];
if(at.ack){ at.ack = (at.ack + 1) || 1 }
if(!msg.put /*|| node_ == get['.']*/ || (get['.'] && !obj_has(msg.put[get['#']], at.get))){
if(!msg.put /*|| node_ == get['.']*/ || (get['.'] && !obj_has(tmp, at.get))){
if(at.put !== u){ return }
//at.ack = 0;
at.on('in', {
@ -1175,6 +1177,10 @@
})
return;
}
if(node_ == get['.']){ // is this a security concern?
at.on('in', {get: at.get, put: tmp[at.get], gun: at.gun, '@': msg['@']});
return;
}
//if(/*!msg.gun &&*/ !get['.'] && get['#']){ at.ack = (at.ack + 1) || 1 }
//msg = obj_to(msg);
msg.gun = at.root;
@ -1185,10 +1191,10 @@
var obj = Gun.obj, obj_has = obj.has, obj_put = obj.put, obj_del = obj.del, obj_to = obj.to, obj_map = obj.map;
var text_rand = Gun.text.random;
var _soul = Gun._.soul, _field = Gun._.field, node_ = Gun.node._;
})(require, './chain');
})(USE, './chain');
;require(function(module){
var Gun = require('./root');
;USE(function(module){
var Gun = USE('./root');
Gun.chain.get = function(key, cb, as){
if(typeof key === 'string'){
var gun, back = this, cat = back._;
@ -1228,7 +1234,7 @@
var cat = back._, next = cat.next, gun = back.chain(), at = gun._;
if(!next){ next = cat.next = {} }
next[at.get = key] = gun;
if(cat.root === back){
if(cat.root === back){
at.soul = key;
} else
if(cat.soul || cat.field || cat.has){ // TODO: Convert field to has!
@ -1260,10 +1266,10 @@
var num_is = Gun.num.is;
var rel = Gun.val.rel, node_ = Gun.node._;
var empty = {}, u;
})(require, './get');
})(USE, './get');
;require(function(module){
var Gun = require('./root');
;USE(function(module){
var Gun = USE('./root');
Gun.chain.put = function(data, cb, as){
// #soul.field=value>state
// ~who#where.where=what>when@was
@ -1468,7 +1474,10 @@
as.soul = (opt.uuid || cat.root._.opt.uuid || Gun.text.random)();
} else {
//as.data = obj_put({}, as.gun._.get, as.data);
as.soul = at.soul || cat.soul || (opt.uuid || cat.root._.opt.uuid || Gun.text.random)();
if(node_ == at.get){
as.soul = (at.put||empty)['#'];
}
as.soul = as.soul || at.soul || cat.soul || (opt.uuid || cat.root._.opt.uuid || Gun.text.random)();
}
if(!as.soul){ // polyfill async uuid for SEA
as.ref.back('opt.uuid')(function(err, soul){ // TODO: improve perf without anonymous callback
@ -1482,19 +1491,20 @@
}
var obj = Gun.obj, obj_is = obj.is, obj_put = obj.put, obj_map = obj.map;
var u, empty = {}, noop = function(){}, iife = function(fn,as){fn.call(as||empty)};
})(require, './put');
var node_ = Gun.node._;
})(USE, './put');
;require(function(module){
var Gun = require('./root');
require('./chain');
require('./back');
require('./put');
require('./get');
;USE(function(module){
var Gun = USE('./root');
USE('./chain');
USE('./back');
USE('./put');
USE('./get');
module.exports = Gun;
})(require, './index');
})(USE, './index');
;require(function(module){
var Gun = require('./index');
;USE(function(module){
var Gun = USE('./index');
Gun.chain.on = function(tag, arg, eas, as){
var gun = this, at = gun._, tmp, act, off;
if(typeof tag === 'string'){
@ -1640,10 +1650,10 @@
var obj = Gun.obj, obj_map = obj.map, obj_has = obj.has, obj_del = obj.del, obj_to = obj.to;
var rel = Gun.val.rel;
var empty = {}, noop = function(){}, u;
})(require, './on');
})(USE, './on');
;require(function(module){
var Gun = require('./index');
;USE(function(module){
var Gun = USE('./index');
Gun.chain.map = function(cb, opt, t){
var gun = this, cat = gun._, chain;
if(!cb){
@ -1679,10 +1689,10 @@
(tmp.echo || (tmp.echo = {}))[at.id] = at;
}
var obj_map = Gun.obj.map, noop = function(){}, event = {stun: noop, off: noop}, n_ = Gun.node._, u;
})(require, './map');
})(USE, './map');
;require(function(module){
var Gun = require('./index');
;USE(function(module){
var Gun = USE('./index');
Gun.chain.set = function(item, cb, opt){
var gun = this, soul;
cb = cb || function(){};
@ -1698,16 +1708,18 @@
item.get('_').get(function(at, ev){
if(!at.gun || !at.gun._.back){ return }
ev.off();
var soul = (at.put||{})['#'];
at = (at.gun._.back._);
var put = {}, node = at.put, soul = Gun.node.soul(node);
var put = {}, node = at.put;
soul = at.soul || Gun.node.soul(node) || soul;
if(!soul){ return cb.call(gun, {err: Gun.log('Only a node can be linked! Not "' + node + '"!')}) }
gun.put(Gun.obj.put(put, soul, Gun.val.rel.ify(soul)), cb, opt);
},{wait:0});
return item;
}
})(require, './set');
})(USE, './set');
;require(function(module){
;USE(function(module){
if(typeof Gun === 'undefined'){ return } // TODO: localStorage is Browser only. But it would be nice if it could somehow plugin into NodeJS compatible localStorage APIs?
var root, noop = function(){}, u;
@ -1781,10 +1793,10 @@
});
}
});
})(require, './adapters/localStorage');
})(USE, './adapters/localStorage');
;require(function(module){
var Gun = require('./index');
;USE(function(module){
var Gun = USE('./index');
var websocket;
if(typeof WebSocket !== 'undefined'){
websocket = WebSocket;
@ -1887,6 +1899,6 @@
}
});
var noop = function(){};
})(require, './adapters/websocket');
})(USE, './adapters/websocket');
}());

View File

@ -88,10 +88,11 @@ var undent = function(code, n){
write('src/polyfill/unbuild.js', undent(code, 1));
(function recurse(c){
code = next(";require(function(module){", "})(require");
code = next(";USE(function(module){", "})(USE");
if(!code){ return }
var file = path();
if(!file){ return }
code = code.replace(/\bUSE\(/g, 'require(');
write(file, undent(code));
recurse();
}());

View File

@ -1,6 +1,6 @@
{
"name": "gun",
"version": "0.9.7",
"version": "0.9.8",
"description": "Graph engine",
"main": "index.js",
"browser": "gun.min.js",

13
sea.js
View File

@ -903,6 +903,12 @@
return;
}
check['any'+soul+key] = 1;
if((tmp = soul.split('~')) && 2 == tmp.length){
setTimeout(function(){ // hacky idea, what would be better?
each.any(val, key, node, soul);
},1);
return;
}
at.on('secure', function(msg){ this.off();
check['any'+soul+key] = 0;
each.end(msg || {err: "Data cannot be modified."});
@ -914,6 +920,13 @@
each.end({err: "Soul is not signed at '" + key + "'."});
return;
}
var other = Gun.obj.map(at.sea.own[soul], function(v, p){
if(user.pub !== p){ return p }
});
if(other){
each.any(val, key, node, soul);
return;
}
check['any'+soul+key] = 1;
SEA.verify(tmp[0], user.pub, tmp[1], function(ok){
if(!ok){ return each.end({err: "Signature did not match account at '" + key + "'."}) }

View File

@ -39,7 +39,7 @@ function cache(key, back){
var cat = back._, next = cat.next, gun = back.chain(), at = gun._;
if(!next){ next = cat.next = {} }
next[at.get = key] = gun;
if(cat.root === back){
if(cat.root === back){
at.soul = key;
} else
if(cat.soul || cat.field || cat.has){ // TODO: Convert field to has!

View File

@ -4,13 +4,13 @@ if(typeof window !== "undefined"){ root = window }
if(typeof global !== "undefined"){ root = global }
root = root || {};
var console = root.console || {log: function(){}};
function require(arg){
return arg.slice? require[resolve(arg)] : function(mod, path){
function USE(arg){
return arg.slice? USE[R(arg)] : function(mod, path){
arg(mod = {exports: {}});
require[resolve(path)] = mod.exports;
USE[R(path)] = mod.exports;
}
function resolve(path){
return path.split('/').slice(-1).toString().replace('.js','');
function R(p){
return p.split('/').slice(-1).toString().replace('.js','');
}
}
if(typeof module !== "undefined"){ var common = module }

View File

@ -204,7 +204,10 @@ function any(at, ev){
as.soul = (opt.uuid || cat.root._.opt.uuid || Gun.text.random)();
} else {
//as.data = obj_put({}, as.gun._.get, as.data);
as.soul = at.soul || cat.soul || (opt.uuid || cat.root._.opt.uuid || Gun.text.random)();
if(node_ == at.get){
as.soul = (at.put||empty)['#'];
}
as.soul = as.soul || at.soul || cat.soul || (opt.uuid || cat.root._.opt.uuid || Gun.text.random)();
}
if(!as.soul){ // polyfill async uuid for SEA
as.ref.back('opt.uuid')(function(err, soul){ // TODO: improve perf without anonymous callback
@ -218,4 +221,5 @@ function any(at, ev){
}
var obj = Gun.obj, obj_is = obj.is, obj_put = obj.put, obj_map = obj.map;
var u, empty = {}, noop = function(){}, iife = function(fn,as){fn.call(as||empty)};
var node_ = Gun.node._;

View File

@ -101,7 +101,10 @@ Gun._ = { // some reserved key words, these are not the only ones.
}
function merge(node, soul){
var ctx = this, cat = ctx.gun._, at = (cat.next || empty)[soul];
if(!at){ return }
if(!at){
ctx.souls[soul] = false;
return
}
var msg = ctx.map[soul] = {
put: node,
get: soul,
@ -139,7 +142,6 @@ Gun._ = { // some reserved key words, these are not the only ones.
function map(msg, soul){
if(!msg.gun){ return }
msg.gun._.root._.stop = {};
//console.log("map ->", soul, msg.put);
(msg.gun._).on('in', msg);
msg.gun._.root._.stop = {};
}
@ -220,6 +222,5 @@ module.exports = Gun;
//console.log("<<<<<", msg.put);
to.next(msg);
},1);
})
});
});*/

View File

@ -15,8 +15,10 @@ Gun.chain.set = function(item, cb, opt){
item.get('_').get(function(at, ev){
if(!at.gun || !at.gun._.back){ return }
ev.off();
var soul = (at.put||{})['#'];
at = (at.gun._.back._);
var put = {}, node = at.put, soul = Gun.node.soul(node);
var put = {}, node = at.put;
soul = at.soul || Gun.node.soul(node) || soul;
if(!soul){ return cb.call(gun, {err: Gun.log('Only a node can be linked! Not "' + node + '"!')}) }
gun.put(Gun.obj.put(put, soul, Gun.val.rel.ify(soul)), cb, opt);
},{wait:0});

27
test/debug/deep-set.html Normal file
View File

@ -0,0 +1,27 @@
<script src="../../gun.js"></script>
<script>
;(function(){
//localStorage.clear();
var gun = window.gun = Gun('http://localhost:8080/gun');
var user = window.user = gun.get('pub/alice');
return;
user.put({pub: 'alice'}, write);
function write(data){
console.log("write...");
user.get('profile').get('said').set({
what: "Hello world! " + Gun.text.random(3)
}, get);
}
function get(){
console.log("get...");
user.get('profile').get('said').map().val(function(data){
console.log("read...", data);
})
}
}());
</script>

200
test/panic/set.js Normal file
View File

@ -0,0 +1,200 @@
var config = {
IP: require('ip').address(),
port: 8080,
servers: 1,
browsers: 2,
route: {
'/': __dirname + '/index.html',
'/gun.js': __dirname + '/../../gun.js',
'/jquery.js': __dirname + '/../../examples/jquery.js',
'/cryptomodules.js': __dirname + '/../../lib/cryptomodules.js',
'/sea.js': __dirname + '/../../sea.js'
}
}
var panic = require('panic-server');
panic.server().on('request', function(req, res){
config.route[req.url] && require('fs').createReadStream(config.route[req.url]).pipe(res);
}).listen(config.port);
var clients = panic.clients;
var manager = require('panic-manager')();
manager.start({
clients: Array(config.servers).fill().map(function(u, i){
return {
type: 'node',
port: config.port + (i + 1)
}
}),
panic: 'http://' + config.IP + ':' + config.port
});
var servers = clients.filter('Node.js');
var server = servers.pluck(1);
var spawn = servers.excluding(server).pluck(1);
var browsers = clients.excluding(servers);
var alice = browsers.pluck(1);
var bob = browsers.excluding(alice).pluck(1);
var again = {};
describe("Make sure SEA syncs correctly", function(){
//this.timeout(5 * 60 * 1000);
this.timeout(10 * 60 * 1000);
it("Servers have joined!", function(){
return servers.atLeast(config.servers);
});
it("GUN started!", function(){
return server.run(function(test){
var env = test.props;
test.async();
try{ require('fs').unlinkSync(env.i+'data') }catch(e){}
try{ require('fs').unlinkSync((env.i+1)+'data') }catch(e){}
var port = env.config.port + env.i;
var server = require('http').createServer(function(req, res){
res.end("I am "+ env.i +"!");
});
var Gun = require('gun');
var gun = Gun({file: env.i+'data', web: server});
server.listen(port, function(){
test.done();
});
}, {i: 1, config: config});
});
it(config.browsers +" browser(s) have joined!", function(){
console.log("PLEASE OPEN http://"+ config.IP +":"+ config.port +" IN "+ config.browsers +" BROWSER(S)!");
return browsers.atLeast(config.browsers);
});
it("Browsers load SEA!", function(){
var tests = [], i = 0;
browsers.each(function(client, id){
tests.push(client.run(function(test){
test.async();
//console.log("load?");
function load(src, cb){
var script = document.createElement('script');
script.onload = cb; script.src = src;
document.head.appendChild(script);
}
/*load('cryptomodules.js', function(){
load('sea.js', function(){
test.done();
});
});*/
test.done();
}, {i: i += 1, config: config}));
});
return Promise.all(tests);
});
it("Browsers initialized gun!", function(){
var tests = [], i = 0;
browsers.each(function(client, id){
tests.push(client.run(function(test){
localStorage.clear();
var env = test.props;
var gun = Gun('http://'+ env.config.IP + ':' + (env.config.port + 1) + '/gun');
window.gun = gun;
var user = window.user = gun.get('pub/alice');
}, {i: i += 1, config: config}));
});
return Promise.all(tests);
});
it("Create Alice", function(){
return alice.run(function(test){
console.log("I AM ALICE");
test.async();
user.put({pub: 'alice'}, function(ack){
if(ack.err){ return }
console.log("write...");
user.get('who').get('said').set({
what: "Hello world!"
}, function(ack){
if(ack.err){ return }
test.done();
});
});
});
});
it("Have Bob listen", function(){
return bob.run(function(test){
test.async();
window.count = [];
user.get('who').get('said').map().val(function(data){
console.log("read...", data);
window.count.push(data);
if(window.count.length - 1){ return }
test.done();
});
});
});
it("Alice reloading.", function(){
return alice.run(function(test){
location.reload();
});
});
it("Got Alice.", function(){
again.alice = browsers.excluding(new panic.ClientList([alice, bob])).pluck(1);
return again.alice.atLeast(1);
});
it("Alice reloaded.", function(){
return again.alice.run(function(test){
var env = test.props;
var gun = Gun('http://'+ env.config.IP + ':' + (env.config.port + 1) + '/gun');
window.gun = gun;
var user = window.user = gun.get('pub/alice');
}, {i: 1, config: config})
});
it("Alice write.", function(){
return again.alice.run(function(test){
test.async();
console.log("write...");
user.get('who').get('said').set({
what: "AAA"
}, function(ack){
if(ack.err){ return }
test.done();
});
});
});
it("Bob got", function(){
return bob.run(function(test){
test.async();
console.log(window.count);
setTimeout(function(){
if('AAA' === window.count[1].what){
test.done();
}
}, 100);
});
});
it("All finished!", function(done){
console.log("Done! Cleaning things up...");
setTimeout(function(){
done();
},1000);
});
after("Everything shut down.", function(){
browsers.run(function(){
//location.reload();
//setTimeout(function(){
//}, 15 * 1000);
});
return servers.run(function(){
process.exit();
});
});
});

250
test/panic/who.js Normal file
View File

@ -0,0 +1,250 @@
var config = {
IP: require('ip').address(),
port: 8080,
servers: 1,
browsers: 2,
route: {
'/': __dirname + '/index.html',
'/gun.js': __dirname + '/../../gun.js',
'/jquery.js': __dirname + '/../../examples/jquery.js',
'/cryptomodules.js': __dirname + '/../../lib/cryptomodules.js',
'/sea.js': __dirname + '/../../sea.js'
}
}
var panic = require('panic-server');
panic.server().on('request', function(req, res){
config.route[req.url] && require('fs').createReadStream(config.route[req.url]).pipe(res);
}).listen(config.port);
var clients = panic.clients;
var manager = require('panic-manager')();
manager.start({
clients: Array(config.servers).fill().map(function(u, i){
return {
type: 'node',
port: config.port + (i + 1)
}
}),
panic: 'http://' + config.IP + ':' + config.port
});
var servers = clients.filter('Node.js');
var server = servers.pluck(1);
var spawn = servers.excluding(server).pluck(1);
var browsers = clients.excluding(servers);
var alice = browsers.pluck(1);
var bob = browsers.excluding(alice).pluck(1);
var again = {};
describe("Make sure SEA syncs correctly", function(){
//this.timeout(5 * 60 * 1000);
this.timeout(10 * 60 * 1000);
it("Servers have joined!", function(){
return servers.atLeast(config.servers);
});
it("GUN started!", function(){
return server.run(function(test){
var env = test.props;
test.async();
try{ require('fs').unlinkSync(env.i+'data') }catch(e){}
try{ require('fs').unlinkSync((env.i+1)+'data') }catch(e){}
var port = env.config.port + env.i;
var server = require('http').createServer(function(req, res){
res.end("I am "+ env.i +"!");
});
var Gun = require('gun');
var gun = Gun({file: env.i+'data', web: server});
server.listen(port, function(){
test.done();
});
}, {i: 1, config: config});
});
it(config.browsers +" browser(s) have joined!", function(){
console.log("PLEASE OPEN http://"+ config.IP +":"+ config.port +" IN "+ config.browsers +" BROWSER(S)!");
return browsers.atLeast(config.browsers);
});
it("Browsers load SEA!", function(){
var tests = [], i = 0;
browsers.each(function(client, id){
tests.push(client.run(function(test){
test.async();
//console.log("load?");
function load(src, cb){
var script = document.createElement('script');
script.onload = cb; script.src = src;
document.head.appendChild(script);
}
load('cryptomodules.js', function(){
load('sea.js', function(){
test.done();
});
});
}, {i: i += 1, config: config}));
});
return Promise.all(tests);
});
it("Browsers initialized gun!", function(){
var tests = [], i = 0;
browsers.each(function(client, id){
tests.push(client.run(function(test){
localStorage.clear();
var env = test.props;
var gun = Gun('http://'+ env.config.IP + ':' + (env.config.port + 1) + '/gun');
window.gun = gun;
var user = window.user = gun.user();
}, {i: i += 1, config: config}));
});
return Promise.all(tests);
});
it("Create Alice", function(){
return alice.run(function(test){
console.log("I AM ALICE");
test.async();
window.user.create('alice', 'xyzabcmnopq', function(ack){
if(ack.err || !ack.pub){ return }
window.user.auth('alice', 'xyzabcmnopq', function(ack){
if(ack.err || !ack.pub){ return }
test.done();
user.get('who').get('said').set({
what: "Hello world!"
}, function(ack){
if(ack.err){ return }
test.done();
});
});
});
});
});
it("Create Bob", function(){
return bob.run(function(test){
test.async();
window.user.create('bob', 'zyxcbaqponm', function(ack){
if(ack.err || !ack.pub){ return }
window.user.auth('bob', 'zyxcbaqponm', function(ack){
if(ack.err || !ack.pub){ return }
test.done();
});
});
});
});
it("Have Bob find Alice", function(){
return bob.run(function(test){
test.async();
window.gun.get('alias/alice').map().val(function(data){
window.ref = gun.get('pub/'+data.pub);
test.done();
});
});
});
it("Have Bob listen", function(){
return bob.run(function(test){
test.async();
window.count = [];
ref.get('who').get('said').map().val(function(data){
console.log("read...", data);
window.count.push(data);
if(window.count.length - 1){ return }
test.done();
});
});
});
it("Alice reloading.", function(){
return alice.run(function(test){
location.reload();
});
});
it("Got Alice.", function(){
again.alice = browsers.excluding(new panic.ClientList([alice, bob])).pluck(1);
return again.alice.atLeast(1);
});
it("Alice reloaded.", function(){
return again.alice.run(function(test){
test.async();
//console.log("load?");
function load(src, cb){
var script = document.createElement('script');
script.onload = cb; script.src = src;
document.head.appendChild(script);
}
load('cryptomodules.js', function(){
load('sea.js', function(){
test.done();
});
});
}, {i: 1, config: config});
});
it("Alice loaded.", function(){
return again.alice.run(function(test){
test.async();
var env = test.props;
var gun = Gun('http://'+ env.config.IP + ':' + (env.config.port + 1) + '/gun');
window.gun = gun;
var user = window.user = gun.user();
user.auth('alice', 'xyzabcmnopq', function(ack){
if(ack.err || !ack.pub){ return }
test.done();
});
}, {i: 1, config: config})
});
it("Alice write.", function(){
return again.alice.run(function(test){
test.async();
console.log("write...");
user.get('who').get('said').set({
what: "AAA"
}, function(ack){
if(ack.err){ return }
test.done();
});
});
});
it("Have Bob listen", function(){
return bob.run(function(test){
test.async();
console.log(window.count);
setTimeout(function(){
if('AAA' === window.count[1].what){
test.done();
}
}, 1200);
});
});
it("All finished!", function(done){
console.log("Done! Cleaning things up...");
setTimeout(function(){
done();
},1000);
});
after("Everything shut down.", function(){
browsers.run(function(){
//location.reload();
//setTimeout(function(){
//}, 15 * 1000);
});
return servers.run(function(){
process.exit();
});
});
});

134
test/ptsd/streampipe.js Normal file
View File

@ -0,0 +1,134 @@
const stream = require('stream')
const Gun = require('gun')
const randomString = length => {
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
let text = ''
for (var i = 0; i < length; i++) {
text += possible[Math.floor(Math.random() * possible.length)]
}
return text
}
// Generator
// generates stream of json {id: "", name: "", description: ""}
class Generator extends stream.Readable {
constructor(n) {
super()
this._n = n
this._i = 0
}
_read(size) {
if (this._i < this._n) {
this.push(
JSON.stringify({
id: `${this._i}`,
name: randomString(20),
description: randomString(200)
})
)
this.push('\n')
this._i++
} else {
this.push(null)
}
}
}
// Line
// read line by line as stream comes through it
class Line extends stream.Transform {
constructor() {
super()
this.buff = ''
}
trySendLine() {
let index = this.buff.indexOf(`\n`)
while (index !== -1) {
const line = this.buff.slice(0, index)
this.buff = this.buff.slice(index + 1)
this.push(line)
index = this.buff.indexOf(`\n`)
}
}
_transform(chunk, enc, cb) {
this.buff += chunk.toString()
this.trySendLine()
cb()
}
end() {
this.trySendLine()
if (this.buff.length > 0) {
this.push(this.buff)
}
}
}
// Graph
// parse the chunk and tries to add it to table
class Graph extends stream.Transform {
constructor() {
super()
this.db = new Gun({
//file: 'graph.json'
localStorage: false
})
this.items = this.db.get('items')
}
_transform(chunk, enc, cb) {
const json = JSON.parse(chunk.toString())
const item = this.db.get(json.id)
item.put(
{
id: json.id,
name: json.name,
description: json.description
},
() => {
this.items.set(item, () => {
this.push(chunk)
cb()
})
}
)
}
}
// Report
// shows how many item has pass through the system
class Report extends stream.Transform {
constructor() {
super()
this._count = 0
}
_transform(chunk, enc, cb) {
this.push(`count: ${this._count++}\r`)
cb()
}
}
const generator = new Generator(5000)
const line = new Line()
const graph = new Graph()
const report = new Report()
generator
.pipe(line)
.pipe(graph)
.pipe(report)
.pipe(process.stdout)

33
test/sea-tmp.html Normal file
View File

@ -0,0 +1,33 @@
<script src="../gun.js"></script>
<script src="../lib/cryptomodules.js"></script>
<script src="../sea.js"></script>
<script>
;(function(){
localStorage.clear();
var gun = window.gun = Gun();
var user = gun.user();
user.create('alice', 'unsafepassword', login);
function login(ack){
console.log("login...");
user.auth('alice', 'unsafepassword', write);
}
function write(data){
console.log("write...");
user.get('profile').get('said').set({
what: "Hello world!"
}, get);
}
function get(){
console.log("get...");
user.get('profile').get('said').map().val(function(data){
console.log("read...", data);
})
}
}());
</script>