-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
6,375 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,16 @@ | ||
{ | ||
"plugins": ["babel-plugin-add-module-exports"], | ||
"presets": ["es2015"] | ||
} | ||
"presets": [ | ||
"env", | ||
"stage-0", | ||
"react" | ||
], | ||
"plugins": [ | ||
"transform-object-rest-spread", | ||
["module-resolver", { "root": ["./src"] }] | ||
], | ||
"env": { | ||
"test": { | ||
"plugins": ["transform-es2015-modules-commonjs"] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Code of Conduct | ||
|
||
## Free Speech and Consideration | ||
|
||
Everyone has the right to communicate opinions and ideas without fear of censorship. Consideration shall be given to all constructive speech that is based in fact and reason. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2018 go1dfish | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,22 @@ | ||
ES6 library starter | ||
=========== | ||
|
||
[![Version](http://img.shields.io/npm/v/es6-library-minimal.svg)](https://www.npmjs.org/package/es6-library-minimal) | ||
[![Build Status](https://travis-ci.org/liady/es6-library-minimal.svg?branch=master)](https://travis-ci.org/liady/es6-library-minimal) | ||
[![Code style: airbnb](https://img.shields.io/badge/code%20style-airbnb-blue.svg?style=flat)](https://github.com/airbnb/javascript) | ||
> I think all censorship should be deplored. My position is that bits are **not a bug**. | ||
> | ||
> — Aaron Swartz (1986 - 2013) | ||
> A boilerplate for a universal (Node, web, UMD) ES6 library. | ||
**notabug** is a p2p link aggregator app that is: | ||
|
||
## Quick usage | ||
1. Clone this repo. | ||
2. Change all relevant entries in `package.json` and `README.md`, so they match your new shiny library. | ||
3. Run `npm install` to install dev dependencies. | ||
4. Write your ES6 code in `src` folder. | ||
5. Write your ES6 tests in `test` folder. | ||
6. Run `npm run build` to build for node. This will compile to ES5, minify, and output the result to `lib` folder. | ||
7. Run `npm run build-web` to build and pack the files for the web. This will output the result to `dist` folder. | ||
8. Run `npm publish` to pulish to the world. | ||
|
||
(Or, if you don't need Webpack bundling, you can use the [even lighter ES6 starter](https://github.com/liady/es6-lib-starter-light)). | ||
* distributed: peers backup/serve content | ||
* anonymous: but don't trust it to be | ||
* immutable: edits are not supported | ||
* PoW-based: **voting is slow/CPU heavy** | ||
|
||
## Detailed overview | ||
This repo is where the network communications code lives | ||
|
||
### Installation | ||
After cloning this repository, make sure to change all the relevant entries in `package.json` so they match your library. | ||
```sh | ||
npm install | ||
``` | ||
--- | ||
|
||
### Build for npm | ||
```sh | ||
npm run build | ||
``` | ||
This will: | ||
1. Run Webpack starting from the entry point file (`src/library.js`, can be configured) | ||
2. Convert all files in `src` folder from ES6 to ES5 | ||
3. According to the `bundle-node` flag in `package.json`, it will either: | ||
1. Leave them as separate files, or - | ||
2. Minify and bundle them using Webpack, **without their** `node_modules` **dependencies** | ||
4. Output the result to the `lib` folder | ||
BCH 1KtRnC9swwXbCTc8WFGBUT9pobYiizj1Ez | ||
BTC 13XvsLbkaiUud82sh9gh86vJB3neZRD2CK | ||
DCR DsYQVTvjyepvangZEy9CaJN16n1Zk97tejW | ||
LTC LPvfg2marjf7H16iDoa4xj7tmt5sVqw4mZ | ||
ETH 0x67857ED6e8834FE9f2ee8367DEc0AA0C7101B4Ab | ||
|
||
### Build for web | ||
```sh | ||
npm run build-web | ||
``` | ||
This will: | ||
1. Run Webpack starting from the entry point file (`src/library.js`, can be configured) | ||
2. Convert all files from ES6 to ES5 | ||
3. Minify them, **including all of their module dependencies**, as a UMD module (so the file will be self-contained) | ||
4. Output the file to the `dist` folder | ||
|
||
### Test | ||
```sh | ||
npm run test | ||
``` | ||
|
||
### Configuration | ||
In `package.json`, change all the relevant entries so they match your library.<br/> | ||
Under the section `library`, you can configure: | ||
1. Library name (defaults to `"Library"`) | ||
2. Webpack entry point (defaults to `library.js`) | ||
3. Dist folder for Node (defaults to `lib`) | ||
4. Dist folder for Web (defaults to `dist`) | ||
5. Choose whether to bundle for Node (defaults to `true`) | ||
|
||
## License | ||
MIT |
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
"use strict"; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.getCollectionsArray = exports.getCollections = exports.getCollection = exports.getScore = exports.getVoteCount = exports.getTimestamp = undefined; | ||
|
||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
|
||
var _compose = require("ramda/src/compose"); | ||
|
||
var _compose2 = _interopRequireDefault(_compose); | ||
|
||
var _pathOr = require("ramda/src/pathOr"); | ||
|
||
var _pathOr2 = _interopRequireDefault(_pathOr); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
var getTimestamp = exports.getTimestamp = function getTimestamp(peer) { | ||
return function (id) { | ||
return (0, _pathOr2.default)(0, ["things", id, "timestamp"], peer.getState()); | ||
}; | ||
}; | ||
|
||
var getVoteCount = exports.getVoteCount = function getVoteCount(peer) { | ||
return function (id, type) { | ||
return (0, _pathOr2.default)(0, ["things", id, "votes", type], peer.getState()); | ||
}; | ||
}; | ||
|
||
var getScore = exports.getScore = function getScore(peer) { | ||
return function (id) { | ||
return peer.getVoteCount(id, "up") - peer.getVoteCount(id, "down"); | ||
}; | ||
}; | ||
|
||
var getCollection = exports.getCollection = function getCollection(peer) { | ||
return function (soul) { | ||
return (0, _pathOr2.default)({}, ["collections", soul, "things"], peer.getState()); | ||
}; | ||
}; | ||
|
||
var getCollections = exports.getCollections = function getCollections(peer) { | ||
return function (souls) { | ||
return souls.reduce(function (ids, collection) { | ||
return _extends({}, ids, getCollection(peer)(collection)); | ||
}, {}); | ||
}; | ||
}; | ||
|
||
var getCollectionsArray = exports.getCollectionsArray = function getCollectionsArray(peer) { | ||
return (0, _compose2.default)(Object.keys, getCollections(peer)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
"use strict"; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.onLogin = exports.isLoggedIn = exports.user = exports.login = exports.signup = undefined; | ||
|
||
var _curry = require("ramda/src/curry"); | ||
|
||
var _curry2 = _interopRequireDefault(_curry); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
var signup = exports.signup = (0, _curry2.default)(function (peer, username, password) { | ||
return new Promise(function (ok, fail) { | ||
if (peer && peer.gun && peer.gun.user) { | ||
var _user = peer.user(); | ||
_user.create(username, password, function (ack) { | ||
if (ack.err) { | ||
fail(ack.err); | ||
_user.leave(); | ||
peer.gun.user().leave(); | ||
} else { | ||
ok(peer.login(username, password)); | ||
} | ||
}); | ||
} else { | ||
fail("SEA is not loaded"); | ||
} | ||
}); | ||
}); /* globals Gun */ | ||
var login = exports.login = (0, _curry2.default)(function (peer, username, password) { | ||
return new Promise(function (ok, fail) { | ||
if (peer && peer.gun && peer.gun.user) { | ||
var _user2 = peer.user(); | ||
_user2.auth(username, password, function (ack) { | ||
return ack.err ? fail(ack.err) : ok(peer.user().is); | ||
}); | ||
} else { | ||
fail("SEA is not loaded"); | ||
} | ||
}).then(function (result) { | ||
peer._onLogin && peer._onLogin(result); // eslint-disable-line | ||
return result; | ||
}); | ||
}); | ||
|
||
var user = exports.user = function user(peer) { | ||
return function () { | ||
return peer.gun.user(); | ||
}; | ||
}; | ||
|
||
var isLoggedIn = exports.isLoggedIn = function isLoggedIn(peer) { | ||
return function () { | ||
return peer.gun && peer.gun.user && peer.user().is; | ||
}; | ||
}; | ||
|
||
var onLogin = exports.onLogin = function onLogin(peer) { | ||
return function (fn) { | ||
return peer._onLogin = fn; | ||
}; | ||
}; // eslint-disable-line |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
"use strict"; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.and = exports.allowFields = exports.valFromSoul = exports.soulMatchesKey = exports.isSoul = exports.valIs = exports.keyIs = exports.TOPIC_NAME_MAX = exports.SUBMISSION_BODY_MAX = exports.SUBMISSION_TITLE_MAX = exports.COMMENT_BODY_MAX = exports.DEFAULT_POW_COMPLEXITY = exports.PREFIX = undefined; | ||
|
||
var _prop = require("ramda/src/prop"); | ||
|
||
var _prop2 = _interopRequireDefault(_prop); | ||
|
||
var _identity = require("ramda/src/identity"); | ||
|
||
var _identity2 = _interopRequireDefault(_identity); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
var PREFIX = exports.PREFIX = "nab"; | ||
var DEFAULT_POW_COMPLEXITY = exports.DEFAULT_POW_COMPLEXITY = 22; | ||
var COMMENT_BODY_MAX = exports.COMMENT_BODY_MAX = 10000; | ||
var SUBMISSION_TITLE_MAX = exports.SUBMISSION_TITLE_MAX = 300; | ||
var SUBMISSION_BODY_MAX = exports.SUBMISSION_BODY_MAX = 40000; | ||
var TOPIC_NAME_MAX = exports.TOPIC_NAME_MAX = 42; | ||
|
||
var keyIs = exports.keyIs = function keyIs(val) { | ||
return function (key) { | ||
return key === val; | ||
}; | ||
}; | ||
var valIs = exports.valIs = function valIs(checkVal) { | ||
return function (_k, val) { | ||
return checkVal === val; | ||
}; | ||
}; | ||
var isSoul = exports.isSoul = function isSoul(soul) { | ||
return function (key, val, parent, parentKey, msg, peer) { | ||
var isMatch = peer.souls[soul].isMatch((0, _prop2.default)("#", val) || key); | ||
if (isMatch) { | ||
var schemaCheck = peer.schema[soul](key, val, parent, parentKey, msg, peer); | ||
return isMatch && schemaCheck; | ||
} | ||
}; | ||
}; | ||
var soulMatchesKey = exports.soulMatchesKey = function soulMatchesKey(key, val) { | ||
return (0, _prop2.default)("#", val) === key; | ||
}; | ||
var valFromSoul = exports.valFromSoul = function valFromSoul(soul, routeKey) { | ||
return function (key, val, parent, pKey, _msg, peer) { | ||
return val === peer.souls[soul].isMatch((0, _prop2.default)("#", parent) || pKey)[routeKey]; | ||
}; | ||
}; | ||
|
||
var allowFields = exports.allowFields = function allowFields() { | ||
for (var _len = arguments.length, validators = Array(_len), _key = 0; _key < _len; _key++) { | ||
validators[_key] = arguments[_key]; | ||
} | ||
|
||
return function (pKey, val, _parent, _pKey, msg, peer) { | ||
return Promise.all(Object.keys(val || {}).map(function (key) { | ||
return Promise.all([keyIs("_"), keyIs("#")].concat(validators).map(function (fn) { | ||
return Promise.resolve(fn(key, val[key], val, pKey, msg, peer)); | ||
})).then(function (results) { | ||
if (!results.find(_identity2.default)) { | ||
if (key.indexOf("~") === -1) { | ||
// console.warn("sanitizing message", pKey, key); // eslint-disable-line | ||
delete val[key]; // eslint-disable-line | ||
} else { | ||
// console.warn("sea", pKey, key, msg); // eslint-disable-line | ||
} | ||
} | ||
}); | ||
})).then(function () { | ||
return val; | ||
}); | ||
}; | ||
}; | ||
|
||
var and = exports.and = function and() { | ||
for (var _len2 = arguments.length, fns = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
fns[_key2] = arguments[_key2]; | ||
} | ||
|
||
return function () { | ||
for (var _len3 = arguments.length, args = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { | ||
args[_key3] = arguments[_key3]; | ||
} | ||
|
||
var result = void 0; | ||
return !fns.find(function (fn, idx) { | ||
return idx === 0 // eslint-disable-line | ||
? !(result = fn.apply(undefined, args)) : !fn.apply(undefined, args); | ||
}) ? result : false; | ||
}; | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.