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: add can store rm & can upload rm commands #101

Merged
merged 4 commits into from
Oct 3, 2023
Merged

feat: add can store rm & can upload rm commands #101

merged 4 commits into from
Oct 3, 2023

Conversation

olizilla
Copy link
Contributor

@olizilla olizilla commented Oct 2, 2023

adds impl, tests, and docs for the can store rm and can upload rm commands.

# remove root cid from upload list
$ w3 can upload rm <root-cid>

# remove car from store
$ w3 can store rm <car-cid>

License: MIT

adds impl, tests, and docs for the `can store rm` and `can upload rm` commands

License: MIT
Signed-off-by: Oli Evans <oli@protocol.ai>
License: MIT
Signed-off-by: Oli Evans <oli@protocol.ai>
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.

LGTM - a few suggestions but they are non blocking 🙂

README.md Outdated Show resolved Hide resolved
if (cid.version === 1 && cid.code === CAR.codec.code) {
return /** @type {CARLink} */ (cid)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Alternatively you could make this a type assertion function:

/**
 * Return true if CID is a CAR CID and false if not.
 * @param {import('multiformats').UnknownLink} cid
 * @returns {cid is import('multiformats').Link<Uint8Array, typeof CAR.codec.code>}
 */
export function isCarLink (cid) {
  return cid.version === 1 && cid.code === CAR.codec.code
}

...and then typescript knows it's a CAR CID later in the code and you don't have to re-assign e.g.:

Screenshot 2023-10-02 at 16 06 14

lib.js Outdated
error(`Error: ${cidStr} is not a CAR CID`)
}
return car
} catch (err) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
} catch (err) {
} catch {

lib.js Outdated
const cid = CID.parse(cidStr.trim())
const car = asCarLink(cid)
if (car === undefined) {
error(`Error: ${cidStr} is not a CAR CID`)
Copy link
Member

Choose a reason for hiding this comment

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

Kinda weird to destructure error from console...

I'd probably just have it throw when not a CAR CID and then in the calling code:

let cid
try {
  cid = parseCarLink(cidStr)
} catch {
  console.error(`Error: invalid CAR CID: ${cidStr}`)
  process.exit(1)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah it used to be parseCarLinkOrExit but that was weird too. Have simplified it again.

export function parseCarLink (cidStr) {
  try {
    return asCarLink(CID.parse(cidStr.trim()))
  } catch {}
}

calling code

const shard = parseCarLink(cidStr)
if (!shard) {
  console.error(`Error: ${cidStr} is not a CAR CID`)
  process.exit(1)
}

License: MIT
Signed-off-by: Oli Evans <oli@protocol.ai>
@olizilla olizilla merged commit a7bda04 into main Oct 3, 2023
1 check passed
@olizilla olizilla deleted the can-rm branch October 3, 2023 09:56
alanshaw pushed a commit that referenced this pull request Oct 18, 2023
🤖 I have created a release *beep* *boop*
---


##
[4.3.0](v4.2.1...v4.3.0)
(2023-10-18)


### Features

* add --verbose --json option to upload command and print piece CID
([#97](#97))
([775d1db](775d1db))
* add `can store rm` & `can upload rm` commands
([#101](#101))
([a7bda04](a7bda04))
* introduce unified service config
([#99](#99))
([f3b6220](f3b6220))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants