Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support name in ls #260

Merged
merged 6 commits into from
Feb 15, 2025
Merged

feat: support name in ls #260

merged 6 commits into from
Feb 15, 2025

Conversation

oed
Copy link
Contributor

@oed oed commented Feb 12, 2025

According to the Kubo docs (and practical experience) the pin label (name) is returned top level on the pin item (not in Metadata)

Also doesn't seem like Metadata is a thing anymore, but left it in case.

@oed
Copy link
Contributor Author

oed commented Feb 13, 2025

Looks like there's just a timeout on the windows tests?

@achingbrain
Copy link
Member

Thanks for submitting this - could you please add a test or some assertions to an existing test in https://github.com/ipfs/js-kubo-rpc-client/blob/main/test/interface-tests/src/pin/ls.ts to ensure this works as expected and there will be no regressions in future?

@oed
Copy link
Contributor Author

oed commented Feb 14, 2025

Sure can, however I'm having some issues installing dependencies locally.

% npm i

npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '[email protected]',
npm WARN EBADENGINE   required: { node: '>=20.18.1' },
npm WARN EBADENGINE   current: { node: 'v20.10.0', npm: '10.2.3' }
npm WARN EBADENGINE }
npm WARN deprecated [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm WARN deprecated [email protected]: This package is deprecated. Use the optional chaining (?.) operator instead.
npm WARN deprecated @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-nullish-coalescing-operator instead.
npm WARN deprecated @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead.
npm WARN deprecated @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-catch-binding instead.
npm WARN deprecated [email protected]: Renamed to read-package-up
npm WARN deprecated [email protected]: Rimraf versions prior to v4 are no longer supported
npm WARN deprecated [email protected]: This package is deprecated. Use require('node:util').isDeepStrictEqual instead.
npm WARN deprecated [email protected]: this library is no longer supported
npm WARN deprecated @humanwhocodes/[email protected]: Use @eslint/config-array instead
npm WARN deprecated @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-chaining instead.
npm WARN deprecated @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-async-generator-functions instead.
npm WARN deprecated [email protected]: Rimraf versions prior to v4 are no longer supported
npm WARN deprecated [email protected]: Rimraf versions prior to v4 are no longer supported
npm WARN deprecated [email protected]: Rimraf versions prior to v4 are no longer supported
npm WARN deprecated [email protected]: Rimraf versions prior to v4 are no longer supported
npm WARN deprecated [email protected]: Rimraf versions prior to v4 are no longer supported
npm WARN deprecated @humanwhocodes/[email protected]: Use @eslint/object-schema instead
npm WARN deprecated [email protected]: Glob versions prior to v9 are no longer supported
npm WARN deprecated [email protected]: Glob versions prior to v9 are no longer supported
npm WARN deprecated [email protected]: Glob versions prior to v9 are no longer supported
npm WARN deprecated [email protected]: Glob versions prior to v9 are no longer supported
npm WARN deprecated [email protected]: Glob versions prior to v9 are no longer supported
npm WARN deprecated [email protected]: Glob versions prior to v9 are no longer supported
npm WARN deprecated @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-object-rest-spread instead.
npm WARN deprecated [email protected]: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
npm WARN deprecated [email protected]: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated [email protected]: This module has been superseded by the multiformats module
npm WARN deprecated [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated [email protected]: This version is no longer supported. Please see https://eslint.org/version-support for other options.
npm WARN deprecated [email protected]: This package will stop receiving updates in the near future. Please migrate to @oas-tools/core and refer to documentation at https://oas-tools.github.io/docs/migration
npm ERR! code 1
npm ERR! path /Users/joel/code/js-kubo-rpc-client/node_modules/kubo
npm ERR! command failed
npm ERR! command sh -c node src/post-install.js
npm ERR! https://dist.ipfs.tech/kubo/versions
npm ERR! HTTPError: Response code 504 (Gateway Timeout)
npm ERR!     at Request.<anonymous> (/Users/joel/code/js-kubo-rpc-client/node_modules/got/dist/source/as-promise/index.js:118:42)
npm ERR!     at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
npm ERR!   code: 'ERR_NON_2XX_3XX_RESPONSE',
npm ERR!   timings: {
npm ERR!     start: 1739540225453,
npm ERR!     socket: 1739540225453,
npm ERR!     lookup: 1739540225453,
npm ERR!     connect: 1739540225453,
npm ERR!     secureConnect: 1739540225453,
npm ERR!     upload: 1739540225453,
npm ERR!     response: 1739540285625,
npm ERR!     end: 1739540285626,
npm ERR!     error: undefined,
npm ERR!     abort: undefined,
npm ERR!     phases: {
npm ERR!       wait: 0,
npm ERR!       dns: 0,
npm ERR!       tcp: 0,
npm ERR!       tls: 0,
npm ERR!       request: 0,
npm ERR!       firstByte: 60172,
npm ERR!       download: 1,
npm ERR!       total: 60173
npm ERR!     }
npm ERR!   }
npm ERR! }

npm ERR! A complete log of this run can be found in: /Users/joel/.npm/_logs/2025-02-14T13_33_51_093Z-debug-0.log

@oed
Copy link
Contributor Author

oed commented Feb 14, 2025

Actually that seems to be an issue with the IDE I was using. Got it working now.

@achingbrain
Copy link
Member

No, I think the infrastructure is flaky 🙄. It was 504ing for me too when you posted that, someone's rebooted something and it works now.

@oed
Copy link
Contributor Author

oed commented Feb 14, 2025

How do I test only a specific file with aegir btw?
I get this error when trying the obvious way:

% npm t -- -f test/interface-tests/src/pin/ls.ts   

> [email protected] test
> aegir test -f test/interface-tests/src/pin/ls.ts

build

> [email protected] build
> aegir build

[15:19:59] tsc [started]
[15:20:01] tsc [completed]
[15:20:01] esbuild [started]
[15:20:01] esbuild [completed]
test node.js

 Exception during run: TypeError: Unknown file extension ".ts" for /Users/joel/code/js-kubo-rpc-client/test/interface-tests/src/pin/ls.ts
    at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:160:9)
    at defaultGetFormat (node:internal/modules/esm/get_format:203:36)
    at defaultLoad (node:internal/modules/esm/load:141:22)
    at ModuleLoader.load (node:internal/modules/esm/loader:409:7)
    at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:291:45)
    at link (node:internal/modules/esm/module_job:76:21) {
  code: 'ERR_UNKNOWN_FILE_EXTENSION'
}
Command failed with exit code 1: mocha test/interface-tests/src/pin/ls.ts --ui bdd --require source-map-support/register --timeout=60000 --bail

@achingbrain
Copy link
Member

achingbrain commented Feb 14, 2025

You can use --grep to match strings from describe or it invocations:

npx aegir test -t node --grep 'a string to match'

You can also stick a .only on the test(s) you want to run:

describe.only('...
it.only('...

@achingbrain
Copy link
Member

achingbrain commented Feb 14, 2025

The tests look good - thanks for adding them.

I think it just needs an assertion that the .name property is included in objects yielded from ipfs.pin.ls as part of the PinLsResult interface then it's ready.

If I read it correctly you could just add it to the should list all recursive pins test:

expect(pinset).to.deep.include({
  type: 'recursive',
  cid: fixtures.files[0].cid,
  name: fixtures.files[0].pinName // <- add this line
})

@oed
Copy link
Contributor Author

oed commented Feb 14, 2025

So interestingly Kubo doesn't return name if it's not something you queried for, but added a check for it in the tests I introduced.

}

export interface PinLsResult {
cid: CID
type: PinType | string
metadata?: Record<string, any>
name?: string
Copy link
Member

Choose a reason for hiding this comment

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

If Kubo doesn’t return this field, does it need to be in the interface?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Kubo does return it if you call pin.ls with the name param. Otherwise not. So yes it needs to be there as optional.

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 think the reason it's not returned by default is that one CID can have multiple names it's pinned under.

Copy link
Member

Choose a reason for hiding this comment

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

Aha, gotcha - so it just needs a test that shows this then all is good.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, so now we test for both cases:

  • should list all types of pins tests that name isn't returned in the regular case
  • should list multiple partially matched named pins and should list specific named pin tests that name is returned

Copy link
Member

Choose a reason for hiding this comment

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

That's perfect, thanks for making those changes.

@achingbrain achingbrain merged commit df1d483 into ipfs:main Feb 15, 2025
19 checks passed
github-actions bot pushed a commit that referenced this pull request Feb 15, 2025
## [5.1.0](v5.0.2...v5.1.0) (2025-02-15)

### Features

* support name in pin.ls ([#260](#260)) ([df1d483](df1d483)), closes [/docs.ipfs.tech/reference/kubo/rpc/#api-v0](https://github.com/ipfs//docs.ipfs.tech/reference/kubo/rpc//issues/api-v0)

### Dependencies

* bump @multiformats/multiaddr-to-uri from 10.1.2 to 11.0.0 ([#249](#249)) ([dafa529](dafa529))
* bump parse-duration from 1.1.2 to 2.1.2 ([#257](#257)) ([3d28859](3d28859))
* **dev:** bump nock from 13.5.6 to 14.0.1 ([#259](#259)) ([06f6f1e](06f6f1e))
Copy link
Contributor

🎉 This PR is included in version 5.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@oed
Copy link
Contributor Author

oed commented Feb 15, 2025

Thanks @achingbrain !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants