Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Implement ipfs refs #2004

Merged
merged 28 commits into from
May 16, 2019
Merged

Implement ipfs refs #2004

merged 28 commits into from
May 16, 2019

Conversation

dirkmc
Copy link
Contributor

@dirkmc dirkmc commented Apr 22, 2019

Implement the ipfs refs command:

USAGE
  ipfs refs <ipfs-path>... - List links (references) from an object.

SYNOPSIS
  ipfs refs [--format=<format>] [--edges | -e] [--unique | -u] [--recursive | -r] [--max-depth=<max-depth>] [--] <ipfs-path>...
  • implement unique flag
  • implement http-api

Depends on ipfs-inactive/js-ipfs-http-client#978

@ghost ghost assigned dirkmc Apr 22, 2019
@ghost ghost added the status/in-progress In progress label Apr 22, 2019
src/cli/commands/refs.js Outdated Show resolved Hide resolved
@dirkmc dirkmc force-pushed the feat/refs branch 2 times, most recently from 24ccb51 to aaf2d3b Compare April 22, 2019 12:10
@dirkmc dirkmc marked this pull request as ready for review April 24, 2019 06:06
@dirkmc dirkmc requested a review from alanshaw April 24, 2019 06:07
@dirkmc
Copy link
Contributor Author

dirkmc commented Apr 24, 2019

After talking to @achingbrain I will take a look at making a change to js-ipfs-unixfs-exporter to include the parent CID so that a call to refs can be streamed (instead of collecting all the results, working out each link's parents and only then outputting a result)

@alanshaw
Copy link
Member

Is refs only for unixfs nodes or should it work with all IPLD nodes? I was originally thinking you’d be talking directly to IPLD for this...

@dirkmc
Copy link
Contributor Author

dirkmc commented Apr 25, 2019

hmm that's a good question. I'll take a look at exactly what refs does and whether it makes sense to use unixfs exporter

@dirkmc
Copy link
Contributor Author

dirkmc commented Apr 25, 2019

Looking at the code it seems like js-ipfs-unixfs-exporter does traverse any kind of IPLD object, but only in order to find unix format ipld objects. I will want to do something very similar, but more generic, ie not just for unix format objects.

@dirkmc
Copy link
Contributor Author

dirkmc commented Apr 28, 2019

It turns out it's actually simple to traverse the refs DAG in js-ipfs with pull-traverse instead of relying on js-ipfs-unix-exporter, which is specifically aimed at unix format files

Copy link
Member

@alanshaw alanshaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

const { print } = require('../utils')

module.exports = {
command: 'refs-local',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to use this as ipfs refs local i.e. without the hyphen

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alanshaw it seems like it will be tricky to make the parser work with both
ipfs refs <path>
ipfs refs local

I can probably hack it to make it work, but before I do that do you think it would make more sense to the user to give the commands different names instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets keep compat with go-ipfs - it's not too hacky to detect when path === 'local' and do the right thing in the refs handler.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That part is easy, it's making the command line parser / help text auto-formatter understand it that will be a little trickier, I'll see if I can make it work

Copy link
Member

@alanshaw alanshaw May 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, please take a look but if it's going to be a big time sink or over complicated then lets forget it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a command aliaser at the beginning of parsing (unfortunately it's not possible to do with yargs middleware): https://github.com/ipfs/js-ipfs/pull/2004/files#diff-71bd1bde77e38a68f76195b8f85ce19c

src/cli/commands/refs-local.js Outdated Show resolved Hide resolved
src/cli/commands/refs-local.js Outdated Show resolved Hide resolved
src/cli/commands/refs-local.js Outdated Show resolved Hide resolved
src/cli/commands/refs.js Outdated Show resolved Hide resolved
src/http/api/resources/files-regular.js Outdated Show resolved Hide resolved
src/http/api/resources/files-regular.js Outdated Show resolved Hide resolved
src/http/api/routes/files-regular.js Show resolved Hide resolved
src/http/api/routes/files-regular.js Show resolved Hide resolved
test/utils/ipfs-exec.js Outdated Show resolved Hide resolved
@dirkmc dirkmc requested a review from alanshaw May 3, 2019 16:05
@dirkmc dirkmc mentioned this pull request May 8, 2019
11 tasks
@alanshaw alanshaw mentioned this pull request May 9, 2019
44 tasks
@alanshaw
Copy link
Member

alanshaw commented May 13, 2019

@dirkmc I've released ipfs-http-client@31 and updated the dependency version here. What's left to do on this PR? I'd like to get it merged ASAP 😁

@dirkmc
Copy link
Contributor Author

dirkmc commented May 13, 2019

@alanshaw I think it's good to go 🚀

@dirkmc
Copy link
Contributor Author

dirkmc commented May 13, 2019

Oh hmm let me fix that commit message... it's failing commitlint

src/cli/commands/refs-local.js Outdated Show resolved Hide resolved
@alanshaw
Copy link
Member

Can we get some 💚 CI please @dirkmc?

@alanshaw alanshaw merged commit 6dc9075 into master May 16, 2019
@whyrusleeping whyrusleeping removed the status/in-progress In progress label May 16, 2019
hugomrdias added a commit that referenced this pull request May 16, 2019
…s-ipfs into feat/support-file-dom-api

* 'feat/support-file-dom-api' of github.com:ipfs/js-ipfs:
  feat: implement ipfs refs and refs local (#2004)
hugomrdias added a commit that referenced this pull request May 16, 2019
* 'feat/support-file-dom-api' of github.com:ipfs/js-ipfs:
  feat: implement ipfs refs and refs local (#2004)
@alanshaw alanshaw deleted the feat/refs branch May 19, 2019 12:06
alanshaw pushed a commit that referenced this pull request Aug 26, 2019
resolves #2012

Depends on
- [x] #2004
- [x] ipfs-inactive/js-ipfs-http-client#992
- [x] ipfs-inactive/interface-js-ipfs-core#462
- [x] achingbrain/mortice#1

TODO:
- [x] Core (mark and sweep)
- [x] CLI
- [x] http interface
- [x] interface-js-ipfs-core tests ipfs-inactive/interface-js-ipfs-core#462
- [x] nodejs-specific tests
- [x] Locking
- [x] Tests for locking
johnytiago pushed a commit to johnytiago/js-ipfs that referenced this pull request Sep 1, 2019
* feat: implement ipfs refs

* feat: refs support in http api

* feat: use ipld instead of unix-fs-exporter for refs

* test: add basic refs test

* feat: refs local

* feat: add refs.localPullStream && refs.localReadableStream

* chore: change Ref -> ref

* feat: make object.links work with CBOR

* feat: handle multiple refs. Better param handling

* fix: print refs errors to stderr

* chore: add comment to explain cli param parsing

* refactor: use streaming for refs local

* chore: update interface-ipfs-core package

* refactor: cleaner refs param handling

* fix: alias 'refs local' to 'refs-local'

* refactor: move links retrieval from object to refs

* chore: add missing packages

* refactor: use streaming for cli refs and refs local

* fix: add refs and refs local to command count

* fix: refs in browser

* fix: restore param parsing behaviour

* chore: update interface-ipfs-core

* chore: update http-client

* chore: update interface-ipfs-core

* fix: skip failing config.set test for now

* fix: skip failing config.set test in http-api

* chore: update interface-ipfs-core and ipfs-http-client

* chore: fix ipfs-http-client version
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants