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

@synonymdev/slashtags-core-data

v1.0.0-alpha.11

Published

Slashtags Core Data is abstraction library that encapsulates logic related to managing data on Slashtags.

Downloads

30

Readme

slashtags-core-data

Slashtags Core Data is abstraction library that encapsulates logic related to managing data on Slashtags.

Install

npm install @synonymdev/slashtags-core-data

Usage

Initialize

const SlashtagsCoreData = require('@synonymdev/slashtags-core-data')
const coreData = new SlashtagsCoreData()

// Wait for instance to be ready 
await coreData.ready
const data = Buffer.from('bar')

await coreData.create('/public/foo', data)
const url = coreData.createURL('/public/foo')
// slash:<key>/public/foo

You can now share the URL generated from above example and read it.

const SlashtagsCoreData = require('@synonymdev/slashtags-core-data')

const reader = new SlashtagsCoreData({ key }) // Key from the writer

const resolved = await reader.readRemote(url) // url shared from the writer
// <Buffer 62 61 72>

API

const coreData = new SlashtagsCoreData(opts)

Create a new Slashtags Core Data instance.

opts is an object that includes:

  • keyPair Optional keyPair {secretKey: Uint8Array, publicKey: Uint8Array} to generate local drives. keys have to be 32 bytes.
  • seeders Optional list of seeder's public keys, where local drives will by synced with for backup and availability.
  • storage Optinal storage path or RandomAccessStorage instance (defaults to RandomAccessMemory).
  • bootstrap Optional Hyperswarm bootstrapping nodes, mostly for testing in a testnet.
  • seedersTopic Optional topic for discovery of other seeders providing remote drives that aren't announced on their own discoveryKeys, defaults to 3b9f8ccd062ca9fc0b7dd407b4cd287ca6e2d8b32f046d7958fa7bea4d78fd75.

await coreData.createURL(path)

Create a Slashtags URL for the data stored at that path.

await coreData.ready()

Await for the instance to be ready to be used.

await coreData.close()

Gracefully close connection and instance.

await coreData.create(path, data, opts)

Same as await coreData.update(path, data, [opts])

opts is an object that includes:

  • skipSeederSync Default to false, if set to true function will resolve without waiting for at least one seeder to reach full sync.

await coreData.update(path, data, [opts])

Updates a file. key should be a string, and data param should be Uint8Array.

If path starts with /public/ it will be unencrypted, otherwise it will a private encrypted drive.

opts is an object that includes:

  • skipSeederSync Default to false, if set to true function will resolve without waiting for at least one seeder to reach full sync.

await coreData.delete(path, [opts])

Deletes the value from drive.

opts is an object that includes:

  • skipSeederSync Default to false, if set to true function will resolve without waiting for at least one seeder to reach full sync.

await coreData.readRemote(url, opts)

opts include:

  • timeout how long to wait to find the data before quitting. Default 10 seconds

Read the data from either a local writable drive or a remote drive shared with you.

const unsubscribe = coreData.subscribe(url, onupdate)

Watch updates to a local or a remote file, and call onupdate(value) function with the current value.

Call unsubscribe() to remove all related listeners and close resources created in subscribe.

Example Scripts

There is a bundled example showing how to read and write a JSON file in Slashtags.

How to use

First start by running Slashtags endpoint that will listen on a key and serve JSON data.

node ./JSONFile.js

Copy the slash:// outputed by the script and open a new terminal.

node ./JSONFile.js --url <slash:// url>

The script should output the JSON written by the first script.