npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sporttotal/selva

v3.2.12

Published

🌴 Selva is a realtime undirected acyclic graph database.

Downloads

7

Readme

Selva

🌴 Selva is a realtime undirected acyclic graph database.

  • Real time
  • Versioning system for the data itself allowing branches of data to be merged and revised into the master data, allows content creators to try stuff before it goes live and allows them to collaborate on a version (in real time)
  • Persistence layer using GIT-LFS allowing backups every 5 mins and keeps versions of all data available
  • Custom query language and indexes optimized for the undirected acyclic graph data structure
  • Simple query language

Methods

selva.connect(options)

Takes an object with options

  • reconnects
  • batches commands
  • queues commands if disconnected
  • *optimized/cached results

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).

client.set()

Set an object on an id. Will deep merge objects by default.

Default behaviours

  • Acenstors can never be set, children and parents update ancestors, children and parents.
  • Date is allways added by default
  • Keyword 'now' in date, start, end will add date
  • Setting a batch with adding new stuff is tricky
    • Try to set - if batch - error 'does' not exist - wait 150ms (?) order the non working results. if it does not work return error
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 }

client.subscribe()

const result = await client.subscribe(
  {
    id: 'myId',
    version: 'mySpecialversion', // optional
  },
  (id, msg) => {
    console.log(`Fired for ${id} with message: ${msg}`)
  }
)

client.subscribe()

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}`)
  }
)

client.unsubscribe()

const result = await client.unsubscribe(
  {
    id: 'myId',
    version: 'mySpecialversion', // optional
  },
  myCallback // if omitted will remove all listeners
)

id

Generate an id

Max types 1764!

const id = await client.id({ type: 'flurpy', externalId: 'smurkysmurk' })
// flgurk

delete

await client.delete('ma12231')
await client.delete({ $id: 'ma12231' })
await client.delete({ $id: 'ma12231', $hierarchy: false })