![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
@saulx/selva
Advanced tools
🌴 Selva is a realtime undirected acyclic graph database.
Takes an object with options
example
import { getService } from 'registry'
const client = selva.connect(() => getService('name-of-db'))
// client.redis.hget()
client.set('myId', { myShine: true }).then(result => console.log(result)) // logs OK
const client = selva.connect({
port: 8080,
host: 'whatever', // defaults to localhost
retryStrategy() {
// optional
return 5e3
}
})
or with a promise
const client = selva.connect(new Promise(resolve => {
resolve({
port: 8080,
host: 'whatever',
retryStrategy () {
return 5e3
}
})
})
or with a (async) function
const client = selva.connect(async () => {
await doSomething()
return {
port: 8080,
host: 'whatever',
retryStrategy() {
return 5e3
}
}
})
On every reconnect selva will call the given function. This allows you to change the configuration (eg. if a db has become unresponsive).
Set an object on an id. Will deep merge objects by default.
Default behaviours
await client.set({
$id: 'myId',
$merge: false, // defaults to true
$version: 'mySpecialversion', // optional
id: 'myNewId',
foo: true
})
await client.set({
$id: 'myId',
$merge: false, // defaults to true
$version: 'mySpecialversion', // optional
id: 'myNewId',
foo: true,
children: {
$add: 'smukytown',
$delete: 'myblarf'
}
})
await client.set({
$id: 'myId',
children: {
// maybe redis SET do it?
// ---- :(
$hierarchy: false, // defaults to true
$add: 'smukytown',
$delete: ['myblarf', 'xxx']
}
})
await client.set({
$id: 'myId',
children: {
// ---- :(
$hierarchy: false, // defaults to true
$value: ['root']
}
})
await client.set({
// gen id, add to root
type: 'tag',
title: 'flowers',
externalId: 'myflower.de'
}
})
await client.set({
// gen id, add to root
type: 'tag',
title: 'flowers',
externalId: {
$merge: false,
$value: 'myflower.de'
}
})
await client.set({
type: 'tag',
title: { de: 'blümen' }
})
await client.set({
$id: 'myId',
$merge: false, // defaults to true
$version: 'mySpecialversion', // optional
myThing: {
title: 'blurf',
nestedCount: {
$default: 100,
$inc: { $value: 1 }
},
access: {
$default: {
flurpiepants: 'my pants'
}
}
}
})
myId
myId#mySpecialversion
const result = await client.get(
{
$id: 'myId',
$version: 'mySpecialversion'
}
)
const versioned = redisClient.get('myId#mySpecialversion')
const original = redisClient.get('myId') || {}
const result = { ...original, ...versioned }
myId
myId#mySpecialversion
const obj = {
foo: {
bar: true
},
haha: true
}
'foo.bar': true
'foo.foo': true
'foo.baz': true
'foo.baz.blarf': true,
haha: true
hkeys: foo.*
{ foo: true }
const result = await client.subscribe(
{
id: 'myId',
version: 'mySpecialversion' // optional
},
(id, msg) => {
console.log(`Fired for ${id} with message: ${msg}`)
}
)
const result = await client.subscribe(
{
id: 'myId',
date: 123123123,
version: 'mySpecialversion' // optional
},
(id, msg) => {
console.log(`Fired for ${id} with message: ${msg}`)
}
)
or with an array for ids
const result = await client.subscribe(
{
id: ['myId', 'myOtherId'],
version: 'mySpecialversion' // optional
},
(id, msg) => {
console.log(`Fired for ${id} with message: ${msg}`)
}
)
const result = await client.unsubscribe(
{
id: 'myId',
version: 'mySpecialversion' // optional
},
myCallback // if omitted will remove all listeners
)
Generate an id
Max types 1764!
const id = await client.id({ type: 'flurpy', externalId: 'smurkysmurk' })
// flgurk
await client.delete('ma12231')
await client.delete({ $id: 'ma12231' })
await client.delete({ $id: 'ma12231', $hierarchy: false })
FAQs
🌴 Selva is a realtime undirected acyclic graph database.
The npm package @saulx/selva receives a total of 35 weekly downloads. As such, @saulx/selva popularity was classified as not popular.
We found that @saulx/selva demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.