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

@ipld/stack

v1.3.0

Published

This repository is an exporatory space to work on the next stack of modules for authoring IPLD data structures.

Downloads

13

Readme

EXPERIMENTAL: New stack for authoring IPLD data structures

This repository is an exporatory space to work on the next stack of modules for authoring IPLD data structures.

Eventually this repository will be deleted as it contains code for many modules. This code will eventually migrate to the right repositories but it's much easier to develop and test the stack as a whole in one repository during this early stage of development.

Goals

After having spent time authoring IPLD data structures we have several improvements and changes we'd like to see implemented.

  • Single end point for authoring a block (rather than finding each format)
  • Lazy encoding, decoding, and cid (hash) creation.
  • Caching everywhere possible: encoding, hashing, etc.
  • Simplified authoring of new formats.
  • Less verbose API names.

Block API

The Block API is the single endpoint for authoring IPLD data structures. Unless you're implementing a new codec you can get everything you need from the Block API: encoding, decoding, cid creation w/ hashing.

Block.encoder(object, codec, algorithm = 'sha2-256')

Create a Block instance from either a native object.

The cid as well as encoding will not happen until requested and then will be cached when appropriate.

let block = Block.encoder({hello: 'world'}, 'dag-cbor')

Returns a Block instance.

Block.decoder(binary, codec, algorithm = 'sha2-256')

Create a Block instance from an existing binary encoded block

The cid as well as decoding will not happen until requested and then will be cached when appropriate.

let block = Block.decoder(someBuffer, 'dag-cbor')

Returns a Block instance.

Block.create(binary, cid)

Create a new block from the raw binary data and cid.

cid can be an instance of CID or a base encoded string of a cid.

Returns a Block instance.

Block(opts)

Once a block instance is created the information represented in the block is considered immutable.

block.decode()

Promise that resolves to a native JavaScript object decoded from the block data.

A new object is returned on every call. The decoding is not cached because it is likely to be mutated by the consumer.

block.cid()

Promise that resolves to a cid instance. Cached after creation.

block.encode()

Promise that resolves to a Buffer instance encoded from the source input.

block.reader()

Returns an instance of Reader() from the codec implementation.

block.validate()

Returns true/false if the CID's multihash matches the given block.

If a CID hasn't been created yet it will return true since we know the hash will match in our eventually created CID.

Hot path methods

We expose a few extra APIs you can use if you find IPLD in the hot paths of your own code.

Since some codecs require async work and some do not, it's a good idea to try and factor our unnecesary async operations when you can if you can in hot paths.

block.encodeMaybeSync

Just like block.encode but returns either a promise or the encoded value synchronously.

block.decodeMaybeSync

Just like block.decode but returns either a proimse or the decoded value synchronously.

Codec Interface

This is the primary interface for implementing new codecs.

The interface is quite simple:

{
  encode: Function,
  decode: Function,
  codec: String,
  reader: Function
}

encode & decode

These are the primary methods you need to implement in order to implement a new codec.

While you can implement the entire Reader interface yourself, you can actually leverage our codec-interface.create utility to get a full implementation with these methods alone.

  • encode takes a native JavaScript object and returns a binary encoding.
  • decode takes a binary encoding and returns a nativfe JavaScript object.

Methods can be either synchronous or asynchronous (returns a promise).

reader(block)

The reader function accepts a Block instance and returns a full Reader interface.

This method can be either synchronous or asynchronous (returns a promise).

codec-interface.create(encode, decode, codecName)

Returns a full Codec Interface based on your encode and decode implementations.

Reader()

Reader.get(path)

Reader.links()

Reader.tree()