├── .github └── workflows │ ├── npm-publish-next.yml │ └── npm-publish.yml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── package-lock.json ├── package.json └── src ├── FeedIndex.js └── FeedStore.js /.github/workflows/npm-publish-next.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Node.js Package (next tag) 3 | 4 | on: 5 | push: 6 | branches: 7 | - main 8 | 9 | jobs: 10 | publish-npm: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v3 14 | - uses: actions/setup-node@v3 15 | with: 16 | node-version: 'lts/*' 17 | registry-url: https://registry.npmjs.org/ 18 | - run: npm ci 19 | - run: | 20 | npm version prerelease --no-git-tag-version \ 21 | --preid=`git rev-parse --short HEAD` 22 | npm publish --tag next 23 | env: 24 | NODE_AUTH_TOKEN: ${{secrets.npm_token}} 25 | -------------------------------------------------------------------------------- /.github/workflows/npm-publish.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Node.js Package 3 | 4 | on: 5 | push: 6 | tags: 7 | - 'v*' 8 | 9 | jobs: 10 | publish-npm: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v2 14 | - uses: actions/setup-node@v2 15 | with: 16 | node-version: 'lts/*' 17 | registry-url: https://registry.npmjs.org/ 18 | - run: npm ci 19 | - run: npm publish 20 | env: 21 | NODE_AUTH_TOKEN: ${{secrets.npm_token}} 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *sublime* 2 | node_modules/ 3 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, gender identity and expression, level of experience, 9 | nationality, personal appearance, race, religion, or sexual identity and 10 | orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at [community@orbitdb.org](mailto:community@orbitdb.org), which goes to all members of the @OrbitDB community team, or to [richardlitt@orbitdb.org](mailto:richardlitt@orbitdb.org), which goes only to [@RichardLitt](https://github.com/RichardLitt) or to [haadcode@orbitdb.org](mailto:haadcode@orbitdb.org), which goes only to [@haadcode](https://github.com/haadcode). All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | . 2 | # Contribute 3 | 4 | Please contribute! Here are some things that would be great: 5 | 6 | - [Open an issue!](https://github.com/orbitdb/orbit-db-feedstore/issues/new) 7 | - Open a pull request! 8 | - Say hi! :wave: 9 | 10 | Please note that we have a [Code of Conduct](CODE_OF_CONDUCT.md), and that all activity in the [@OrbitDB](https://github.com/orbitdb) organization falls under it. Read it before you contribute, as being part of this community means that you agree to abide by it. Thanks. 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016-2018 Protocol Labs Inc. 4 | Copyright (c) 2018 Haja Networks Oy 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # orbit-db-feedstore 2 | 3 | [![npm version](https://badge.fury.io/js/orbit-db-feedstore.svg)](https://badge.fury.io/js/orbit-db-feedstore) 4 | [![Gitter](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/orbitdb/Lobby) [![Matrix](https://img.shields.io/badge/matrix-%23orbitdb%3Apermaweb.io-blue.svg)](https://riot.permaweb.io/#/room/#orbitdb:permaweb.io) [![Discord](https://img.shields.io/discord/475789330380488707?color=blueviolet&label=discord)](https://discord.gg/cscuf5T) 5 | 6 | > Log database for orbit-db 7 | 8 | A log database with traversable history. Entries can be added and removed. Useful for *"shopping cart"* type of use cases, or for example as a feed of blog posts or *"tweets"*. 9 | 10 | Used in [orbit-db](https://github.com/haadcode/orbit-db). 11 | 12 | ## Table of Contents 13 | 14 | - [Install](#install) 15 | - [Usage](#usage) 16 | - [API](#api) 17 | - [Contributing](#contributing) 18 | - [License](#license) 19 | 20 | ## Install 21 | 22 | This project uses [npm](https://npmjs.com) and [node](https://nodejs.org) 23 | 24 | ```sh 25 | npm install orbit-db ipfs 26 | ``` 27 | 28 | ## Usage 29 | 30 | First, create an instance of OrbitDB: 31 | 32 | ```javascript 33 | import * as IPFS from 'ipfs' 34 | import OrbitDB from 'orbit-db' 35 | 36 | const ipfs = new IPFS() 37 | const orbitdb = await OrbitDB.createInstance(ipfs) 38 | ``` 39 | 40 | Get a feed database and add an entry to it: 41 | 42 | ```javascript 43 | const feed = await orbitdb.feed('haad.posts') 44 | feed.add({ title: 'Hello', content: 'World' }) 45 | .then(() => { 46 | const posts = feed.iterator().collect() 47 | posts.forEach((post) => { 48 | let data = post.payload.value 49 | console.log(data.title + '\n', data.content) 50 | // Hello 51 | // World 52 | }) 53 | }) 54 | ``` 55 | 56 | Later, when the database contains data, load the history and query when ready: 57 | 58 | ```javascript 59 | const feed = await orbitdb.feed('haad.posts') 60 | feed.events.on('ready', () => { 61 | const posts = feed.iterator().collect() 62 | posts.forEach((post) => console.log(post.title + '\n', post.content)) 63 | // Hello 64 | // World 65 | }) 66 | ``` 67 | 68 | ## API 69 | 70 | See [orbit-db's API Documenations](https://github.com/orbitdb/orbit-db/blob/master/API.md#feedname) for full details. 71 | 72 | ## Contributing 73 | 74 | If you think this could be better, please [open an issue](https://github.com/orbitdb/orbit-db-feedstore/issues/new)! 75 | 76 | Please note that all interactions in [@orbitdb](https://github.com/orbitdb) fall under our [Code of Conduct](CODE_OF_CONDUCT.md). 77 | 78 | Note: Tests for this repo are in the [`orbit-db`](https://github.com/orbitdb/orbit-db) repository. 79 | 80 | ## License 81 | 82 | [MIT](LICENSE) © 2016-2020 Protocol Labs Inc., Haja Networks Oy 83 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "orbit-db-feedstore", 3 | "version": "2.0.0", 4 | "description": "Feed store for orbit-db", 5 | "type": "module", 6 | "main": "src/FeedStore.js", 7 | "homepage": "https://github.com/orbitdb/orbit-db-feedstore", 8 | "bugs": "https://github.com/orbitdb/orbit-db-feedstore/issues", 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/orbitdb/orbit-db-feedstore" 12 | }, 13 | "scripts": { 14 | "lint": "standard", 15 | "lint:fix": "standard --fix" 16 | }, 17 | "keywords": [ 18 | "orbit-db", 19 | "orbitdb", 20 | "database", 21 | "log-database" 22 | ], 23 | "author": "Haad", 24 | "contributors": [ 25 | "haadcode", 26 | "greenkeeperio-bot", 27 | "shamb0t", 28 | "RichardLitt", 29 | "MartianH", 30 | "adam-palazzo" 31 | ], 32 | "license": "MIT", 33 | "dependencies": { 34 | "orbit-db-eventstore": "*" 35 | }, 36 | "localMaintainers": [ 37 | "haad ", 38 | "shamb0t ", 39 | "hajamark " 40 | ], 41 | "devDependencies": { 42 | "standard": "^17.0.0" 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/FeedIndex.js: -------------------------------------------------------------------------------- 1 | export default class FeedIndex { 2 | constructor () { 3 | this._index = {} 4 | } 5 | 6 | get () { 7 | return Object.keys(this._index).map((f) => this._index[f]) 8 | } 9 | 10 | updateIndex (oplog) { 11 | this._index = {} 12 | oplog.values.reduce((handled, item) => { 13 | if (!handled.includes(item.hash)) { 14 | handled.push(item.hash) 15 | if (item.payload.op === 'ADD') { 16 | this._index[item.hash] = item 17 | } else if (item.payload.op === 'DEL') { 18 | delete this._index[item.payload.value] 19 | } 20 | } 21 | return handled 22 | }, []) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/FeedStore.js: -------------------------------------------------------------------------------- 1 | import EventStore from 'orbit-db-eventstore' 2 | import FeedIndex from './FeedIndex.js' 3 | 4 | export default class FeedStore extends EventStore { 5 | constructor (ipfs, id, dbname, options) { 6 | if (!options) options = {} 7 | if (!options.Index) Object.assign(options, { Index: FeedIndex }) 8 | super(ipfs, id, dbname, options) 9 | this._type = 'feed' 10 | } 11 | 12 | remove (hash, options = {}) { 13 | return this.del(hash, options) 14 | } 15 | 16 | del (hash, options = {}) { 17 | const operation = { 18 | op: 'DEL', 19 | key: null, 20 | value: hash 21 | } 22 | return this._addOperation(operation, options) 23 | } 24 | } 25 | --------------------------------------------------------------------------------