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 all 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
7 changes: 3 additions & 4 deletions src/tutorials/0004-mutable-file-system/02.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,19 @@ 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')
```

This method returns an object with some essential data about our file or directory:

* **cid** (the CID object)
* **type** (a string that can be either `directory` or `file`)
* **size** (an integer with the file or directory size in Bytes)
* **cumulativeSize** (an integer with the size of the DAGNodes making up the file in Bytes)
* **type** (a string that can be either `directory` or `file`)
* **blocks** (if type is `directory`, this is the number of files in the directory; if type is `file`, it's the number of blocks that make up the file)
* **withLocality** (a boolean to indicate if locality information are present)
* **local** (a boolean to indicate if the queried dag is fully present locally)
* **sizeLocal** (an integer indicating the cumulative size of the data present locally)
* **mode** (the UnixFS mode as a Number)

*Gotcha!* The `size` of a directory is always `0`, no matter how many entries it contains, since directories are really just a set of links to other files and directories. A directory's `cumulativeSize`, by contrast, changes as the directory's contents change. It represents not just the file sizes of all the entries in that directory, but also the metadata that describes those entries: types, block sizes and so on.

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
5 changes: 3 additions & 2 deletions src/tutorials/0004-mutable-file-system/06.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ When your root directory was empty and you checked its status using [`ipfs.files
```js
{
"cid": CID("QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn"),
"type": "directory",
"size": 0,
"cumulativeSize": 4,
"blocks": 0,
"type": "directory",
"withLocality": false
"withLocality": false,
"mode": 493
}
```

Expand Down
8 changes: 4 additions & 4 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 Expand Up @@ -121,7 +121,7 @@ const validate = async (result, ipfs) => {
// filenames match and created empty some/stuff
return {
success: 'Success! Check out your directory contents below.',
logDesc: "Here's what was returned by `ls` in your root directory. Notice how directories have a type of `1` while files have a type of `0`.",
logDesc: "Here's what was returned by `ls` in your root directory.",
log: ipfsFilesInRoot.map(utils.format.ipfsObject)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/tutorials/0004-mutable-file-system/08-challenge.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Move only the files (no directories) from your root directory into the `some/stu

Remember that you can pass an array into `files.mv` as the `from` value. This is useful because it allows you to run the async function only once. Be sure to use the `await` keyword so that the `mv` call completes before the contents of your `/some/stuff` directory are evaluated.

When creating your array to pass in, ensure it only contains files, not directories. Remember that each object accessed through `files.ls` in IPFS has a `type` property that you can use to determine whether it's a file or a directory; its value is `0` for files and `1` for directories. (Hint: Try the [`filter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) or [`forEach`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach) array methods.)
When creating your array to pass in, ensure it only contains files, not directories. Remember that each object accessed through `files.ls` in IPFS has a `type` property that you can use to determine whether it's a `file` or a `directory`. (Hint: Try the [`filter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) or [`forEach`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach) array methods.)

Remember that `files.mv` needs paths, not filenames, so you'll need to prepend each filename in your array with `/`. (Hint: Try the [`map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) or [`forEach`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach) array methods and incorporate the `name` property available through the `files.ls` method.)

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
Loading