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

w3-wnfs

v0.1.1

Published

Provides the necessary components to use WNFS with Web3Storage.

Downloads

6

Readme

W3-WNFS

npm (scoped)

Provides the necessary components to use WNFS with Web3Storage.

Features

  • Blockstore that fetches from the w3s.link IPFS gateway.
  • Tracking of changed blocks, so you know what to upload to W3S.
  • Blockstore uses the tracker + a flush function to store the tracked blocks on W3S.
  • Data root (root CID) management using uploads.

How it works

The tracker tracks all the new blocks that Web3Storage doesn't have yet. These blocks are then stored on W3S when you call blockstore.flush(). The root CID that contains all those blocks is called the data root, which is registered as an upload when Pointer.save() is called.

Each time a new upload is registered, the old ones are removed; because there's currently no way to identify a particular upload.

Ideally this is used within a space that's used only for a single WNFS.

Installation

npm install w3-wnfs

Usage

Setting up all the pieces: In this example we're keeping all the blocks around locally too in an indexedDB, but any "fallback" blockstore can be used.

import { Blockstore, Tracker } from 'w3-wnfs/blockstore'

import * as W3UP from '@web3-storage/w3up-client'
import * as IDB from 'idb-keyval'
import { IDBBlockstore } from 'blockstore-idb'

// 🌍 Web3Storage client.
const _client = await W3UP.create()

// 🪃 The tracker that keeps track of which blocks to upload
const tracker = await Tracker.create({
  // Example, store in indexedDB
  getter: async () => await IDB.get('block-tracker'),
  setter: async (table: SimplifiedTable) => {
    await IDB.set('block-tracker', table)
  },
})

// 📦 The blockstore that keeps around the individual data pieces of our WNFS
const cache = new IDBBlockstore(idbName)
await cache.open()

const _blockstore = await Blockstore.create({
  cache,
  tracker,
})

Then connect it with WNFS. Here we use @wnfs-wg/nest as an example, but you could also use the wnfs package.

import { Pointer } from 'w3-wnfs'

const dataRoot = await Pointer.lookup({ client })

// Create or load file system
const fs =
  dataRoot === undefined
    ? await FileSystem.create({ blockstore })
    : await FileSystem.fromCID(dataRoot, { blockstore })

// Flush blocks and update pointer when publishing changes
fs.on('publish', async (event) => {
  await blockstore.flush()
  await Pointer.save({
    client,
    dataRoot: event.dataRoot,
  })
})

Working offline

You can save the data root locally too so you can work offline:

import * as W3_WNFS from 'w3-wnfs'
import { CID } from 'w3-wnfs'

async function storePointerLocally(dataRoot: CID): Promise<void> {
  await IDB.set('data-root', dataRoot.toString())
}

async function lookupPointer(): Promise<CID | undefined> {
  const remote = navigator.onLine
    ? await W3_WNFS.Pointer.lookup({ client })
    : undefined
  if (remote !== undefined) return remote
  const value = await IDB.get(this.LOCAL_NAME)
  if (typeof value === 'string') return CID.parse(value)
  return undefined
}

// 🚀 Building on the example from above
const _dataRoot = await lookupPointer()

// `@wnfs-wg/nest` integration:
//
// Save data root locally when changes are committed
// (note: publish has a small delay, commit does not)
fs.on('commit', async (event) => {
  await storePointerLocally(event.dataRoot)
})

Docs

Check https://icidasset.github.io/radical-edward

Contributing

Read contributing guidelines here.

Open in GitHub Codespaces

License

This project is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.