Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lejeunerenard/ouroboros
This module provides a way to define derived indexes on autobase hyperbees. This is done by creating an api similar to SimpleAutobee to support hyperbee operations w/ autobase, but also providing simple ways to watch key ranges and derive values base on changes to those ranges as well.
https://github.com/lejeunerenard/ouroboros
Last synced: about 1 month ago
JSON representation
This module provides a way to define derived indexes on autobase hyperbees. This is done by creating an api similar to SimpleAutobee to support hyperbee operations w/ autobase, but also providing simple ways to watch key ranges and derive values base on changes to those ranges as well.
- Host: GitHub
- URL: https://github.com/lejeunerenard/ouroboros
- Owner: lejeunerenard
- Created: 2024-02-18T21:49:36.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-04-11T01:41:50.000Z (9 months ago)
- Last Synced: 2024-04-11T03:58:06.664Z (9 months ago)
- Language: JavaScript
- Size: 152 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-pears - ouroboros - define derived indexes on autobase hyperbees (**Awesome Pears 🍐** / Building Blocks)
- awesome-pears - ouroboros - define derived indexes on autobase hyperbees (**Awesome Pears 🍐** / Building Blocks)
README
# Ouroboros
Define derived indexes on autobase hyperbees.
This is done by creating an api similar to SimpleAutobee to support hyperbee
operations w/ autobase, but also providing simple ways to watch key ranges and
derive values base on changes to those ranges as well.The ability for indexes to update based on themselves or other indexes is
likened to eating its own tail, hence Ouroboros. Be wary of infinite loops.## Usage
```js
import Autobase from 'autobase'
import Corestore from 'corestore'
import b4a from 'b4a'
import { wrap, apply, createIndex } from '@lejeunerenard/ouroboros'const store = new Corestore('./db')
const bootstrap = null
const open = (viewStore) => {
const core = viewStore.get('ouroboros')
return new Hyperbee(core, {
keyEncoding: 'utf-8',
valueEncoding: 'json',
extension: false
})
}
const base = wrap(new Autobase(store, bootstrap, {
open,
apply,
valueEncoding: 'json'
}))const range = { gte: 'entry!', lt: 'entry"' }
const [sub] = createIndex('2x', base, range, async (node, sub) =>
sub.put(node.key, 2 * node.value))const key = 'entry!foo'
await base.put(key, 2)await sub.update()
const node = await sub.get(key)
console.log(node.value) // 4
```