Datastore setup

I have asked in GitHub issues at More detailed usage · Issue #59 · ipfs/js-datastore-level · GitHub but moved here.

My use case is to setup IPFS working like following. For both Node.js and browsers:

  • In development, I want IPFS to work in-memory.
  • In production, I want IPFS to work somehow persistent way, but on top of managed environment by JavaScript engines, such as IndexedDB.

I have considered using datastore-level with level-mem but had no luck as shown in the GitHub issue above.

I have also considered using datastore-fs with pseudo-filesystems such as memfs, but datastore-fs is not providing any option to set fs-compliant module as its backend.

What can I do for this? I’d better write a new datastore-compliant module?

And I’ve tested the answer by @achingbrain in the GitHub issue like this:

import { MemoryDatastore } from "interface-datastore"

export const IPFS = IPFSCore.create({
  repo: new Repo(`.ipfs`, {
    storageBackends: {
      root: MemoryDatastore,
      blocks: MemoryDatastore,
      keys: MemoryDatastore,
      datastore: MemoryDatastore
    }
  }),
  start: false,
  // silent: true,
  init: {
    algorithm: "Ed25519"
  }
})

but this emits another error like this:

    unexpected error when determining the last published IPNS record for 0,36,8,1,18,32,224,177,254,116,17,126,27,149,182,8,164,242,33,223,49,71,116,178,14,166,104,66,53,13,81,83,113,199,198,150,108,110 Error: unexpected error getting the ipns record 0,36,8,1,18,32,224,177,254,116,17,126,27,149,182,8,164,242,33,223,49,71,116,178,14,166,104,66,53,13,81,83,113,199,198,150,108,110 from datastore

      at IpnsPublisher._getPublished (../../../node_modules/ipfs-core/src/ipns/publisher.js:151:23)
      at IpnsPublisher._updateOrCreateRecord (../../../node_modules/ipfs-core/src/ipns/publisher.js:196:27)
      at IpnsPublisher.publishWithEOL (../../../node_modules/ipfs-core/src/ipns/publisher.js:31:31)
      at IPNS.publish (../../../node_modules/ipfs-core/src/ipns/index.js:32:7)
      at Object.create (../../../node_modules/ipfs-core/src/components/index.js:228:7)
      at IpnsPublisher._updateOrCreateRecord (../../../node_modules/ipfs-core/src/ipns/publisher.js:202:23)
      at IpnsPublisher.publishWithEOL (../../../node_modules/ipfs-core/src/ipns/publisher.js:31:20)
      at IPNS.publish (../../../node_modules/ipfs-core/src/ipns/index.js:32:7)
      at Object.create (../../../node_modules/ipfs-core/src/components/index.js:228:7)

I’m using:

    "interface-datastore": "^3.0.4",
    "ipfs-core": "^0.5.2",
    "ipfs-repo": "^8.0.0",

Another weird thing is, why is it still accessing “.ipfs/pins/LOCK” despite that I use lock-memory for the Repo?

import IPFSCore from "ipfs-core"
import Repo from "ipfs-repo"
import { MemoryDatastore } from "interface-datastore"
import LockMemory from "ipfs-repo/src/lock-memory"

export const IPFS = IPFSCore.create({
  repo: new Repo(`.ipfs`, {
    storageBackends: {
      root: MemoryDatastore,
      blocks: MemoryDatastore,
      keys: MemoryDatastore,
      datastore: MemoryDatastore
    },
    lock: LockMemory
  }),
  start: false,
  // silent: true,
  init: {
    algorithm: "Ed25519"
  }
})
    OpenError: IO error: .ipfs/pins/LOCK: No such file or directory

      at ../../../node_modules/levelup/lib/levelup.js:119:23
      at ../../../node_modules/abstract-leveldown/abstract-leveldown.js:38:14
      at ../../../node_modules/deferred-leveldown/deferred-leveldown.js:31:21
      at ../../../node_modules/encoding-down/node_modules/abstract-leveldown/abstract-leveldown.js:38:14
      at ../../../node_modules/abstract-leveldown/abstract-leveldown.js:38:14

In this case I’m not using LevelDB.