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

chore: upgrade ipfs to 0.55.x #661

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62,467 changes: 27,330 additions & 35,137 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
"googleapis": "^71.0.0",
"highlight.js": "^9.12.0",
"inquirer": "^7.1.0",
"ipfs": "^0.50.2",
"ipfs": "^0.55.1",
"ipfs-css": "^0.6.0",
"it-all": "^1.0.5",
"it-to-buffer": "^1.0.1",
"it-to-buffer": "^2.0.0",
"lodash": "^4.17.19",
"mailchimp-api-v3": "^1.13.1",
"markdown-toc": "^1.2.0",
Expand All @@ -60,7 +60,10 @@
"vuelidate": "^0.7.5"
},
"devDependencies": {
"@babel/plugin-proposal-optional-chaining": "^7.14.2",
"@babel/preset-env": "^7.14.2",
"@cypress/webpack-preprocessor": "^4.1.1",
"@vue/babel-preset-app": "^4.5.13",
"@vue/cli-plugin-babel": "^3.12.1",
"@vue/cli-plugin-eslint": "^3.12.1",
"@vue/cli-service": "^3.12.1",
Expand Down Expand Up @@ -119,9 +122,7 @@
}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 8"
"last 2 versions and not dead and > 2%"
],
"bin": {
"protowizard": "./scripts/commands/wizard/index.js"
Expand Down
2 changes: 1 addition & 1 deletion src/tutorials/0004-mutable-file-system/02.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ When working with your IPFS node, you'll often want to check the status of a fil

For example, to check the status of a directory called `stuff` located within our root directory ( `/` ), we could call the method like so:

````javascript
```javascript
await ipfs.files.stat('/stuff')
```

Expand Down
2 changes: 1 addition & 1 deletion src/tutorials/0004-mutable-file-system/04.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const validate = async (result, ipfs) => {
let uploadedFilenames = uploadedFiles.map(file => file.name.toString()).sort()
let ipfsFilenames = ipfsFiles.map(file => file.name.toString()).sort()
let itemsMatch = JSON.stringify(ipfsFilenames) === JSON.stringify(uploadedFilenames)
let itemsAreFiles = ipfsFiles.every(file => file.type === 0)
let itemsAreFiles = ipfsFiles.every(file => file.type === 'file')

if (itemsMatch && itemsAreFiles) {
return {
Expand Down
2 changes: 1 addition & 1 deletion src/tutorials/0004-mutable-file-system/05.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const validate = async (result, ipfs) => {
let uploadedFilenames = uploadedFiles.map(file => file.name.toString()).sort()
let ipfsFilenames = expected.map(file => file.name.toString()).sort()
let itemsMatch = JSON.stringify(ipfsFilenames) === JSON.stringify(uploadedFilenames)
let itemsAreFiles = expected.every(file => file.type === 0)
let itemsAreFiles = expected.every(file => file.type === 'file')
let rightFilesUploaded = itemsMatch && itemsAreFiles

if (!result) {
Expand Down
5 changes: 2 additions & 3 deletions src/tutorials/0004-mutable-file-system/05.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ such as `/catPics`,
`files.ls` produces an array of objects, one for each file or directory
contained in the directory you're inspecting, with the following properties:

- `cid`: the Content Identifier (CID) that identifies your file in IPFS
- `name`: the file's name
- `type`: the object's type (`0` - file or `1` - directory)
- `type`: the object's type (`file` or `directory`)
- `size`: the size of the file in bytes
- `cid`: the Content Identifier (CID) that identifies your file in IPFS
- `mode`: the UnixFS mode as a Number
- `mtime`: an object with numeric `secs` and `nsecs` properties
Copy link
Member Author

Choose a reason for hiding this comment

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

This field will be present if found in the DAG so it's probably worth keeping it here with a note that it's an optional property.

That is, mode gets a default value depending on if the entry is a file or directory, but mtime does not.


If we wanted to inspect the contents of a `/catPics`
directory, we could do it like this:
Expand Down
6 changes: 3 additions & 3 deletions src/tutorials/0004-mutable-file-system/07.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ const validate = async (result, ipfs) => {
let stringifiedResult = JSON.stringify(result, null, 2)
let ipfsFilesInRoot = await all(ipfs.files.ls('/'))
let listedRoot = stringifiedResult === JSON.stringify(ipfsFilesInRoot, null, 2)
let rootSomeItemIsFile = ipfsFilesInRoot.some(file => file.type === 0)
let rootSomeItemIsFile = ipfsFilesInRoot.some(file => file.type === 'file')

const includesSome = ipfsFilesInRoot.some(file => file.name === 'some' && file.type === 1)
const includesSome = ipfsFilesInRoot.some(file => file.name === 'some' && file.type === 'directory')
if (includesSome) {
const ipfsFilesInSome = await all(ipfs.files.ls('/some'))
listedSome = stringifiedResult === JSON.stringify(ipfsFilesInSome, null, 2)

const includesStuff = ipfsFilesInSome.some(file => file.name === 'stuff' && file.type === 1)
const includesStuff = ipfsFilesInSome.some(file => file.name === 'stuff' && file.type === 'directory')
if (includesStuff) {
const ipfsFilesInSomeStuff = await all(ipfs.files.ls('/some/stuff'))
listedSomeStuff = stringifiedResult === JSON.stringify(ipfsFilesInSomeStuff, null, 2)
Expand Down
10 changes: 5 additions & 5 deletions src/tutorials/0004-mutable-file-system/08.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const validate = async (result, ipfs) => {

// check whether contents of /some/stuff are the right files
itemsMatch = JSON.stringify(someStuffFilenames) === JSON.stringify(uploadedFilenames)
itemsAreFiles = someStuffFiles.every(file => file.type === 0)
itemsAreFiles = someStuffFiles.every(file => file.type === 'file')
}

if (!result) {
Expand Down Expand Up @@ -61,7 +61,7 @@ const validate = async (result, ipfs) => {
fail: utils.validationMessages.VALUE_IS_ASYNC_ITERABLE_ALL
}
} else if (rootIsEmpty) {
return { fail: 'Your root directory is empty. Did you accidentally move the `some/stuff` directory? Remember to test whether each item is a file (`type === 0`) before moving it.' }
return { fail: 'Your root directory is empty. Did you accidentally move the `some/stuff` directory? Remember to test whether each item is a file (`type === \'file\'`) before moving it.' }
} else if (result instanceof Error && result.code === utils.ipfs.errorCodes.ERR_INVALID_PATH) {
return {
fail: 'Invalid path. Did you use just the file name when attempting to move each file? Remember to start the path with a leading `/`.',
Expand Down Expand Up @@ -119,11 +119,11 @@ const run = async (files) => {
await ipfs.files.mkdir('/some/stuff', { parents: true })
const rootDirectoryContents = await all(ipfs.files.ls('/'))

const filepathsToMove = rootDirectoryContents.filter(file => file.type === 0).map(file => '/' + file.name)
await ipfs.files.mv(...filepathsToMove, '/some/stuff')
const filepathsToMove = rootDirectoryContents.filter(file => file.type === 'file').map(file => '/' + file.name)
await ipfs.files.mv(filepathsToMove, '/some/stuff')

// // alternatively, wrapping multiple mv calls into a single async function with await:
// const filesToMove = rootDirectoryContents.filter(item => item.type === 0)
// const filesToMove = rootDirectoryContents.filter(item => item.type === 'file')
// await Promise.all(filesToMove.map(file => {
// return ipfs.files.mv('/' + file.name, '/some/stuff')
// }))
Expand Down
12 changes: 3 additions & 9 deletions src/tutorials/0004-mutable-file-system/08.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The method looks like this:
await ipfs.files.mv(from, to, [options])
```

`from` is the source path (or paths) of the content you'd like to move. `to` is the destination path.
`from` is the source path (or paths) of the content you'd like to move and can be a string or an array of strings. `to` is the destination path.

If your destination path references parent directories that don't already exist, you'll need to use the `{ parents: true }` option, just as you did with `files.mkdir`.

Expand All @@ -28,15 +28,9 @@ await ipfs.files.mv('/source-directory', '/destination-directory')
await ipfs.files.mv('/source-file.txt', '/destination-file.txt')
```

To move multiple files into a directory, you can add multiple source paths before the `to` argument:
To move multiple files into a directory, you can pass `from` as an array of paths:

```js
// move multiple files into a directory
await ipfs.files.mv('/source-file-1.txt', '/source-file-2.txt', '/source-file-3.txt', '/destination-directory')
```

If you're starting with an array of source paths, you can use JavaScript's [spread syntax](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax) to expand its elements into the required format:

```js
await ipfs.files.mv(...fromArray, '/destination-directory')
await ipfs.files.mv(['/source-file-1.txt', '/source-file-2.txt', '/source-file-3.txt'], '/destination-directory')
```
8 changes: 4 additions & 4 deletions src/tutorials/0004-mutable-file-system/09.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ const run = async (files) => {
await Promise.all(files.map(f => ipfs.files.write('/' + f.name, f, { create: true })))
await ipfs.files.mkdir('/some/stuff', { parents: true })
const rootDirectoryContents = await all(ipfs.files.ls('/'))
const filepathsToMove = rootDirectoryContents.filter(file => file.type === 0).map(file => '/' + file.name)
await ipfs.files.mv(...filepathsToMove, '/some/stuff')
const filepathsToMove = rootDirectoryContents.filter(file => file.type === 'file').map(file => '/' + file.name)
await ipfs.files.mv(filepathsToMove, '/some/stuff')

// Your code goes here

Expand All @@ -109,8 +109,8 @@ const run = async (files) => {
await Promise.all(files.map(f => ipfs.files.write('/' + f.name, f, { create: true })))
await ipfs.files.mkdir('/some/stuff', { parents: true })
const rootDirectoryContents = await all(ipfs.files.ls('/'))
const filepathsToMove = rootDirectoryContents.filter(file => file.type === 0).map(file => '/' + file.name)
await ipfs.files.mv(...filepathsToMove, '/some/stuff')
const filepathsToMove = rootDirectoryContents.filter(file => file.type === 'file').map(file => '/' + file.name)
await ipfs.files.mv(filepathsToMove, '/some/stuff')

await ipfs.files.cp('/ipfs/QmWCscor6qWPdx53zEQmZvQvuWQYxx1ARRCXwYVE4s9wzJ', '/some/stuff/success.txt')

Expand Down
7 changes: 2 additions & 5 deletions src/tutorials/0004-mutable-file-system/09.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Unlike `files.mv`, which removes items from their source path when moving them t

The method looks like this:
```js
await ipfs.files.cp(...from, to, [options])
await ipfs.files.cp(from, to, [options])
```
However, you now have two formatting options for `from`. You can pass in either:

Expand All @@ -25,11 +25,8 @@ You can use `files.cp` to perform a number of different operations:
await ipfs.files.cp('/source-file.txt', '/destination-directory')
await ipfs.files.cp('/ipfs/QmWGeRAEgtsHW3ec7U4qW2CyVy7eA2mFRVbk1nb24jFyks', '/destination-directory')

// copy multiple files into a directory (note the two acceptable formats with or without [ ])
await ipfs.files.cp('/source-file-1.txt', '/source-file-2.txt', '/destination-directory')
// copy multiple files into a directory (note `from` is now an array)
await ipfs.files.cp(['/source-file-1.txt', '/source-file-2.txt'], '/destination-directory')
await ipfs.files.cp('/ipfs/QmWGeRAEgtsHW3ec7U4qW2CyVy7eA2mFRVbk1nb24jFyks',
'/ipfs/QmWGeRAEgtsHW3jk7U4qW2CyVy7eA2mFRVbk1nb24jFyre', '/destination-directory')
await ipfs.files.cp(['/ipfs/QmWGeRAEgtsHW3ec7U4qW2CyVy7eA2mFRVbk1nb24jFyks',
'/ipfs/QmWGeRAEgtsHW3jk7U4qW2CyVy7eA2mFRVbk1nb24jFyre'], '/destination-directory')

Expand Down
11 changes: 6 additions & 5 deletions src/tutorials/0004-mutable-file-system/10.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ const run = async (files) => {
await Promise.all(files.map(f => ipfs.files.write('/' + f.name, f, { create: true })))
await ipfs.files.mkdir('/some/stuff', { parents: true })
let rootDirectoryContents = await all(ipfs.files.ls('/'))
const filepathsToMove = rootDirectoryContents.filter(file => file.type === 0).map(file => '/' + file.name)
await ipfs.files.mv(...filepathsToMove, '/some/stuff')
const filepathsToMove = rootDirectoryContents.filter(file => file.type === 'file').map(file => '/' + file.name)
await ipfs.files.mv(filepathsToMove, '/some/stuff')
await ipfs.files.cp('/ipfs/QmWCscor6qWPdx53zEQmZvQvuWQYxx1ARRCXwYVE4s9wzJ', '/some/stuff/success.txt')
let someStuffDirectoryContents = await all(ipfs.files.ls('/some/stuff'))

Expand All @@ -53,12 +53,13 @@ const run = async (files) => {
await Promise.all(files.map(f => ipfs.files.write('/' + f.name, f, { create: true })))
await ipfs.files.mkdir('/some/stuff', { parents: true })
let rootDirectoryContents = await all(ipfs.files.ls('/'))
const filepathsToMove = rootDirectoryContents.filter(file => file.type === 0).map(file => '/' + file.name)
await ipfs.files.mv(...filepathsToMove, '/some/stuff')
const filepathsToMove = rootDirectoryContents.filter(file => file.type === 'file').map(file => '/' + file.name)
await ipfs.files.mv(filepathsToMove, '/some/stuff')
await ipfs.files.cp('/ipfs/QmWCscor6qWPdx53zEQmZvQvuWQYxx1ARRCXwYVE4s9wzJ', '/some/stuff/success.txt')
let someStuffDirectoryContents = await all(ipfs.files.ls('/some/stuff'))

let secretMessage = (await toBuffer(ipfs.files.read('/some/stuff/success.txt'))).toString('utf8')
let secretMessageContents = await toBuffer(ipfs.files.read('/some/stuff/success.txt'))
let secretMessage = new TextDecoder().decode(secretMessageContents)

return secretMessage
}
Expand Down
4 changes: 2 additions & 2 deletions src/tutorials/0004-mutable-file-system/10.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ ipfs.files.read(path, [options])

The `path` provided is the path of the file to read, and it must point to a file rather than a directory.

The `files.read` method returns an Async Iterable that iterates over the file's chunks of data, i.e. Buffers. In our case, we ultimately need to convert Buffers into strings using the method `toString()`. However, the chunks of data within a single file need to be reassembled (concatenated) before the conversion. The [`it-to-buffer`](https://www.npmjs.com/package/it-to-buffer) package can iterate over all of the chunks and put them back together for us. (We've made this package available to you in our challenges as `toBuffer`.)
The `files.read` method returns an Async Iterable that iterates over the file's chunks of data, i.e. Buffers. In our case, we ultimately need to convert Buffers into strings using the method `new TextDecoder().encode(buffer)`. However, the chunks of data within a single file need to be reassembled (concatenated) before the conversion. The [`it-to-buffer`](https://www.npmjs.com/package/it-to-buffer) package can iterate over all of the chunks and put them back together for us. (We've made this package available to you in our challenges as `toBuffer`.)

```js
// the toBuffer variable is globally available (just like ipfs)

let bufferedContents = await toBuffer(ipfs.files.read('/directory/some-file.txt')) // a buffer
let contents = bufferedContents.toString() // a string
let contents = new TextDecoder().decode(bufferedContents) // a string
```

When you're ready to try this in the real world, you should note that the above example can result in heavy memory usage, depending on the contents of the file being read. If you're working with large files and find this to be the case, you might want to skip using the `it-to-buffer` package and instead process each chunk of data iteratively. The main reason IPFS now returns `Async Iterables` is to provide a built-in option for dealing with potential performance issues.
Expand Down
8 changes: 4 additions & 4 deletions src/tutorials/0004-mutable-file-system/11.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ const run = async (files) => {
await Promise.all(files.map(f => ipfs.files.write('/' + f.name, f, { create: true })))
await ipfs.files.mkdir('/some/stuff', { parents: true })
let rootDirectoryContents = await all(ipfs.files.ls('/'))
const filepathsToMove = rootDirectoryContents.filter(file => file.type === 0).map(file => '/' + file.name)
await ipfs.files.mv(...filepathsToMove, '/some/stuff')
const filepathsToMove = rootDirectoryContents.filter(file => file.type === 'file').map(file => '/' + file.name)
await ipfs.files.mv(filepathsToMove, '/some/stuff')
await ipfs.files.cp('/ipfs/QmWCscor6qWPdx53zEQmZvQvuWQYxx1ARRCXwYVE4s9wzJ', '/some/stuff/success.txt')
let someStuffDirectoryContents = await all(ipfs.files.ls('/some/stuff'))

Expand All @@ -87,8 +87,8 @@ const run = async (files) => {
await Promise.all(files.map(f => ipfs.files.write('/' + f.name, f, { create: true })))
await ipfs.files.mkdir('/some/stuff', { parents: true })
let rootDirectoryContents = await all(ipfs.files.ls('/'))
const filepathsToMove = rootDirectoryContents.filter(file => file.type === 0).map(file => '/' + file.name)
await ipfs.files.mv(...filepathsToMove, '/some/stuff')
const filepathsToMove = rootDirectoryContents.filter(file => file.type === 'file').map(file => '/' + file.name)
await ipfs.files.mv(filepathsToMove, '/some/stuff')
await ipfs.files.cp('/ipfs/QmWCscor6qWPdx53zEQmZvQvuWQYxx1ARRCXwYVE4s9wzJ', '/some/stuff/success.txt')
let someStuffDirectoryContents = await all(ipfs.files.ls('/some/stuff'))

Expand Down
7 changes: 3 additions & 4 deletions src/tutorials/0004-mutable-file-system/11.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@
MFS allows you to remove files or directories using the [`files.rm`](https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/FILES.md#ipfsfilesrmpaths-options) method:

```js
await ipfs.files.rm(...paths, [options])
await ipfs.files.rm(path, [options])
```

`paths` are one or more paths to remove.
`path` is one or more paths to remove - passed as a string or an array of strings.

By default, if you attempt to remove a directory that still has contents, the request will fail. To remove a directory and everything contained in it, you'll need to use the option `{ recursive: true }`.

```js
// remove a file
await ipfs.files.rm('/my/beautiful/file.txt')

// remove multiple files (note the two acceptable formats with or without [ ])
await ipfs.files.rm('/my/beautiful/file.txt', '/my/other/file.txt')
// remove multiple files (note `path` is now an array)
await ipfs.files.rm(['/my/beautiful/file.txt', '/my/other/file.txt'])

// remove a directory and its contents
Expand Down
4 changes: 2 additions & 2 deletions src/tutorials/0005-regular-files-api/04-challenge.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ Using the `cat` function, retrieve the file's contents and return them as a stri

**Hints:**

- The `CID` we provide is a string, so it needs to be placed inside quotes. Also, don't forget to convert the buffered contents of the text file to a string using `.toString()` before returning your result.
- You need to concatenate all the chunks of data because the `ipfs.cat` method returns an `Async Iterable`. You can use the package `it-to-buffer` to achieve this.
- The `CID` we provide is a string, so it needs to be placed inside quotes. Also, don't forget to convert the buffered contents of the text file to a string using `new TextDecoder().decode()` before returning your result.
- You need to concatenate all the chunks of data because the `ipfs.cat` method returns an `Async Iterable`. You can use the package `it-to-buffer` to achieve this.
2 changes: 1 addition & 1 deletion src/tutorials/0005-regular-files-api/04.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const solution = `/* global ipfs, toBuffer */

const run = async () => {
const fileContents = await toBuffer(ipfs.cat('QmWCscor6qWPdx53zEQmZvQvuWQYxx1ARRCXwYVE4s9wzJ'))
const message = fileContents.toString()
const message = new TextDecoder().decode(fileContents)

return message
}
Expand Down
4 changes: 2 additions & 2 deletions src/tutorials/0005-regular-files-api/04.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The `cat` method first searches your own node for the file requested, and if it

The `cat` method returns an Async Iterable that iterates over the file's chunks of data, i.e. Buffers.

A `Buffer` is just a raw collection of bytes and as such doesn't make any assumptions about encodings or the type of data it contains. However, if we know the file being retrieved is a plain text file such as a `.txt`, we can convert its buffered contents to a UTF-8 string (an interpretation of those raw bytes) by calling the JavaScript method `.toString()`.
A `Buffer` is just a raw collection of bytes and as such doesn't make any assumptions about encodings or the type of data it contains. However, if we know the file being retrieved is a plain text file such as a `.txt`, we can convert its buffered contents to a UTF-8 string (an interpretation of those raw bytes) by calling the JavaScript method `new TextDecoder().decode()`.

But since we have multiple buffers of the same file, we need to reassemble them (concatenate) into a single buffer before converting it into a string. The [`it-to-buffer`](https://www.npmjs.com/package/it-to-buffer) package can do just that: iterate over all of the chunks of the file and put them back together for us.

Expand All @@ -25,7 +25,7 @@ So if you had the CID for a text file in an IPFS node, you could retrieve the fi
// the toBuffer variable is globally available (just like ipfs)

const bufferedContents = await toBuffer(ipfs.cat('QmWCscor6qWPdx53zEQmZvQvuWQYxx1ARRCXwYVE4s9wzJ')) // returns a Buffer
const stringContents = bufferedContents.toString() // returns a string
const stringContents = new TextEncoder().decode(bufferedContents) // returns a string
```

When you're ready to try this in the real world, you should note that the above example can result in heavy memory usage, depending on the contents of the file being read. If you're working with large files and find this to be the case, you might want to skip using the `it-to-buffer` package and instead process each chunk of data iteratively. The main reason IPFS now returns `Async Iterables` is to provide a built-in option for dealing with potential performance issues.
Expand Down
Loading