1.0.0-alpha.0 • Published 11 months ago

@synonymdev/slashtags-contacts v1.0.0-alpha.0

Weekly downloads
-
License
-
Repository
-
Last release
11 months ago

slashtags-contacts

Slashtags contacts management.

Install

npm install @synonymdev/slashtags-contacts

Usage

Initialize

const coreData = new SlashtagsCoreData()

const contacts = new SlashtagsContacts(coreData)

await contacts.ready() // await loading contacts from disk

await contacts.set('slash:kencdz6km9xde46iph165d6isidssy9uate7b6srfaur8stm5br7', { name: "Foo" }) // set new contact

const contact = contacts.get('slash:kencdz6km9xde46iph165d6isidssy9uate7b6srfaur8stm5br7')
// { name: "Foo" }


for (let [id, contact] contacts.list() {
  // id: 'kencdz6km9xde46iph165d6isidssy9uate7b6srfaur8stm5br7'
  // ccontact: { name: "Foo" }
}

API

const contacts = new SlashtagsContacts(coreData)

Create a new contacts instance from a CoreData instance

await contacts.ready()

Await opening the contacts list from storage.

await contacts.set(url, contact)

Await setting the value of contact and storing it as persistent encrypted data. contact has to be in the shape:

{
  name: string, // Local (pet)name of the contact.
}

const contact = contacts.get(url)

Return contact value from contact's Slashtags url.

for (let [id, contact] contacts.list() {}

Return an iterator of entries in the internal Map. id is z-base32 endoced key of the contact. Internal map will be populated after contacts.ready()

contact.close()

Close underlying coreData instance and all subscriptions.