Skip to content

Commit

Permalink
Merge branch 'master' of http://github.com/amark/gun
Browse files Browse the repository at this point in the history
  • Loading branch information
amark committed Nov 10, 2023
2 parents 96b1402 + 0251de1 commit 5d3cbac
Show file tree
Hide file tree
Showing 27 changed files with 104 additions and 97 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# install packages
FROM node:14-alpine as builder
FROM node:lts-alpine as builder
RUN mkdir /work
WORKDIR /work
RUN apk add --no-cache alpine-sdk python3
Expand All @@ -8,7 +8,7 @@ RUN mkdir -p node_modules
RUN npm ci --only=production

# fresh image without dev packages
FROM node:14-alpine
FROM node:lts-alpine
# build-time metadata as defined at http://label-schema.org
ARG BUILD_DATE
ARG VCS_REF
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<p id="readme"><a href="https://gun.eco/"><img width="40%" src="https://cldup.com/TEy9yGh45l.svg"/></a><img width="50%" align="right" vspace="25" src="https://gun.eco/see/demo.gif"/></p>

[![](https://data.jsdelivr.com/v1/package/gh/amark/gun/badge?style=rounded)](https://data.jsdelivr.com/v1/package/gh/amark/gun/stats)
[![](https://data.jsdelivr.com/v1/package/npm/gun/badge)](https://www.jsdelivr.com/package/npm/gun)
![Build](https://github.com/amark/gun/actions/workflows/ci.yml/badge.svg)
[![Gitter](https://img.shields.io/gitter/room/amark/gun.js.svg)](http://chat.gun.eco)

**GUN** is an [ecosystem](https://gun.eco/docs/Ecosystem) of **tools** that let you build [community run](https://www.nbcnews.com/tech/tech-news/these-technologists-think-internet-broken-so-they-re-building-another-n1030136) and [encrypted applications](https://gun.eco/docs/Cartoon-Cryptography) - like an Open Source Firebase or a Decentralized Dropbox.

The [Internet Archive](https://news.ycombinator.com/item?id=17685682) and [100s of other apps](https://github.com/amark/gun/wiki/awesome-gun) run GUN in-production. GUN is also part of [Twitter's Bluesky](https://blueskycommunity.net/) initiative!
The [Internet Archive](https://news.ycombinator.com/item?id=17685682) and [100s of other apps](https://github.com/amark/gun/wiki/awesome-gun) run GUN in-production. GUN was also part of [Twitter's bluesky](https://blueskycommunity.net/) initiative!

+ Multiplayer by default with realtime p2p state synchronization!
+ Graph data lets you use key/value, tables, documents, videos, & more!
Expand Down Expand Up @@ -42,7 +42,7 @@ GUN is *super easy* to get started with:
> **Note:** If you don't have [node](http://nodejs.org/) or [npm](https://www.npmjs.com/), read [this](https://github.com/amark/gun/blob/master/examples/install.sh) first.
> If the `npm` command line didn't work, you may need to `mkdir node_modules` first or use `sudo`.
- An online demo of the examples are available here: http://gunjs.herokuapp.com/
- An online demo of the examples are available here: http://try.axe.eco/
- Or write a quick app: ([try now in a playground](https://jsbin.com/kadobamevo/edit?js,console))
```html
<script src="https://cdn.jsdelivr.net/npm/gun/gun.js"></script>
Expand Down Expand Up @@ -155,7 +155,9 @@ Thanks to:
<a href="https://hunterowens.com/">Hunter Owens</a>,
<a href="https://github.com/JacobMillner">Jacob Millner</a>,
<a href="https://github.com/b-lack">Gerrit Balindt</a>,
<a href="https://github.com/gabriellemon">Gabriel Lemon</a>
<a href="https://github.com/gabriellemon">Gabriel Lemon</a>,
<a href="https://github.com/murageyun">Murage Martin</a>,
<a href="https://github.com/octalmage">Jason Stallings</a>
</p>

- Join others in sponsoring code: https://www.patreon.com/gunDB !
Expand Down Expand Up @@ -211,7 +213,7 @@ This would not be possible without **community contributors**, big shout out to:

**[ajmeyghani](https://github.com/ajmeyghani) ([Learn GUN Basics with Diagrams](https://medium.com/@ajmeyghani/gundb-a-graph-database-in-javascript-3860a08d873c))**; **[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))**; **[Lightnet](https://github.com/Lightnet)** ([Awesome Vue User Examples](https://glitch.com/edit/#!/jsvuegunui?path=README.md:1:0) & [User Kitchen Sink Playground](https://gdb-auth-vue-node.glitch.me/)); **[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))**; **[rogowski](https://github.com/rogowski) (AXE)**; [sbeleidy](https://github.com/sbeleidy); **[sbiaudet](https://github.com/sbiaudet) ([C# Port](https://github.com/sbiaudet/cs-gun))**; **[Sean Matheson](https://github.com/ctrlplusb) ([Observable/RxJS/Most.js bindings](https://github.com/ctrlplusb/gun-most))**; **[Shadyzpop](https://github.com/Shadyzpop) ([React Native example](https://github.com/amark/gun/tree/master/examples/react-native))**; **[sjones6](https://github.com/sjones6) ([Flint](https://github.com/sjones6/gun-flint))**; RIP **[Stefdv](https://github.com/stefdv) (Polymer/web components)**; **[zrrrzzt](https://github.com/zrrrzzt) ([JWT Auth](https://gist.github.com/zrrrzzt/6f88dc3cedee4ee18588236756d2cfce))**; **[xmonader](https://github.com/xmonader) ([Python Port](https://github.com/xmonader/pygundb))**;

I am missing many others, apologies, will be adding them soon! This list is infintiely old & way out of date, if you want to be listed in it please make a PR! :)
I am missing many others, apologies, will be adding them soon! This list is infinitely old & way out of date, if you want to be listed in it please make a PR! :)

## Testing

Expand Down
2 changes: 1 addition & 1 deletion examples/angular/src/app/gun.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { pick } from 'underscore';
export function on$(node, cleanup = true): Observable<any> {
return Observable.fromEventPattern(
h => {
// there is no way to off() an on() until at least one value is trigerred
// there is no way to off() an on() until at least one value is triggered
// so that we can access the event listener to off() it
const signal = { stop: false };
node.on((data, key, at, ev) => {
Expand Down
2 changes: 1 addition & 1 deletion examples/json/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ <h3>Admin JSON Editor</h3>
color: skyblue;
background: transparent;
text-decoration: none;
cursor: poiner;
cursor: pointer;
}
ul, li {
list-style-type: none;
Expand Down
4 changes: 2 additions & 2 deletions examples/react-native/src/webview-crypto/serializeBinary.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/vue/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</head>
<body>
<div id="app">
This is example of simple Vue plugin. It works exatcly same as the Vue instance data property, but the name is gunData.<br>
This is example of simple Vue plugin. It works exactly same as the Vue instance data property, but the name is gunData.<br>
The cool part is that every property in the gunData is realtime synced via gunDB to every other page viewer!<br>
<table>
<tr>
Expand Down
4 changes: 2 additions & 2 deletions lib/axe.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function start(root){
if(root.axe){ return }
var opt = root.opt, peers = opt.peers;
if(false === opt.axe){ return }
if((typeof process !== "undefined") && 'false' === ''+(process.env||'').AXE){ return }
if((typeof process !== "undefined") && 'false' === ''+(opt.env=process.env||'').AXE){ return }
Gun.log.once("AXE", "AXE relay enabled!");
var axe = root.axe = {}, tmp, id;
var mesh = opt.mesh = opt.mesh || Gun.Mesh(root); // DAM!
Expand Down Expand Up @@ -219,7 +219,7 @@ function start(root){
The mob threshold might be determined by other factors,
like how much RAM or CPU stress we have.
*/
opt.mob = opt.mob || 9900; // should be based on ulimit, some clouds as low as 10K.
opt.mob = opt.mob || parseFloat((opt.env||'').MOB) || 9900; // should be based on ulimit, some clouds as low as 10K.

// handle rebalancing a mob of peers:
root.on('hi', function(peer){
Expand Down
8 changes: 4 additions & 4 deletions lib/les.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@
* - gc_delay : sets the amount of time between attempted garbage collections in milliseconds
* - gc_info_enable : Enables or Disables the info printout
* - gc_info : sets the ~ amount of time between info messages
* this is checked everytime the gc is ran
* this is checked every time the gc is ran
* - gc_info_mini : this will use a smaller, less user friendly info printout
* - gc_importance_func : This will be the function used for finding the importance of a potental collect
* - gc_importance_func : This will be the function used for finding the importance of a potential collect
* takes the form of func(timestamp, ctime, memoryUsageRatio) {return val}
* Collects when returned value is 100
*/

//NOTE: set to false to use require for getting gun DEFUALT: false
//NOTE: set to false to use require for getting gun DEFAULT: false
var USELOCALGUN = false;


//NOTE: adds some debug messages DEFUALT: false
//NOTE: adds some debug messages DEFAULT: false
var DEBUG = false;

if(!(typeof window !== "undefined") && USELOCALGUN)
Expand Down
4 changes: 2 additions & 2 deletions lib/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
var name, tag, tags = opt.tags;
for(name in tags) {
if(opt.hierarchy.indexOf(name)===-1)
throw Error('tag "'+name+'" is missing hierachy definition');
throw Error('tag "'+name+'" is missing hierarchy definition');
}
opt.hierarchy.forEach(function(name){
if(!tags[name]){
Expand All @@ -117,7 +117,7 @@

// GENERAL UTILS

function get(o, args){ // path argments as separate string parameters
function get(o, args){ // path arguments as separate string parameters
if(typeof args === 'string')
return o[args[0]];
var i = 0, l = args.length, u;
Expand Down
4 changes: 2 additions & 2 deletions lib/not.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ declare module '../types/gun/IGunChain' {
* through it, then you have a pretty reasonable assurance that a not found means that
* the data doesn't exist yet. Just be mindful of how you use it
*
* @param callack If there's reason to believe the data doesn't exist, the callback will be
* @param callback If there's reason to believe the data doesn't exist, the callback will be
* invoked. This can be used as a check to prevent implicitly writing data
*/
not(
callack: (key: string) => void
callback: (key: string) => void
): IGunChain<TNode, TChainParent, TGunInstance, TKey>;
}
}
6 changes: 3 additions & 3 deletions lib/promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Turn any part of a gun chain into a promise, that you can then use
* .then().catch() pattern.
* In normal gun doing var item = gun.get('someKey'), gun returns a reference
* to the someKey synchroneously. Using a reference is quite helpful in making
* to the someKey synchronously. Using a reference is quite helpful in making
* graph structures, so I have chosen to follow the following paradigm.
* Whenever a promise is resolved, gun will return an object of data, I will
* wrap that data in an object together with the reference like so:
Expand Down Expand Up @@ -62,7 +62,7 @@ function sleep (limit) {
* @param item (string / object) - item to be put to that key in the chain
* @param opt - option object
* @return object - Returns an object with the ref to that node that was just
* created as well as the 'ack' which acknowledges the put was succesful
* created as well as the 'ack' which acknowledges the put was successful
* object {ref: gunReference, ack: acknowledgmentObject}
* If put had an error we can catch the return via .catch
*/
Expand All @@ -82,7 +82,7 @@ Gun.chain.promPut = async function (item, opt) {
* @param item (string / object) - item to be set into a list at this key
* @param opt - option object
* @return object - Returns object with the ref to that node that was just
* created as well as the 'ack' which acknowledges the set was succesful
* created as well as the 'ack' which acknowledges the set was successful
* object {ref: gunReference, ack: acknowledgmentObject}
* If set had an error we can catch the return via .catch
*/
Expand Down
50 changes: 28 additions & 22 deletions lib/radisk3.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
;(function (){ // RAD
;(function(){ // RAD
console.log("Warning: Experimental rewrite of RAD to use Book. It is not API compatible with RAD yet and is very alpha.");
var sT = setTimeout, Book = sT.Book, RAD = sT.RAD || (sT.RAD = function (opt){
var sT = setTimeout, Book = sT.Book, RAD = sT.RAD || (sT.RAD = function(opt){
opt = opt || {};
opt.file = String(opt.file || 'radata');
var log = opt.log || nope;
Expand Down Expand Up @@ -30,7 +30,7 @@
var p = page || b.page(word);
reply = reply.call ? reply : () => { };
log(`read() ${word.slice(0, 40)}`);
get(p, function (err, disk){
get(p, function(err, disk){
if(err){ log("ERR! in read() get() cb", err); reply(err); return }
p.from = disk || p.from;
reply(null, p, b);
Expand All @@ -42,7 +42,7 @@
var p = b.page(word), tmp;
if(tmp = p.saving){ reply && tmp.push(reply); return } p.saving = [reply];
var S = +new Date; log(" writing", p.substring(), 'since last', S - p.saved, RAD.c, 'records', env.count++, 'mid-swap.');
get(p, function (err, disk){
get(p, function(err, disk){
if(err){ log("ERR! in write() get() cb ", err); return }
log(' get() - p.saving ', (p.saving || []).length);
if(p.from && disk){
Expand All @@ -52,7 +52,7 @@
// p.list = p.text = p.from = 0;
// p.first = p.first.word || p.first;
tmp = p.saving; p.saving = [];
put(p, '' + p, function (err, ok){
put(p, '' + p, function(err, ok){
env.count--; p.saved = +new Date; log(" ...wrote %d bytes in %dms", ('' + p).length, (p.saved = +new Date) - S);
// TODO: BUG: Confirmed! Only calls back first. Need to fix + use perf hack from old RAD.
sT.each(tmp, function(cb){ cb && cb(err, ok) });
Expand All @@ -61,30 +61,32 @@
console.log("hm?", word, reply+'');
write(word, reply);
});
})
}, p);
}
function put(file, data, cb){
file.first && (file = Book.slot(file.first)[0]);
put[file = fname(file)] = { data: data };
RAD.put(file, data, function (err, ok){
RAD.put(file, data, function(err, ok){
delete put[file];
cb && cb(err, ok);
});
};
function get(file, cb){
var tmp;
if(!file){ return } // TODO: HANDLE ERROR!!
if(file.from){ cb(null, file.from); return } // IS THIS LINE SAFE? ADD TESTS!
file.first && (file = Book.slot(file.first)[0]);
if(tmp = put[file = fname(file)]){ cb(u, tmp.data); return }
if(tmp = get[file]){ tmp.push(cb); return } get[file] = [cb];
RAD.get(file, function (err, data){
RAD.get(file, function(err, data){
tmp = get[file]; delete get[file];
var i = -1, f; while (f = tmp[++i]){ f(err, data) } // TODO: BUG! CPU SCHEDULE?
});
};

function start(word, is, reply){
if(b){ r(word, is, reply); return }
get(' ', function (err, d){
get(' ', function(err, d){
if(err){ log('ERR! in start() get()', err); reply && reply(err); return }
if(b){ r(word, is, reply); return }
//wrap(b = r.book = Book(d));
Expand All @@ -95,7 +97,7 @@
}
function watch(b){ // SPLIT LOGIC!
var split = b.split;
b.list.toString = function (){
b.list.toString = function(){
console.log("hi'");
console.time();
var i = -1, t = '', p; while (p = this[++i]){
Expand All @@ -105,9 +107,9 @@
console.timeEnd();
return t;
}
b.split = function (next, page){
b.split = function(next, page){
log("SPLIT!!!!", b.list.length);
put(' ', '' + b.list, function (err, ok){
put(' ', '' + b.list, function(err, ok){
if(err){ console.log("ERR!"); return }
// ??
});
Expand All @@ -119,6 +121,11 @@
function fname(p){ return opt.file + '/' + ename(p.substring()) }


function valid(word, is, reply){
if(is !== is){ reply(word +" cannot be NaN!"); return }
return true;
}

function valid(word, is, reply){
if(is !== is){ reply(word +" cannot be NaN!"); return }
return true;
Expand All @@ -130,7 +137,7 @@
try { module.exports = RAD } catch (e){ }

// junk below that needs to be cleaned up and corrected for the actual correct RAD API.
var env = {}, nope = function (){ }, nah = function (){ return nope }, u;
var env = {}, nope = function(){ }, nah = function(){ return nope }, u;
env.require = (typeof require !== '' + u && require) || nope;
env.process = (typeof process != '' + u && process) || { memoryUsage: nah };
env.os = env.require('os') || { totalmem: nope, freemem: nope };
Expand All @@ -145,7 +152,7 @@

//if(err && 'ENOENT' === (err.code||'').toUpperCase()){ err = null }

setInterval(function (){
setInterval(function(){
var stats = { memory: {} };

stats.memory.total = env.os.totalmem() / 1024 / 1024; // in MB
Expand All @@ -158,37 +165,37 @@
}());


; (function (){ // temporary fs storage plugin, needs to be refactored to use the actual RAD plugin interface.
; (function(){ // temporary fs storage plugin, needs to be refactored to use the actual RAD plugin interface.
var fs;
try { fs = require('fs') } catch (e){ };
if(!fs){ return }

var sT = setTimeout, RAD = sT.RAD;
RAD.put = function (file, data, cb){
RAD.put = function(file, data, cb){
fs.writeFile(file, data, cb);
}
RAD.get = function (file, cb){
fs.readFile(file, function (err, data){
RAD.get = function(file, cb){
fs.readFile(file, function(err, data){
if(err && 'ENOENT' === (err.code || '').toUpperCase()){ return cb() }
cb(err, data.toString());
});
}
}());


;(function (){ // temporary fs storage plugin, needs to be refactored to use the actual RAD plugin interface.
;(function(){ // temporary fs storage plugin, needs to be refactored to use the actual RAD plugin interface.
var lS;
try { lS = localStorage } catch (e){ };
if(!lS){ return }

var sT = setTimeout, RAD = sT.RAD;
RAD.put = function (file, data, cb){
RAD.put = function(file, data, cb){
setTimeout(function(){
lS[file] = data;
cb(null, 1);
},9);
}
RAD.get = function (file, cb){
RAD.get = function(file, cb){
setTimeout(function(){
cb(null, lS[file]);
},9);
Expand All @@ -204,7 +211,6 @@
RAD.put = function(file, data, cb){ cb(401) }
RAD.get = async function(file, cb){
var t = (await (await fetch('http://localhost:8765/gun/'+file)).text());
console.log("???file?", file, t);
if('404' == t){ cb(); return }
cb(null, t);
}
Expand Down

0 comments on commit 5d3cbac

Please sign in to comment.