mirror of
https://github.com/amark/gun.git
synced 2025-10-14 00:59:35 +00:00
Merge to gun/master 0.9.8 conflicts resolved
This commit is contained in:
commit
ac31e953c4
@ -135,7 +135,7 @@ Thanks to:<br/>
|
|||||||
|
|
||||||
This would not be possible without **community contributors**, big shout out to:
|
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!
|
I am missing many others, apologies, will be adding them soon!
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.send {
|
.send {
|
||||||
style: margin: 0 0 0.4em 0.4em;
|
margin: 0 0 0.4em 0.4em;
|
||||||
padding: 0.2em 0.5em;
|
padding: 0.2em 0.5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,8 @@
|
|||||||
margin: 1em 0;
|
margin: 1em 0;
|
||||||
padding: 1em;
|
padding: 1em;
|
||||||
border: none;
|
border: none;
|
||||||
background: white;
|
background: rgba(100%, 100%, 100%, 0.9);
|
||||||
|
back-ground: white;
|
||||||
}
|
}
|
||||||
.sigbut {
|
.sigbut {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
@ -56,7 +57,7 @@
|
|||||||
<ul>
|
<ul>
|
||||||
<a href="person" name="#">
|
<a href="person" name="#">
|
||||||
<li>
|
<li>
|
||||||
<span name="profile">
|
<span name="who">
|
||||||
<b name="name"></b>
|
<b name="name"></b>
|
||||||
</span>
|
</span>
|
||||||
<i>~</i><i name="alias"></i>
|
<i>~</i><i name="alias"></i>
|
||||||
@ -86,7 +87,7 @@
|
|||||||
|
|
||||||
<div id="person" class="hue3 page">
|
<div id="person" class="hue3 page">
|
||||||
<div class="pad">
|
<div class="pad">
|
||||||
<div name="profile">
|
<div name="who">
|
||||||
<!-- img src="" -->
|
<!-- img src="" -->
|
||||||
<h2 name="name" contenteditable="true">Name</h2>
|
<h2 name="name" contenteditable="true">Name</h2>
|
||||||
<i name="born"></i>
|
<i name="born"></i>
|
||||||
@ -97,7 +98,7 @@
|
|||||||
</form>
|
</form>
|
||||||
<div>
|
<div>
|
||||||
<ul name="said">
|
<ul name="said">
|
||||||
<li name="#"><span name="what"></span></li>
|
<li name="#" class="shade rim"><div name="what" class="rim"></div></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -109,15 +110,21 @@
|
|||||||
<p>A mysterious new example app has appeared! It is not finished/ready yet.</p>
|
<p>A mysterious new example app has appeared! It is not finished/ready yet.</p>
|
||||||
</div id="info">
|
</div id="info">
|
||||||
|
|
||||||
<script src="../jquery.js"></script>
|
<!-- script src="/Users/mark/Dropbox/Public/gun/db/examples/jquery.js"></script>
|
||||||
<script src="../../gun.js"></script>
|
<script src="/Users/mark/Dropbox/Public/gun/db/gun.js"></script>
|
||||||
<script src="../../lib/cryptomodules.js"></script>
|
<script src="/Users/mark/Dropbox/Public/gun/db/lib/cryptomodules.js"></script>
|
||||||
<script src="../../sea.js"></script>
|
<script src="/Users/mark/Dropbox/Public/gun/db/sea.js"></script>
|
||||||
<script src="../../as.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>
|
<script>
|
||||||
//var gun = Gun('http://localhost:8080/gun'); // DOESN'T WORK YET :(
|
var gun = Gun(location.origin+'/gun');
|
||||||
var gun = Gun();
|
//var gun = Gun();
|
||||||
var app = gun.get('example/contacts/4');
|
var app = gun.get('example/contacts/6');
|
||||||
var user = gun.user();
|
var user = gun.user();
|
||||||
var c = window.c = {};
|
var c = window.c = {};
|
||||||
(function(){
|
(function(){
|
||||||
@ -203,7 +210,7 @@
|
|||||||
(function(){
|
(function(){
|
||||||
$(document).on('submit', '#say', function(e){
|
$(document).on('submit', '#say', function(e){
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
user.get('profile').get('said').set({
|
user.get('who').get('said').set({
|
||||||
what: $(this).find('.jot').val()
|
what: $(this).find('.jot').val()
|
||||||
});
|
});
|
||||||
$(this).find('.jot').val('');
|
$(this).find('.jot').val('');
|
||||||
@ -219,7 +226,7 @@
|
|||||||
as.route.page('person', function(){
|
as.route.page('person', function(){
|
||||||
if(!user.is){ return as.route('sign') }
|
if(!user.is){ return as.route('sign') }
|
||||||
var pub = location.hash.split('/').slice(-1)[0];
|
var pub = location.hash.split('/').slice(-1)[0];
|
||||||
as('#person', gun.get('pub/'+pub));
|
as('#person', window.PUB = gun.get('pub/'+pub));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
|
<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>
|
<script>
|
||||||
function Where(opt, cb){
|
function Where(opt, cb){
|
||||||
// a small wrapper around Leaflet for map tracking.
|
// a small wrapper around Leaflet for map tracking.
|
||||||
|
@ -62,6 +62,13 @@ input, textarea {
|
|||||||
background: white;
|
background: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.shade {
|
||||||
|
background: rgba(0%, 0%, 0%, 0.1);
|
||||||
|
}
|
||||||
|
.tint {
|
||||||
|
background: rgba(100%, 100%, 100%, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
.redt {
|
.redt {
|
||||||
color: #ea3224;
|
color: #ea3224;
|
||||||
}
|
}
|
||||||
@ -88,6 +95,10 @@ input, textarea {
|
|||||||
max-width: 50em;
|
max-width: 50em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.rim {
|
||||||
|
margin: 2%;
|
||||||
|
}
|
||||||
|
|
||||||
.right {
|
.right {
|
||||||
float: right;
|
float: right;
|
||||||
}
|
}
|
||||||
@ -125,17 +136,17 @@ input, textarea {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@keyframes hue {
|
@keyframes hue {
|
||||||
0% {background: #4D79D8;}
|
0% {background-color: #4D79D8;}
|
||||||
25% {background: #33cc33;}
|
25% {background-color: #33cc33;}
|
||||||
50% {background: #f2b919;}
|
50% {background-color: #f2b919;}
|
||||||
75% {background: #ea3224;}
|
75% {background-color: #ea3224;}
|
||||||
100% {background: #4D79D8;}
|
100% {background-color: #4D79D8;}
|
||||||
} @-webkit-keyframes hue {
|
} @-webkit-keyframes hue {
|
||||||
0% {background: #4D79D8;}
|
0% {background-color: #4D79D8;}
|
||||||
25% {background: #33cc33;}
|
25% {background-color: #33cc33;}
|
||||||
50% {background: #f2b919;}
|
50% {background-color: #f2b919;}
|
||||||
75% {background: #ea3224;}
|
75% {background-color: #ea3224;}
|
||||||
100% {background: #4D79D8;}
|
100% {background-color: #4D79D8;}
|
||||||
}
|
}
|
||||||
|
|
||||||
.huet {
|
.huet {
|
||||||
@ -165,17 +176,17 @@ input, textarea {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@keyframes hue2 {
|
@keyframes hue2 {
|
||||||
0% {background: #ea3224;}
|
0% {background-color: #ea3224;}
|
||||||
25% {background: #4D79D8;}
|
25% {background-color: #4D79D8;}
|
||||||
50% {background: #33cc33;}
|
50% {background-color: #33cc33;}
|
||||||
75% {background: #f2b919;}
|
75% {background-color: #f2b919;}
|
||||||
100% {background: #ea3224;}
|
100% {background-color: #ea3224;}
|
||||||
} @-webkit-keyframes hue2 {
|
} @-webkit-keyframes hue2 {
|
||||||
0% {background: #ea3224;}
|
0% {background-color: #ea3224;}
|
||||||
25% {background: #4D79D8;}
|
25% {background-color: #4D79D8;}
|
||||||
50% {background: #33cc33;}
|
50% {background-color: #33cc33;}
|
||||||
75% {background: #f2b919;}
|
75% {background-color: #f2b919;}
|
||||||
100% {background: #ea3224;}
|
100% {background-color: #ea3224;}
|
||||||
}
|
}
|
||||||
|
|
||||||
.huet2 {
|
.huet2 {
|
||||||
@ -205,17 +216,17 @@ input, textarea {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@keyframes hue3 {
|
@keyframes hue3 {
|
||||||
0% {background: #33cc33;}
|
0% {background-color: #33cc33;}
|
||||||
25% {background: #f2b919;}
|
25% {background-color: #f2b919;}
|
||||||
50% {background: #ea3224;}
|
50% {background-color: #ea3224;}
|
||||||
75% {background: #4D79D8;}
|
75% {background-color: #4D79D8;}
|
||||||
100% {background: #33cc33;}
|
100% {background-color: #33cc33;}
|
||||||
} @-webkit-keyframes hue3 {
|
} @-webkit-keyframes hue3 {
|
||||||
0% {background: #33cc33;}
|
0% {background-color: #33cc33;}
|
||||||
25% {background: #f2b919;}
|
25% {background-color: #f2b919;}
|
||||||
50% {background: #ea3224;}
|
50% {background-color: #ea3224;}
|
||||||
75% {background: #4D79D8;}
|
75% {background-color: #4D79D8;}
|
||||||
100% {background: #33cc33;}
|
100% {background-color: #33cc33;}
|
||||||
}
|
}
|
||||||
|
|
||||||
.huet3 {
|
.huet3 {
|
||||||
@ -245,17 +256,17 @@ input, textarea {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@keyframes hue4 {
|
@keyframes hue4 {
|
||||||
0% {background: #f2b919;}
|
0% {background-color: #f2b919;}
|
||||||
25% {background: #ea3224;}
|
25% {background-color: #ea3224;}
|
||||||
50% {background: #4D79D8;}
|
50% {background-color: #4D79D8;}
|
||||||
75% {background: #33cc33;}
|
75% {background-color: #33cc33;}
|
||||||
100% {background: #f2b919;}
|
100% {background-color: #f2b919;}
|
||||||
} @-webkit-keyframes hue4 {
|
} @-webkit-keyframes hue4 {
|
||||||
0% {background: #f2b919;}
|
0% {background-color: #f2b919;}
|
||||||
25% {background: #ea3224;}
|
25% {background-color: #ea3224;}
|
||||||
50% {background: #4D79D8;}
|
50% {background-color: #4D79D8;}
|
||||||
75% {background: #33cc33;}
|
75% {background-color: #33cc33;}
|
||||||
100% {background: #f2b919;}
|
100% {background-color: #f2b919;}
|
||||||
}
|
}
|
||||||
|
|
||||||
.huet4 {
|
.huet4 {
|
||||||
|
182
gun.js
182
gun.js
@ -6,19 +6,19 @@
|
|||||||
if(typeof global !== "undefined"){ root = global }
|
if(typeof global !== "undefined"){ root = global }
|
||||||
root = root || {};
|
root = root || {};
|
||||||
var console = root.console || {log: function(){}};
|
var console = root.console || {log: function(){}};
|
||||||
function require(arg){
|
function USE(arg){
|
||||||
return arg.slice? require[resolve(arg)] : function(mod, path){
|
return arg.slice? USE[R(arg)] : function(mod, path){
|
||||||
arg(mod = {exports: {}});
|
arg(mod = {exports: {}});
|
||||||
require[resolve(path)] = mod.exports;
|
USE[R(path)] = mod.exports;
|
||||||
}
|
}
|
||||||
function resolve(path){
|
function R(p){
|
||||||
return path.split('/').slice(-1).toString().replace('.js','');
|
return p.split('/').slice(-1).toString().replace('.js','');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(typeof module !== "undefined"){ var common = module }
|
if(typeof module !== "undefined"){ var common = module }
|
||||||
/* UNBUILD */
|
/* UNBUILD */
|
||||||
|
|
||||||
;require(function(module){
|
;USE(function(module){
|
||||||
// Generic javascript utilities.
|
// Generic javascript utilities.
|
||||||
var Type = {};
|
var Type = {};
|
||||||
//Type.fns = Type.fn = {is: function(fn){ return (!!fn && fn instanceof Function) }}
|
//Type.fns = Type.fn = {is: function(fn){ return (!!fn && fn instanceof Function) }}
|
||||||
@ -163,9 +163,9 @@
|
|||||||
var list_is = Type.list.is;
|
var list_is = Type.list.is;
|
||||||
var obj = Type.obj, obj_is = obj.is, obj_has = obj.has, obj_map = obj.map;
|
var obj = Type.obj, obj_is = obj.is, obj_has = obj.has, obj_map = obj.map;
|
||||||
module.exports = Type;
|
module.exports = Type;
|
||||||
})(require, './type');
|
})(USE, './type');
|
||||||
|
|
||||||
;require(function(module){
|
;USE(function(module){
|
||||||
// On event emitter generic javascript utility.
|
// On event emitter generic javascript utility.
|
||||||
module.exports = function onto(tag, arg, as){
|
module.exports = function onto(tag, arg, as){
|
||||||
if(!tag){ return {to: onto} }
|
if(!tag){ return {to: onto} }
|
||||||
@ -203,9 +203,9 @@
|
|||||||
(tag = tag.to).next(arg);
|
(tag = tag.to).next(arg);
|
||||||
return tag;
|
return tag;
|
||||||
};
|
};
|
||||||
})(require, './onto');
|
})(USE, './onto');
|
||||||
|
|
||||||
;require(function(module){
|
;USE(function(module){
|
||||||
/* Based on the Hypothetical Amnesia Machine thought experiment */
|
/* Based on the Hypothetical Amnesia Machine thought experiment */
|
||||||
function HAM(machineState, incomingState, currentState, incomingValue, currentValue){
|
function HAM(machineState, incomingState, currentState, incomingValue, currentValue){
|
||||||
if(machineState < incomingState){
|
if(machineState < incomingState){
|
||||||
@ -250,10 +250,10 @@
|
|||||||
}
|
}
|
||||||
var Lexical = JSON.stringify, undefined;
|
var Lexical = JSON.stringify, undefined;
|
||||||
module.exports = HAM;
|
module.exports = HAM;
|
||||||
})(require, './HAM');
|
})(USE, './HAM');
|
||||||
|
|
||||||
;require(function(module){
|
;USE(function(module){
|
||||||
var Type = require('./type');
|
var Type = USE('./type');
|
||||||
var Val = {};
|
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.
|
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 }
|
if(v === u){ return false }
|
||||||
@ -294,11 +294,11 @@
|
|||||||
var text_is = Type.text.is;
|
var text_is = Type.text.is;
|
||||||
var obj = Type.obj, obj_is = obj.is, obj_put = obj.put, obj_map = obj.map;
|
var obj = Type.obj, obj_is = obj.is, obj_put = obj.put, obj_map = obj.map;
|
||||||
module.exports = Val;
|
module.exports = Val;
|
||||||
})(require, './val');
|
})(USE, './val');
|
||||||
|
|
||||||
;require(function(module){
|
;USE(function(module){
|
||||||
var Type = require('./type');
|
var Type = USE('./type');
|
||||||
var Val = require('./val');
|
var Val = USE('./val');
|
||||||
var Node = {_: '_'};
|
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 = 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.
|
Node.soul.ify = function(n, o){ // put a soul on an object.
|
||||||
@ -353,11 +353,11 @@
|
|||||||
var soul_ = Node.soul._;
|
var soul_ = Node.soul._;
|
||||||
var u;
|
var u;
|
||||||
module.exports = Node;
|
module.exports = Node;
|
||||||
})(require, './node');
|
})(USE, './node');
|
||||||
|
|
||||||
;require(function(module){
|
;USE(function(module){
|
||||||
var Type = require('./type');
|
var Type = USE('./type');
|
||||||
var Node = require('./node');
|
var Node = USE('./node');
|
||||||
function State(){
|
function State(){
|
||||||
var t;
|
var t;
|
||||||
if(perf){
|
if(perf){
|
||||||
@ -437,12 +437,12 @@
|
|||||||
var fn = Type.fn, fn_is = fn.is;
|
var fn = Type.fn, fn_is = fn.is;
|
||||||
var N_ = Node._, u;
|
var N_ = Node._, u;
|
||||||
module.exports = State;
|
module.exports = State;
|
||||||
})(require, './state');
|
})(USE, './state');
|
||||||
|
|
||||||
;require(function(module){
|
;USE(function(module){
|
||||||
var Type = require('./type');
|
var Type = USE('./type');
|
||||||
var Val = require('./val');
|
var Val = USE('./val');
|
||||||
var Node = require('./node');
|
var Node = USE('./node');
|
||||||
var Graph = {};
|
var Graph = {};
|
||||||
;(function(){
|
;(function(){
|
||||||
Graph.is = function(g, cb, fn, as){ // checks to see if an object is a valid graph.
|
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 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;
|
var u;
|
||||||
module.exports = Graph;
|
module.exports = Graph;
|
||||||
})(require, './graph');
|
})(USE, './graph');
|
||||||
|
|
||||||
;require(function(module){
|
;USE(function(module){
|
||||||
// request / response module, for asking and acking messages.
|
// request / response module, for asking and acking messages.
|
||||||
require('./onto'); // depends upon onto!
|
USE('./onto'); // depends upon onto!
|
||||||
module.exports = function ask(cb, as){
|
module.exports = function ask(cb, as){
|
||||||
if(!this.on){ return }
|
if(!this.on){ return }
|
||||||
if(!(cb instanceof Function)){
|
if(!(cb instanceof Function)){
|
||||||
@ -613,10 +613,10 @@
|
|||||||
}, (this.opt||{}).lack || 9000);
|
}, (this.opt||{}).lack || 9000);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
})(require, './ask');
|
})(USE, './ask');
|
||||||
|
|
||||||
;require(function(module){
|
;USE(function(module){
|
||||||
var Type = require('./type');
|
var Type = USE('./type');
|
||||||
function Dup(opt){
|
function Dup(opt){
|
||||||
var dup = {s:{}};
|
var dup = {s:{}};
|
||||||
opt = opt || {max: 1000, age: 1000 * 9};//1000 * 60 * 2};
|
opt = opt || {max: 1000, age: 1000 * 9};//1000 * 60 * 2};
|
||||||
@ -640,9 +640,9 @@
|
|||||||
}
|
}
|
||||||
var time_is = Type.time.is;
|
var time_is = Type.time.is;
|
||||||
module.exports = Dup;
|
module.exports = Dup;
|
||||||
})(require, './dup');
|
})(USE, './dup');
|
||||||
|
|
||||||
;require(function(module){
|
;USE(function(module){
|
||||||
|
|
||||||
function Gun(o){
|
function Gun(o){
|
||||||
if(o instanceof Gun){ return (this._ = {gun: this}).gun }
|
if(o instanceof Gun){ return (this._ = {gun: this}).gun }
|
||||||
@ -657,16 +657,16 @@
|
|||||||
Gun.chain = Gun.prototype;
|
Gun.chain = Gun.prototype;
|
||||||
Gun.chain.toJSON = function(){};
|
Gun.chain.toJSON = function(){};
|
||||||
|
|
||||||
var Type = require('./type');
|
var Type = USE('./type');
|
||||||
Type.obj.to(Type, Gun);
|
Type.obj.to(Type, Gun);
|
||||||
Gun.HAM = require('./HAM');
|
Gun.HAM = USE('./HAM');
|
||||||
Gun.val = require('./val');
|
Gun.val = USE('./val');
|
||||||
Gun.node = require('./node');
|
Gun.node = USE('./node');
|
||||||
Gun.state = require('./state');
|
Gun.state = USE('./state');
|
||||||
Gun.graph = require('./graph');
|
Gun.graph = USE('./graph');
|
||||||
Gun.on = require('./onto');
|
Gun.on = USE('./onto');
|
||||||
Gun.ask = require('./ask');
|
Gun.ask = USE('./ask');
|
||||||
Gun.dup = require('./dup');
|
Gun.dup = USE('./dup');
|
||||||
|
|
||||||
Gun._ = { // some reserved key words, these are not the only ones.
|
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.
|
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){
|
function merge(node, soul){
|
||||||
var ctx = this, cat = ctx.gun._, at = (cat.next || empty)[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] = {
|
var msg = ctx.map[soul] = {
|
||||||
put: node,
|
put: node,
|
||||||
get: soul,
|
get: soul,
|
||||||
@ -783,7 +786,6 @@
|
|||||||
function map(msg, soul){
|
function map(msg, soul){
|
||||||
if(!msg.gun){ return }
|
if(!msg.gun){ return }
|
||||||
msg.gun._.root._.stop = {};
|
msg.gun._.root._.stop = {};
|
||||||
//console.log("map ->", soul, msg.put);
|
|
||||||
(msg.gun._).on('in', msg);
|
(msg.gun._).on('in', msg);
|
||||||
msg.gun._.root._.stop = {};
|
msg.gun._.root._.stop = {};
|
||||||
}
|
}
|
||||||
@ -864,12 +866,12 @@
|
|||||||
//console.log("<<<<<", msg.put);
|
//console.log("<<<<<", msg.put);
|
||||||
to.next(msg);
|
to.next(msg);
|
||||||
},1);
|
},1);
|
||||||
})
|
});
|
||||||
});*/
|
});*/
|
||||||
})(require, './root');
|
})(USE, './root');
|
||||||
|
|
||||||
;require(function(module){
|
;USE(function(module){
|
||||||
var Gun = require('./root');
|
var Gun = USE('./root');
|
||||||
Gun.chain.back = function(n, opt){ var tmp;
|
Gun.chain.back = function(n, opt){ var tmp;
|
||||||
n = n || 1;
|
n = n || 1;
|
||||||
if(-1 === n || Infinity === n){
|
if(-1 === n || Infinity === n){
|
||||||
@ -908,13 +910,13 @@
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
var empty = {}, u;
|
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
|
// 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
|
// is complicated and was extremely hard to build. If you port GUN to another
|
||||||
// language, consider implementing an easier API to build.
|
// language, consider implementing an easier API to build.
|
||||||
var Gun = require('./root');
|
var Gun = USE('./root');
|
||||||
Gun.chain.chain = function(){
|
Gun.chain.chain = function(){
|
||||||
var at = this._, chain = new this.constructor(this), cat = chain._, root;
|
var at = this._, chain = new this.constructor(this), cat = chain._, root;
|
||||||
cat.root = root = at.root;
|
cat.root = root = at.root;
|
||||||
@ -1162,9 +1164,9 @@
|
|||||||
Gun.obj.del(at, 'ask'); // TODO: PERFORMANCE? More elegant way?
|
Gun.obj.del(at, 'ask'); // TODO: PERFORMANCE? More elegant way?
|
||||||
}
|
}
|
||||||
function ack(msg, ev){
|
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(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 }
|
if(at.put !== u){ return }
|
||||||
//at.ack = 0;
|
//at.ack = 0;
|
||||||
at.on('in', {
|
at.on('in', {
|
||||||
@ -1175,6 +1177,10 @@
|
|||||||
})
|
})
|
||||||
return;
|
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 }
|
//if(/*!msg.gun &&*/ !get['.'] && get['#']){ at.ack = (at.ack + 1) || 1 }
|
||||||
//msg = obj_to(msg);
|
//msg = obj_to(msg);
|
||||||
msg.gun = at.root;
|
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 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 text_rand = Gun.text.random;
|
||||||
var _soul = Gun._.soul, _field = Gun._.field, node_ = Gun.node._;
|
var _soul = Gun._.soul, _field = Gun._.field, node_ = Gun.node._;
|
||||||
})(require, './chain');
|
})(USE, './chain');
|
||||||
|
|
||||||
;require(function(module){
|
;USE(function(module){
|
||||||
var Gun = require('./root');
|
var Gun = USE('./root');
|
||||||
Gun.chain.get = function(key, cb, as){
|
Gun.chain.get = function(key, cb, as){
|
||||||
if(typeof key === 'string'){
|
if(typeof key === 'string'){
|
||||||
var gun, back = this, cat = back._;
|
var gun, back = this, cat = back._;
|
||||||
@ -1228,7 +1234,7 @@
|
|||||||
var cat = back._, next = cat.next, gun = back.chain(), at = gun._;
|
var cat = back._, next = cat.next, gun = back.chain(), at = gun._;
|
||||||
if(!next){ next = cat.next = {} }
|
if(!next){ next = cat.next = {} }
|
||||||
next[at.get = key] = gun;
|
next[at.get = key] = gun;
|
||||||
if(cat.root === back){
|
if(cat.root === back){
|
||||||
at.soul = key;
|
at.soul = key;
|
||||||
} else
|
} else
|
||||||
if(cat.soul || cat.field || cat.has){ // TODO: Convert field to has!
|
if(cat.soul || cat.field || cat.has){ // TODO: Convert field to has!
|
||||||
@ -1260,10 +1266,10 @@
|
|||||||
var num_is = Gun.num.is;
|
var num_is = Gun.num.is;
|
||||||
var rel = Gun.val.rel, node_ = Gun.node._;
|
var rel = Gun.val.rel, node_ = Gun.node._;
|
||||||
var empty = {}, u;
|
var empty = {}, u;
|
||||||
})(require, './get');
|
})(USE, './get');
|
||||||
|
|
||||||
;require(function(module){
|
;USE(function(module){
|
||||||
var Gun = require('./root');
|
var Gun = USE('./root');
|
||||||
Gun.chain.put = function(data, cb, as){
|
Gun.chain.put = function(data, cb, as){
|
||||||
// #soul.field=value>state
|
// #soul.field=value>state
|
||||||
// ~who#where.where=what>when@was
|
// ~who#where.where=what>when@was
|
||||||
@ -1468,7 +1474,10 @@
|
|||||||
as.soul = (opt.uuid || cat.root._.opt.uuid || Gun.text.random)();
|
as.soul = (opt.uuid || cat.root._.opt.uuid || Gun.text.random)();
|
||||||
} else {
|
} else {
|
||||||
//as.data = obj_put({}, as.gun._.get, as.data);
|
//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
|
if(!as.soul){ // polyfill async uuid for SEA
|
||||||
as.ref.back('opt.uuid')(function(err, soul){ // TODO: improve perf without anonymous callback
|
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 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 u, empty = {}, noop = function(){}, iife = function(fn,as){fn.call(as||empty)};
|
||||||
})(require, './put');
|
var node_ = Gun.node._;
|
||||||
|
})(USE, './put');
|
||||||
|
|
||||||
;require(function(module){
|
;USE(function(module){
|
||||||
var Gun = require('./root');
|
var Gun = USE('./root');
|
||||||
require('./chain');
|
USE('./chain');
|
||||||
require('./back');
|
USE('./back');
|
||||||
require('./put');
|
USE('./put');
|
||||||
require('./get');
|
USE('./get');
|
||||||
module.exports = Gun;
|
module.exports = Gun;
|
||||||
})(require, './index');
|
})(USE, './index');
|
||||||
|
|
||||||
;require(function(module){
|
;USE(function(module){
|
||||||
var Gun = require('./index');
|
var Gun = USE('./index');
|
||||||
Gun.chain.on = function(tag, arg, eas, as){
|
Gun.chain.on = function(tag, arg, eas, as){
|
||||||
var gun = this, at = gun._, tmp, act, off;
|
var gun = this, at = gun._, tmp, act, off;
|
||||||
if(typeof tag === 'string'){
|
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 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 rel = Gun.val.rel;
|
||||||
var empty = {}, noop = function(){}, u;
|
var empty = {}, noop = function(){}, u;
|
||||||
})(require, './on');
|
})(USE, './on');
|
||||||
|
|
||||||
;require(function(module){
|
;USE(function(module){
|
||||||
var Gun = require('./index');
|
var Gun = USE('./index');
|
||||||
Gun.chain.map = function(cb, opt, t){
|
Gun.chain.map = function(cb, opt, t){
|
||||||
var gun = this, cat = gun._, chain;
|
var gun = this, cat = gun._, chain;
|
||||||
if(!cb){
|
if(!cb){
|
||||||
@ -1679,10 +1689,10 @@
|
|||||||
(tmp.echo || (tmp.echo = {}))[at.id] = at;
|
(tmp.echo || (tmp.echo = {}))[at.id] = at;
|
||||||
}
|
}
|
||||||
var obj_map = Gun.obj.map, noop = function(){}, event = {stun: noop, off: noop}, n_ = Gun.node._, u;
|
var obj_map = Gun.obj.map, noop = function(){}, event = {stun: noop, off: noop}, n_ = Gun.node._, u;
|
||||||
})(require, './map');
|
})(USE, './map');
|
||||||
|
|
||||||
;require(function(module){
|
;USE(function(module){
|
||||||
var Gun = require('./index');
|
var Gun = USE('./index');
|
||||||
Gun.chain.set = function(item, cb, opt){
|
Gun.chain.set = function(item, cb, opt){
|
||||||
var gun = this, soul;
|
var gun = this, soul;
|
||||||
cb = cb || function(){};
|
cb = cb || function(){};
|
||||||
@ -1698,16 +1708,18 @@
|
|||||||
item.get('_').get(function(at, ev){
|
item.get('_').get(function(at, ev){
|
||||||
if(!at.gun || !at.gun._.back){ return }
|
if(!at.gun || !at.gun._.back){ return }
|
||||||
ev.off();
|
ev.off();
|
||||||
|
var soul = (at.put||{})['#'];
|
||||||
at = (at.gun._.back._);
|
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 + '"!')}) }
|
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);
|
gun.put(Gun.obj.put(put, soul, Gun.val.rel.ify(soul)), cb, opt);
|
||||||
},{wait:0});
|
},{wait:0});
|
||||||
return item;
|
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?
|
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;
|
var root, noop = function(){}, u;
|
||||||
@ -1781,10 +1793,10 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})(require, './adapters/localStorage');
|
})(USE, './adapters/localStorage');
|
||||||
|
|
||||||
;require(function(module){
|
;USE(function(module){
|
||||||
var Gun = require('./index');
|
var Gun = USE('./index');
|
||||||
var websocket;
|
var websocket;
|
||||||
if(typeof WebSocket !== 'undefined'){
|
if(typeof WebSocket !== 'undefined'){
|
||||||
websocket = WebSocket;
|
websocket = WebSocket;
|
||||||
@ -1887,6 +1899,6 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
var noop = function(){};
|
var noop = function(){};
|
||||||
})(require, './adapters/websocket');
|
})(USE, './adapters/websocket');
|
||||||
|
|
||||||
}());
|
}());
|
@ -88,10 +88,11 @@ var undent = function(code, n){
|
|||||||
write('src/polyfill/unbuild.js', undent(code, 1));
|
write('src/polyfill/unbuild.js', undent(code, 1));
|
||||||
|
|
||||||
(function recurse(c){
|
(function recurse(c){
|
||||||
code = next(";require(function(module){", "})(require");
|
code = next(";USE(function(module){", "})(USE");
|
||||||
if(!code){ return }
|
if(!code){ return }
|
||||||
var file = path();
|
var file = path();
|
||||||
if(!file){ return }
|
if(!file){ return }
|
||||||
|
code = code.replace(/\bUSE\(/g, 'require(');
|
||||||
write(file, undent(code));
|
write(file, undent(code));
|
||||||
recurse();
|
recurse();
|
||||||
}());
|
}());
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "gun",
|
"name": "gun",
|
||||||
"version": "0.9.7",
|
"version": "0.9.8",
|
||||||
"description": "Graph engine",
|
"description": "Graph engine",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"browser": "gun.min.js",
|
"browser": "gun.min.js",
|
||||||
|
13
sea.js
13
sea.js
@ -903,6 +903,12 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
check['any'+soul+key] = 1;
|
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();
|
at.on('secure', function(msg){ this.off();
|
||||||
check['any'+soul+key] = 0;
|
check['any'+soul+key] = 0;
|
||||||
each.end(msg || {err: "Data cannot be modified."});
|
each.end(msg || {err: "Data cannot be modified."});
|
||||||
@ -914,6 +920,13 @@
|
|||||||
each.end({err: "Soul is not signed at '" + key + "'."});
|
each.end({err: "Soul is not signed at '" + key + "'."});
|
||||||
return;
|
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;
|
check['any'+soul+key] = 1;
|
||||||
SEA.verify(tmp[0], user.pub, tmp[1], function(ok){
|
SEA.verify(tmp[0], user.pub, tmp[1], function(ok){
|
||||||
if(!ok){ return each.end({err: "Signature did not match account at '" + key + "'."}) }
|
if(!ok){ return each.end({err: "Signature did not match account at '" + key + "'."}) }
|
||||||
|
@ -39,7 +39,7 @@ function cache(key, back){
|
|||||||
var cat = back._, next = cat.next, gun = back.chain(), at = gun._;
|
var cat = back._, next = cat.next, gun = back.chain(), at = gun._;
|
||||||
if(!next){ next = cat.next = {} }
|
if(!next){ next = cat.next = {} }
|
||||||
next[at.get = key] = gun;
|
next[at.get = key] = gun;
|
||||||
if(cat.root === back){
|
if(cat.root === back){
|
||||||
at.soul = key;
|
at.soul = key;
|
||||||
} else
|
} else
|
||||||
if(cat.soul || cat.field || cat.has){ // TODO: Convert field to has!
|
if(cat.soul || cat.field || cat.has){ // TODO: Convert field to has!
|
||||||
|
@ -4,13 +4,13 @@ if(typeof window !== "undefined"){ root = window }
|
|||||||
if(typeof global !== "undefined"){ root = global }
|
if(typeof global !== "undefined"){ root = global }
|
||||||
root = root || {};
|
root = root || {};
|
||||||
var console = root.console || {log: function(){}};
|
var console = root.console || {log: function(){}};
|
||||||
function require(arg){
|
function USE(arg){
|
||||||
return arg.slice? require[resolve(arg)] : function(mod, path){
|
return arg.slice? USE[R(arg)] : function(mod, path){
|
||||||
arg(mod = {exports: {}});
|
arg(mod = {exports: {}});
|
||||||
require[resolve(path)] = mod.exports;
|
USE[R(path)] = mod.exports;
|
||||||
}
|
}
|
||||||
function resolve(path){
|
function R(p){
|
||||||
return path.split('/').slice(-1).toString().replace('.js','');
|
return p.split('/').slice(-1).toString().replace('.js','');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(typeof module !== "undefined"){ var common = module }
|
if(typeof module !== "undefined"){ var common = module }
|
||||||
|
@ -204,7 +204,10 @@ function any(at, ev){
|
|||||||
as.soul = (opt.uuid || cat.root._.opt.uuid || Gun.text.random)();
|
as.soul = (opt.uuid || cat.root._.opt.uuid || Gun.text.random)();
|
||||||
} else {
|
} else {
|
||||||
//as.data = obj_put({}, as.gun._.get, as.data);
|
//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
|
if(!as.soul){ // polyfill async uuid for SEA
|
||||||
as.ref.back('opt.uuid')(function(err, soul){ // TODO: improve perf without anonymous callback
|
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 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 u, empty = {}, noop = function(){}, iife = function(fn,as){fn.call(as||empty)};
|
||||||
|
var node_ = Gun.node._;
|
||||||
|
|
@ -101,7 +101,10 @@ Gun._ = { // some reserved key words, these are not the only ones.
|
|||||||
}
|
}
|
||||||
function merge(node, soul){
|
function merge(node, soul){
|
||||||
var ctx = this, cat = ctx.gun._, at = (cat.next || empty)[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] = {
|
var msg = ctx.map[soul] = {
|
||||||
put: node,
|
put: node,
|
||||||
get: soul,
|
get: soul,
|
||||||
@ -139,7 +142,6 @@ Gun._ = { // some reserved key words, these are not the only ones.
|
|||||||
function map(msg, soul){
|
function map(msg, soul){
|
||||||
if(!msg.gun){ return }
|
if(!msg.gun){ return }
|
||||||
msg.gun._.root._.stop = {};
|
msg.gun._.root._.stop = {};
|
||||||
//console.log("map ->", soul, msg.put);
|
|
||||||
(msg.gun._).on('in', msg);
|
(msg.gun._).on('in', msg);
|
||||||
msg.gun._.root._.stop = {};
|
msg.gun._.root._.stop = {};
|
||||||
}
|
}
|
||||||
@ -220,6 +222,5 @@ module.exports = Gun;
|
|||||||
//console.log("<<<<<", msg.put);
|
//console.log("<<<<<", msg.put);
|
||||||
to.next(msg);
|
to.next(msg);
|
||||||
},1);
|
},1);
|
||||||
})
|
});
|
||||||
});*/
|
});*/
|
||||||
|
|
@ -15,8 +15,10 @@ Gun.chain.set = function(item, cb, opt){
|
|||||||
item.get('_').get(function(at, ev){
|
item.get('_').get(function(at, ev){
|
||||||
if(!at.gun || !at.gun._.back){ return }
|
if(!at.gun || !at.gun._.back){ return }
|
||||||
ev.off();
|
ev.off();
|
||||||
|
var soul = (at.put||{})['#'];
|
||||||
at = (at.gun._.back._);
|
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 + '"!')}) }
|
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);
|
gun.put(Gun.obj.put(put, soul, Gun.val.rel.ify(soul)), cb, opt);
|
||||||
},{wait:0});
|
},{wait:0});
|
||||||
|
27
test/debug/deep-set.html
Normal file
27
test/debug/deep-set.html
Normal 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
200
test/panic/set.js
Normal 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
250
test/panic/who.js
Normal 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
134
test/ptsd/streampipe.js
Normal 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
33
test/sea-tmp.html
Normal 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>
|
Loading…
x
Reference in New Issue
Block a user