21.2.3 • Published 2 months ago

@saulx/selva-server v21.2.3

Weekly downloads
654
License
MIT
Repository
github
Last release
2 months ago

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

2 months ago

21.1.1

9 months ago

21.1.0

10 months ago

21.2.0

8 months ago

21.2.2

7 months ago

21.2.1

7 months ago

21.0.1

1 year ago

21.0.0

1 year ago

20.4.0

1 year ago

20.5.4

1 year ago

20.6.0

1 year ago

20.2.3

1 year ago

20.2.2

1 year ago

20.2.1

1 year ago

20.2.0

1 year ago

20.2.4

1 year ago

20.3.0

1 year ago

19.0.1

2 years ago

19.0.0

2 years ago

19.2.1

1 year ago

19.2.0

1 year ago

20.0.0

1 year ago

19.1.0

2 years ago

19.1.2

2 years ago

19.1.1

2 years ago

20.1.0

1 year ago

20.1.3

1 year ago

20.1.2

1 year ago

20.1.1

1 year ago

17.0.0

2 years ago

16.0.0

2 years ago

15.0.0

2 years ago

14.2.0

2 years ago

14.2.1

2 years ago

14.2.2

2 years ago

13.1.0

2 years ago

13.2.0

2 years ago

14.0.0

2 years ago

13.0.0

2 years ago

15.1.1

2 years ago

15.1.2

2 years ago

15.1.0

2 years ago

12.3.0

2 years ago

12.0.0

2 years ago

11.1.3

2 years ago

11.1.4

2 years ago

11.1.1

2 years ago

11.1.2

2 years ago

11.1.0

2 years ago

12.2.1

2 years ago

12.2.0

2 years ago

12.1.2

2 years ago

12.1.0

2 years ago

12.1.1

2 years ago

11.0.2

2 years ago

11.0.0

2 years ago

11.0.1

2 years ago

10.6.3

2 years ago

10.6.2

2 years ago

10.6.1

2 years ago

10.0.0

2 years ago

10.4.0

2 years ago

9.1.9

2 years ago

10.3.0

2 years ago

10.3.1

2 years ago

10.6.0

2 years ago

10.2.0

2 years ago

10.2.1

2 years ago

10.5.0

2 years ago

10.1.0

2 years ago

9.1.8

2 years ago

9.1.7

2 years ago

9.1.6

2 years ago

9.1.5

2 years ago

9.1.4

2 years ago

9.1.3

2 years ago

9.1.2

2 years ago

9.1.1

2 years ago

9.1.0

2 years ago

9.0.0

3 years ago

8.2.2

3 years ago

8.2.1

3 years ago

8.2.0

3 years ago

8.1.0

3 years ago

8.1.1

3 years ago

8.0.1

3 years ago

8.0.0

3 years ago

7.0.8

3 years ago

7.0.9

3 years ago

7.0.7

3 years ago

7.0.6

3 years ago

7.0.5

3 years ago

7.0.4

3 years ago

7.0.3

3 years ago

7.0.2

3 years ago

7.0.0

3 years ago

7.0.1

3 years ago

6.0.0

3 years ago

5.1.0

3 years ago

5.0.2

3 years ago

5.0.1

3 years ago

5.0.0

3 years ago

4.7.0

3 years ago

4.6.0

3 years ago

4.5.1

3 years ago

4.5.0

3 years ago

4.4.0

3 years ago

4.3.0

3 years ago

4.2.1

3 years ago

4.2.0

3 years ago

4.1.0

3 years ago

4.0.1

3 years ago

4.0.0

3 years ago

4.0.2

3 years ago

3.5.0

3 years ago

3.4.5

3 years ago

3.4.4

3 years ago

3.4.3

3 years ago

3.4.2

3 years ago

3.4.1

3 years ago

3.4.0

3 years ago

3.3.0

3 years ago

3.2.11

3 years ago

3.2.10

3 years ago

3.2.9

3 years ago

3.2.8

3 years ago

3.2.7

3 years ago

3.2.6

3 years ago

3.2.5

3 years ago

3.2.3

3 years ago

3.2.2

3 years ago

3.2.1

3 years ago

3.2.0

3 years ago

3.1.4

3 years ago

3.1.3

3 years ago

3.1.1

3 years ago

3.1.0

3 years ago

2.0.17

3 years ago

2.0.15

3 years ago

2.0.16

3 years ago

2.0.14

3 years ago

2.0.13

3 years ago

3.0.3

3 years ago

3.0.2

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago

2.0.12

4 years ago

2.0.11

4 years ago

2.0.7

4 years ago

2.0.6

4 years ago

2.0.9

4 years ago

2.0.8

4 years ago

2.0.10

4 years ago

2.0.5

4 years ago

2.0.3

4 years ago

2.0.4

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.14.5

4 years ago

1.14.1

4 years ago

1.14.0

4 years ago

1.14.4

4 years ago

1.14.3

4 years ago

1.13.0

4 years ago

1.12.1

4 years ago

1.12.0

4 years ago

1.10.1

4 years ago

1.10.0

4 years ago

1.9.5

4 years ago

1.9.6

4 years ago

1.9.4

4 years ago

1.9.3

4 years ago

1.9.2

4 years ago

1.9.1

4 years ago

1.9.0

4 years ago

1.8.0

4 years ago

1.5.4

4 years ago

1.5.3

4 years ago

1.5.2

4 years ago

1.5.1

4 years ago

1.5.0

4 years ago

1.4.6

4 years ago

1.4.5

4 years ago

1.4.4

4 years ago

1.4.3

4 years ago

1.4.2

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.20

4 years ago

1.3.19

4 years ago

1.3.18

4 years ago

1.3.15

4 years ago

1.3.16

4 years ago

1.3.13

4 years ago

1.3.11

4 years ago

1.3.12

4 years ago

1.3.10

4 years ago

1.3.9

4 years ago

1.3.8

4 years ago

1.3.7

4 years ago

1.3.6

4 years ago

1.3.5

4 years ago

1.3.4

4 years ago

1.3.3

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

0.2.51

4 years ago

0.2.50

4 years ago

1.2.52

4 years ago

0.2.48

4 years ago

0.2.47

4 years ago

0.2.46

4 years ago

0.2.44

4 years ago

0.2.43

4 years ago

0.2.41

4 years ago

0.2.40

4 years ago

0.2.39

4 years ago

0.2.38

4 years ago

0.2.37

4 years ago

0.2.35

4 years ago

0.2.34

4 years ago

0.2.33

4 years ago

0.2.32

4 years ago

0.2.30

4 years ago

0.2.29

4 years ago

0.2.28

4 years ago

0.2.27

4 years ago

0.2.26

4 years ago

0.2.25

4 years ago

0.2.23

4 years ago

0.2.22

4 years ago

0.2.21

4 years ago

0.2.20

4 years ago

0.2.19

4 years ago

0.2.15

4 years ago

0.2.14

4 years ago

0.2.17

4 years ago

0.2.1

4 years ago

0.2.2

4 years ago

0.2.0

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago