Home

Awesome

⛔️ DEPRECATED: This module has been superseded by multiformats <!-- omit in toc -->

<div align="center"> <a href="https://ipld.io"><img src="https://ipld.io/img/ipld-logo.png" alt="IPLD hex logo" /></a> </div>

The JavaScript implementation of the IPLD <!-- omit in toc -->

Travis CI Coverage Status Dependency Status js-standard-style Greenkeeper badge

The JavaScript implementation of the IPLD, InterPlanetary Linked-Data

Project Status <!-- omit in toc -->

This project is considered stable, but alpha quality implementation. The IPLD strategy for persistence and integration with IPFS has evolved since this package was created. This package will be deprecated once the new strategy is fully implemented. You can read more about the new strategy in Issue #260

IPLD Team Management

Tech Lead <!-- omit in toc -->

Volker Mische

Lead Maintainer <!-- omit in toc -->

Volker Mische

Table of Contents <!-- omit in toc -->

Install

> npm install --save ipld

Usage

const Ipld = require('ipld')
const IpfsRepo = require('ipfs-repo')
const IpfsBlockService = require('ipfs-block-service')

const initIpld = async (ipfsRepoPath) => {
  const repo = new IpfsRepo(ipfsRepoPath)
  await repo.init({})
  await repo.open()
  const blockService = new IpfsBlockService(repo)
  return new Ipld({blockService: blockService})
}

initIpld('/tmp/ipfsrepo2')
  .then((ipld) => {
    // Do something with the `ipld`, e.g. `ipld.get(…)`
  })
  .catch((error) => {
    console.error(error)
  })

API

The IPLD API works strictly with CIDs and deserialized IPLD Nodes. Interacting with the binary data happens on lower levels. To access the binary data directly, use the Block API.

All methods that return an async iterator return one that got extended with convenience methods:

Example:

const result = ipld.getMany([cid1, cid2])
const node1 = await result.first()

IPLD constructor

Creates and returns an instance of IPLD.

const ipld = new Ipld(options)

The options is an object with any of these properties:

options.blockService
TypeDefault
ipfs.BlockService instanceRequired (no default)

Example:

const blockService = new IpfsBlockService(repo)
const ipld = new Ipld({blockService: blockService})
options.formats
TypeDefault
Array of IPLD Format implementations[require('ipld-dag-cbor'), require('ipld-dag-pb'), require('ipld-raw')]

By default only the dag-cbor), dag-pb) and raw) IPLD Formats are supported. Other formats need to be added manually. Here is an example if you want to have support for ipld-git only:

const ipldGit = require('ipld-git')

const ipld = new Ipld({
  formats: [ipldGit],
  …
})
options.loadFormat(codec)
TypeDefault
async Functionnull

Function to dynamically load an IPLD Format. It is passed a codec, the multicodec code of the IPLD format to load and returns an IPLD Format implementation. For example:

const multicodec = require('multicodec')
const ipld = new Ipld({
  async loadFormat (codec) {
    if (codec === multicodec.GIT_RAW) {
      return require('ipld-git')
    } else {
      throw new Error('unable to load format ' + multicodec.print[codec])
    }
  }
})

.put(node, format, options)

Stores the given IPLD Node of a recognized IPLD Format.

Returns a Promise with the CID of the serialized IPLD Node.

.putMany(nodes, format, options)

Stores the given IPLD Nodes of a recognized IPLD Format.

Returns an async iterator with the CIDs of the serialized IPLD Nodes. The iterator will throw an exception on the first error that occurs.

.resolve(cid, path, options)

Retrieves IPLD Nodes along the path that is rooted at cid.

Returns an async iterator of all the IPLD Nodes that were traversed during the path resolving. Every element is an object with these fields:

.get(cid, options)

Retrieve an IPLD Node.

Returns a Promise with the IPLD Node that correspond to the given cid.

Throws an error if the IPLD Node can’t be retrieved.

.getMany(cids, options)

Retrieve several IPLD Nodes at once.

Returns an async iterator with the IPLD Nodes that correspond to the given cids.

Throws an error if a IPLD Node can’t be retrieved.

.remove(cid, options)

Remove an IPLD Node by the given cid

Throws an error if the IPLD Node can’t be removed.

.removeMany(cids, options)

Remove IPLD Nodes by the given cids

Throws an error if any of the Blocks can’t be removed. This operation is not atomic, some Blocks might have already been removed.

.tree(cid, [path], [options])

Returns all the paths that can be resolved into.

Returns an async iterator of all the paths (as Strings) you could resolve into.

.addFormat(ipldFormatImplementation)

Add support for an IPLD Format

Returns the IPLD instance. This way you can chain addFormat() calls.

.getFormat(codec)

Return the implementation for an IPLD Format

If the implementation is not present in the current list of resolvers, the loadFormat function passed as an option to the constructor of this module will be invoked and it's output added to the list of available resolvers.

.removeFormat(codec)

Remove support for an IPLD Format

Returns the IPLD instance. This way you can chain removeFormat() calls.

Properties

defaultOptions

Default options for IPLD.

Packages

Listing of dependencies from the IPLD ecosystem.

This table is generated using the module package-table with package-table --data=package-list.json.

PackageVersionDepsCICoverageLead Maintainer
IPLD Formats
ipld-bitcoinnpmDepsTravis CIcodecovVolker Mische
ipld-dag-cbornpmDepsTravis CIcodecovVolker Mische
ipld-dag-pbnpmDepsTravis CIcodecovVolker Mische
ipld-ethereumnpmDepsTravis CIcodecovVolker Mische
ipld-gitnpmDepsTravis CIcodecovVolker Mische
ipld-rawnpmDepsTravis CIcodecovVolker Mische
ipld-zcashnpmDepsTravis CIcodecovVolker Mische
Data Types (non IPLD specific)
multihashesnpmDepsTravis CIcodecovDavid Dias
ipfs-blocknpmDepsTravis CIcodecovVolker Mische
Storage
ipfs-reponpmDepsTravis CIcodecovJacob Heun
interface-datastorenpmDepsTravis CIcodecovPedro Teixeira
ipfs-block-servicenpmDepsTravis CIcodecovVolker Mische

Contribute

Feel free to join in. All welcome. Open an issue!

This repository falls under the IPFS Code of Conduct.

License

MIT