Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'cids' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
.then(result => {
expect(result.pinned).to.eql(pinned)
if (type === pinTypes.indirect) {
// indirect pins return a CID of recursively pinned root instead of 'indirect' string
expect(CID.isCID(result.reason)).to.be.true()
} else if (type !== pinTypes.all) {
expect(result.reason).to.eql(type)
}
})
}
module.exports = function (cid) {
if (Buffer.isBuffer(cid)) {
return new CID(cid).toString()
}
if (CID.isCID(cid)) {
return cid.toString()
}
if (typeof cid !== 'string') {
throw new Error('unexpected cid type: ' + typeof cid)
}
new CID(cid.split('/')[0]) // eslint-disable-line
return cid
}
// blocks are exclusive operations
const release = await self._gcLock.writeLock()
try {
for (let cid of cids) {
cid = cleanCid(cid)
const result = {
hash: cid.toString()
}
try {
const pinResult = await self.pin.pinManager.isPinnedWithType(cid, PinTypes.all)
if (pinResult.pinned) {
if (CID.isCID(pinResult.reason)) { // eslint-disable-line max-depth
throw errCode(new Error(`pinned via ${pinResult.reason}`))
}
throw errCode(new Error(`pinned: ${pinResult.reason}`))
}
// remove has check when https://github.com/ipfs/js-ipfs-block-service/pull/88 is merged
const has = await self._blockService._repo.blocks.has(cid)
if (!has) {
throw errCode(new Error('block not found'), 'ERR_BLOCK_NOT_FOUND')
}
await self._blockService.delete(cid)
} catch (err) {
if (!options.force) {
parallelMap(BLOCK_RM_CONCURRENCY, async cid => {
cid = cleanCid(cid)
const result = { hash: cid.toString() }
try {
const pinResult = await pinManager.isPinnedWithType(cid, PinTypes.all)
if (pinResult.pinned) {
if (CID.isCID(pinResult.reason)) { // eslint-disable-line max-depth
throw errCode(new Error(`pinned via ${pinResult.reason}`))
}
throw errCode(new Error(`pinned: ${pinResult.reason}`))
}
// remove has check when https://github.com/ipfs/js-ipfs-block-service/pull/88 is merged
const has = await blockService._repo.blocks.has(cid)
if (!has) {
throw errCode(new Error('block not found'), 'ERR_BLOCK_NOT_FOUND')
}
await blockService.delete(cid)
} catch (err) {
if (!options.force) {
async _walkDag ({ cid, preload = false, onCid = () => {} }) {
if (!CID.isCID(cid)) {
cid = new CID(cid)
}
const walk = (cid) => {
return async () => {
const { value: node } = await this.dag.get(cid, { preload })
onCid(cid)
if (cid.codec === 'dag-pb') {
queue.addAll(
node.Links.map(link => walk(link.Hash))
)
} else if (cid.codec === 'dag-cbor') {
for (const [_, childCid] of dagCborLinks(node)) { // eslint-disable-line no-unused-vars
queue.add(walk(childCid))
async function createMap (id) {
if (id) { // existing
if (!CID.isCID(id)) {
id = new CID(id)
}
return iamap.load(store, id)
}
// new map with default options, our hasher and custom store
return iamap.create(store, { hashAlg: 'murmur3-32' })
}
resolve (cid, path) {
if (!CID.isCID(cid)) {
throw new Error('`cid` argument must be a CID')
}
if (typeof path !== 'string') {
throw new Error('`path` argument must be a string')
}
const generator = async function * () {
// End iteration if there isn't a CID to follow anymore
while (cid !== null) {
const format = await this._getFormat(cid.codec)
// get block
// use local resolver
// update path value
const block = await promisify(this.bs.get.bind(this.bs))(cid)
const result = format.resolver.resolve(block.data, path)
const traverse = function * (node, path) {
// Traverse only objects and arrays
if (Buffer.isBuffer(node) || CID.isCID(node) || typeof node === 'string' ||
node === null) {
return
}
for (const item of Object.keys(node)) {
const nextpath = path === undefined ? item : path + '/' + item
yield nextpath
yield * traverse(node[item], nextpath)
}
}
const traverse = function * (node, path) {
// Traverse only objects and arrays
if (Buffer.isBuffer(node) || CID.isCID(node) || typeof node === 'string' ||
node === null) {
return
}
for (const item of Object.keys(node)) {
const nextpath = path === undefined ? item : path + '/' + item
yield nextpath
yield * traverse(node[item], nextpath)
}
}
const _traverse = function * (node, path) {
// Traverse only objects and arrays
if (Buffer.isBuffer(node) || CID.isCID(node) || typeof node === 'string' ||
node === null) {
return
}
for (const item of Object.keys(node)) {
const nextpath = path === undefined ? item : path + '/' + item
yield nextpath
yield * _traverse(node[item], nextpath)
}
}