hldb / welo

peer-to-peer, collaborative states using Merkle-CRDTs
Other
32 stars 2 forks source link

refactor!: modularization #71

Closed saul-jb closed 1 year ago

saul-jb commented 1 year ago

This PR is a work in progress example of refactoring the registrar into a more modular design.

I envision the end API to look something like this, obviously taking inspiration for how Libp2p/Helia are structured:

import { createWelo } from 'welo'
import { liveReplicator } from 'welo/replicator/live'
import { basalEntry, createBasalEntryConfig } from 'welo/entry/basal'
import { basalIdentity, createBasalIdentityConfig } from 'welo/identity/basal'
import { staticAccess, createStaticAccessConfig } from 'welo/access/static'
import { keyvalue, createKeyvalueConfig } from 'welo/store/keyvalue'

const welo = await createWelo({
  helia,
  datastore: LevelDatastore,
  replicators: [ liveReplicator() ],
  identities: [ basalIdentity() ],
  entries: [ basalEntry() ],
  access: [ staticAccess() ]
})

const manifest = await welo.determine({
  name: "my-database",
  access: createStaticAccessConfig({ write: ['*'] }),
  entry: createBasalEntryConfig(),
  store: createKeyvalueConfig(),
  identity: createBasalIdentityConfig()
})

const db = await welo.open(manifest)
const store = await keyvalue(db)

I would like to simplify (shorten) the code needed to create a manifest but I'm not sure how yet.

saul-jb commented 1 year ago

Register is now completely gone along with the multi-replicator. More changes to come.

saul-jb commented 1 year ago

Unfortunately this has become a 'rewrite the entire codebase' PR, so apologies for that, it should have probably been split into a few PRs.

Main changes:

Marking this as ready but will need reviewing to ensure that functionality remains the same.

saul-jb commented 1 year ago

wondering if we could use the helia data/block -stores (by default) if they are name spaced

I suspect this is a bad idea since Helia would be expecting exclusive access to the store, instead I used the in-memory store as the default (like Helia does) and if the user wants to use the same store for both they can pass unique namespaces to both Welo and Helia.