Skip to content

Commit

Permalink
fix: use remove from client (#167)
Browse files Browse the repository at this point in the history
by simply relying on remove from client, we miss some feedback we were
providing to the user on the CLI. We could add a `onShardDelete` to
client to make it a bit better. What do you think @alanshaw ?

Error testing for sharding is also now part of client and I removed
tests here as they would also have expectations on output/
  • Loading branch information
vasco-santos authored Jan 25, 2024
1 parent e746fe4 commit 96966ba
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 103 deletions.
35 changes: 2 additions & 33 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,45 +204,14 @@ export async function remove(rootCid, opts) {
process.exit(1)
}
const client = await getClient()
let upload

try {
upload = await client.capability.upload.remove(root)
await client.remove(root, opts)
} catch (/** @type {any} */ err) {
console.error(`Remove failed: ${err.message ?? err}`)
console.error(err)
process.exit(1)
}
if (!opts.shards) {
return
}
if (!upload.root) {
return console.log(
'⁂ upload not found. could not determine shards to remove.'
)
}
if (!upload.shards || !upload.shards.length) {
return console.log('⁂ no shards to remove.')
}

const { shards } = upload
console.log(
`⁂ removing ${shards.length} shard${shards.length === 1 ? '' : 's'}`
)

/** @param {import('@web3-storage/w3up-client/types').CARLink} shard */
function removeShard(shard) {
return oraPromise(client.capability.store.remove(shard), {
text: `${shard}`,
successText: `${shard} removed`,
failText: `${shard} failed`,
})
}

const results = await Promise.allSettled(shards.map(removeShard))

if (results.some((res) => res.status === 'rejected')) {
process.exit(1)
}
}

/**
Expand Down
90 changes: 79 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"@web3-storage/access": "^18.0.7",
"@web3-storage/data-segment": "^5.0.0",
"@web3-storage/did-mailto": "^2.1.0",
"@web3-storage/w3up-client": "^11.2.1",
"@web3-storage/w3up-client": "^12.2.0",
"ansi-escapes": "^6.2.0",
"chalk": "^5.3.0",
"files-from-path": "^1.0.4",
Expand Down
61 changes: 3 additions & 58 deletions test/bin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -774,69 +774,14 @@ export const testW3Up = {
])
.env(context.env.alice)
.join()
.catch()

assert.equal(rm.status.code, 0)
assert.match(
rm.output,
/upload not found. could not determine shards to remove/
)
}),

'w3 remove --shards': test(async (assert, context) => {
await loginAndCreateSpace(context)

const up = await w3
.args(['up', 'test/fixtures/pinpie.jpg'])
.env(context.env.alice)
.join()

assert.match(
up.output,
/bafybeiajdopsmspomlrpaohtzo5sdnpknbolqjpde6huzrsejqmvijrcea/
)

const rm = await w3
.args([
'rm',
'bafybeiajdopsmspomlrpaohtzo5sdnpknbolqjpde6huzrsejqmvijrcea',
'--shards',
])
.env(context.env.alice)
.join()

assert.equal(rm.status.code, 0)

assert.match(rm.output, /1 shard/)
assert.equal(rm.status.code, 1)
assert.match(
rm.error,
/bagbaieraxkuzouwfuphnqlbbpobywmypb26stej5vbwkelrv7chdqoxfuuea removed/
/Upload not found/
)
}),

'w3 remove --shards - no shards to remove': test(async (assert, context) => {
const space = await loginAndCreateSpace(context)

const root = parseLink(
'bafybeih2k7ughhfwedltjviunmn3esueijz34snyay77zmsml5w24tqamm'
)

// store upload without any shards
await context.uploadTable.insert({
space,
root,
shards: [],
issuer: Test.alice.did(),
invocation: parseLink('bafkqaaa'),
})

const rm = await w3
.args(['rm', root.toString(), '--shards'])
.env(context.env.alice)
.join()

assert.equal(rm.status.code, 0)
assert.match(rm.output, /no shards to remove/)
}),
}

export const testDelegation = {
Expand Down

0 comments on commit 96966ba

Please sign in to comment.