Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 805c2fd

Browse files
committed
fix: optional arguments go in the options object
We have a few older APIs that take multiple optional arguments, which makes our code more complicated as it has to guess the users' intent, sometimes by inspecting properties on the passed args to see if they happen to correspond with paroperties on the actual options object. The options object was recently added to all API calls and is the right place for optional arguments to go, so the change here is to move all optional arguments into the options object, except where the presence of an optional argument dramatically changes the behaviour of the call (`ipfs.bootstrap` I'm mostly looking at you), in which case the methods are split out into multiple versions that do distinct things. Only the programatic API is affected, the CLI and HTTP APIs do not change. BREAKING CHANGES: - `ipfs.bitswap.wantlist([peer], [options]) becomes `ipfs.bitswap([options]) - `peer` is moved into the `options` object - `ipfs.bootstrap.add([addr], [options])` is split into: - `ipfs.bootstrap.add(addr, [options])` - add a bootstrap node - `ipfs.bootstrap.reset()` - restore the default list of bootstrap nodes - `ipfs.bootstrap.rm([addr], [options])` is split into: - `ipfs.bootstrap.rm(addr, [options])` - remove a bootstrap node - `ipfs.bootstrap.clear([options]) - empty the bootstrap list - `ipfs.dag.get(cid, [path], [options]) becomes `ipfs.dag.get(cid, [options])` - `path` is moved into the `options` object - `ipfs.files.flush([path], [options])` becomes `ipfs.files.flush(path, [options])` - `ipfs.files.ls([path], [options])` becomes `ipfs.files.ls(path, [options])` - `ipfs.object.new([template], [options]) becomes `ipfs.object.new([options])` - `template` is moved into the `options` object - `ipfs.pin.ls([paths], [options])` is split into: - `ipfs.pin.ls([options])` - list all pins - `ipfs.pin.query(paths, [options])` - find out if certain paths/cids are pinned
1 parent 21dab48 commit 805c2fd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+1028
-470
lines changed

docs/core-api/BITSWAP.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Bitswap API <!-- omit in toc -->
22

3-
- [`ipfs.bitswap.wantlist([peerId,] [options])`](#ipfsbitswapwantlistpeerid-options)
3+
- [`ipfs.bitswap.wantlist([options])`](#ipfsbitswapwantlistoptions)
44
- [Parameters](#parameters)
55
- [Options](#options)
66
- [Returns](#returns)
@@ -16,22 +16,21 @@
1616
- [Returns](#returns-2)
1717
- [Example](#example-2)
1818

19-
## `ipfs.bitswap.wantlist([peerId,] [options])`
19+
## `ipfs.bitswap.wantlist([options])`
2020

21-
> Returns the wantlist, optionally filtered by peer ID
21+
> Returns the wantlist for your node or for a connected peer
2222
2323
### Parameters
2424

25-
| Name | Type | Description |
26-
| ---- | ---- | ----------- |
27-
| peerId | [PeerId][], [CID][], `String` or `Buffer` | An optional peer ID to return the wantlist for |
25+
None
2826

2927
### Options
3028

3129
An optional object which may have the following keys:
3230

3331
| Name | Type | Default | Description |
3432
| ---- | ---- | ------- | ----------- |
33+
| peer | [PeerId][], [CID][], `String` or `Buffer` | A peer ID to return the wantlist for |
3534
| timeout | `Number` | `undefined` | A timeout in ms |
3635
| signal | [AbortSignal][] | `undefined` | Can be used to cancel any long running requests started as a result of this call |
3736

@@ -48,7 +47,7 @@ const list = await ipfs.bitswap.wantlist()
4847
console.log(list)
4948
// [ CID('QmHash') ]
5049

51-
const list2 = await ipfs.bitswap.wantlist(peerId)
50+
const list2 = await ipfs.bitswap.wantlist({ peer: peerId })
5251
console.log(list2)
5352
// [ CID('QmHash') ]
5453
```

docs/core-api/BOOTSTRAP.md

Lines changed: 101 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,53 @@
44
55
Warning: your node requires bootstrappers to join the network and find other peers.
66

7-
If you edit this list, you may find you have reduced or no connectivity. If this is the case, please reset your node's bootstrapper list with `ipfs.bootstrap.add({ default: true })`.
7+
If you edit this list, you may find you have reduced or no connectivity. If this is the case, please reset your node's bootstrapper list with `ipfs.bootstrap.reset()`.
88

9-
- [`ipfs.bootstrap.add([addr,] [options])`](#ipfsbootstrapaddaddr-options)
9+
- [`ipfs.bootstrap.add(addr, [options])`](#ipfsbootstrapaddaddr-options)
1010
- [Parameters](#parameters)
1111
- [Options](#options)
1212
- [Returns](#returns)
1313
- [Example](#example)
14-
- [`ipfs.bootstrap.list([options])`](#ipfsbootstraplistoptions)
14+
- [`ipfs.bootstrap.reset([options])`](#ipfsbootstrapresetoptions)
1515
- [Parameters](#parameters-1)
1616
- [Options](#options-1)
1717
- [Returns](#returns-1)
1818
- [Example](#example-1)
19-
- [`ipfs.bootstrap.rm([addr,] [options])`](#ipfsbootstraprmaddr-options)
19+
- [`ipfs.bootstrap.list([options])`](#ipfsbootstraplistoptions)
2020
- [Parameters](#parameters-2)
2121
- [Options](#options-2)
2222
- [Returns](#returns-2)
2323
- [Example](#example-2)
24-
25-
## `ipfs.bootstrap.add([addr,] [options])`
24+
- [`ipfs.bootstrap.rm(addr, [options])`](#ipfsbootstraprmaddr-options)
25+
- [Parameters](#parameters-3)
26+
- [Options](#options-3)
27+
- [Returns](#returns-3)
28+
- [Example](#example-3)
29+
- [`ipfs.bootstrap.clear([options])`](#ipfsbootstrapclearoptions)
30+
- [Parameters](#parameters-4)
31+
- [Options](#options-4)
32+
- [Returns](#returns-4)
33+
- [Example](#example-4)
34+
35+
## `ipfs.bootstrap.add(addr, [options])`
2636

2737
> Add a peer address to the bootstrap list
2838
2939
### Parameters
3040

3141
| Name | Type | Description |
3242
| ---- | ---- | ----------- |
33-
| addr | [MultiAddr][] | The address of a network peer. If omitted the `default` option must be passed as `true`. |
43+
| addr | [MultiAddr][] | The address of a network peer |
3444

3545
### Options
3646

3747
An optional object which may have the following keys:
3848

3949
| Name | Type | Default | Description |
4050
| ---- | ---- | ------- | ----------- |
41-
| default | `boolean` | `false` | If true, add the default peers to the list |
4251
| timeout | `Number` | `undefined` | A timeout in ms |
4352
| signal | [AbortSignal][] | `undefined` | Can be used to cancel any long running requests started as a result of this call |
4453

45-
Note: If passing the `default` option, `addr` is an optional parameter (may be `undefined`/`null`) and options may be passed as the first argument. i.e. `ipfs.bootstrap.add({ default: true })`
46-
4754
### Returns
4855

4956
| Type | Description |
@@ -71,6 +78,48 @@ console.log(res.Peers)
7178

7279
A great source of [examples][] can be found in the tests for this API.
7380

81+
## `ipfs.bootstrap.reset([options])`
82+
83+
> Reset the bootstrap list to contain only the default bootstrap nodes
84+
85+
### Parameters
86+
87+
None.
88+
89+
### Options
90+
91+
An optional object which may have the following keys:
92+
93+
| Name | Type | Default | Description |
94+
| ---- | ---- | ------- | ----------- |
95+
| timeout | `Number` | `undefined` | A timeout in ms |
96+
| signal | [AbortSignal][] | `undefined` | Can be used to cancel any long running requests started as a result of this call |
97+
98+
### Returns
99+
100+
| Type | Description |
101+
| -------- | -------- |
102+
| `Promise<Object>` | An object that contains an array with all the added addresses |
103+
104+
example of the returned object:
105+
106+
```JavaScript
107+
{
108+
Peers: [address1, address2, ...]
109+
}
110+
```
111+
112+
### Example
113+
114+
```JavaScript
115+
const res = await ipfs.bootstrap.reset()
116+
console.log(res.Peers)
117+
// Logs:
118+
// ['/ip4/104....9z']
119+
```
120+
121+
A great source of [examples][] can be found in the tests for this API.
122+
74123
## `ipfs.bootstrap.list([options])`
75124

76125
> List all peer addresses in the bootstrap list
@@ -113,27 +162,64 @@ console.log(res.Peers)
113162

114163
A great source of [examples][] can be found in the tests for this API.
115164

116-
## `ipfs.bootstrap.rm([addr,] [options])`
165+
## `ipfs.bootstrap.rm(addr, [options])`
117166

118167
> Remove a peer address from the bootstrap list
119168
120169
### Parameters
121170

122171
| Name | Type | Description |
123172
| ---- | ---- | ----------- |
124-
| addr | [MultiAddr][] | The address of a network peer. If omitted the `all` option must be passed as `true`. |
173+
| addr | [MultiAddr][] | The address of a network peer |
125174

126175
### Options
127176

128177
An optional object which may have the following keys:
129178

130179
| Name | Type | Default | Description |
131180
| ---- | ---- | ------- | ----------- |
132-
| all | `boolean` | `false` | If true, remove all peers from the bootstrap list |
133181
| timeout | `Number` | `undefined` | A timeout in ms |
134182
| signal | [AbortSignal][] | `undefined` | Can be used to cancel any long running requests started as a result of this call |
135183

136-
Note: If passing the `all` option, `addr` is an optional parameter (may be `undefined`/`null`) and options may be passed as the first argument. i.e. `ipfs.bootstrap.rm({ all: true })`
184+
### Returns
185+
186+
| Type | Description |
187+
| -------- | -------- |
188+
| `Promise<Object>` | An object that contains an array with all the removed addresses |
189+
190+
```JavaScript
191+
{
192+
Peers: [address1, address2, ...]
193+
}
194+
```
195+
196+
### Example
197+
198+
```JavaScript
199+
const res = await ipfs.bootstrap.rm('address1')
200+
console.log(res.Peers)
201+
// Logs:
202+
// [address1, ...]
203+
```
204+
205+
A great source of [examples][] can be found in the tests for this API.
206+
207+
## `ipfs.bootstrap.clear([options])`
208+
209+
> Remove all peer addresses from the bootstrap list
210+
211+
### Parameters
212+
213+
None.
214+
215+
### Options
216+
217+
An optional object which may have the following keys:
218+
219+
| Name | Type | Default | Description |
220+
| ---- | ---- | ------- | ----------- |
221+
| timeout | `Number` | `undefined` | A timeout in ms |
222+
| signal | [AbortSignal][] | `undefined` | Can be used to cancel any long running requests started as a result of this call |
137223

138224
### Returns
139225

@@ -150,7 +236,7 @@ Note: If passing the `all` option, `addr` is an optional parameter (may be `unde
150236
### Example
151237

152238
```JavaScript
153-
const res = await ipfs.bootstrap.rm(null, { all: true })
239+
const res = await ipfs.bootstrap.clear()
154240
console.log(res.Peers)
155241
// Logs:
156242
// [address1, address2, ...]

docs/core-api/DAG.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
- [Options](#options)
88
- [Returns](#returns)
99
- [Example](#example)
10-
- [`ipfs.dag.get(cid, [path], [options])`](#ipfsdaggetcid-path-options)
10+
- [`ipfs.dag.get(cid, [options])`](#ipfsdaggetcid-path-options)
1111
- [Parameters](#parameters-1)
1212
- [Options](#options-1)
1313
- [Returns](#returns-1)
1414
- [Example](#example-1)
15-
- [`ipfs.dag.tree(cid, [path,] [options])`](#ipfsdagtreecid-path-options)
15+
- [`ipfs.dag.tree(cid, [options])`](#ipfsdagtreecid-path-options)
1616
- [Parameters](#parameters-2)
1717
- [Options](#options-2)
1818
- [Returns](#returns-2)
@@ -65,23 +65,23 @@ console.log(cid.toString())
6565

6666
A great source of [examples][] can be found in the tests for this API.
6767

68-
## `ipfs.dag.get(cid, [path], [options])`
68+
## `ipfs.dag.get(cid, [options])`
6969

7070
> Retrieve an IPLD format node
7171
7272
### Parameters
7373

7474
| Name | Type | Description |
7575
| ---- | ---- | ----------- |
76-
| cid | [CID][] | A DAG node that follows one of the supported IPLD formats |
77-
| path | `String` | An optional path within the DAG to resolve |
76+
| cid | [CID][] | A CID that resolves to a node to get |
7877

7978
### Options
8079

8180
An optional object which may have the following keys:
8281

8382
| Name | Type | Default | Description |
8483
| ---- | ---- | ------- | ----------- |
84+
| path | `String` | An optional path within the DAG to resolve |
8585
| localResolve | `boolean` | `false` | If set to true, it will avoid resolving through different objects |
8686
| timeout | `Number` | `undefined` | A timeout in ms |
8787
| signal | [AbortSignal][] | `undefined` | Can be used to cancel any long running requests started as a result of this call |
@@ -114,34 +114,34 @@ const cid = await ipfs.dag.put(obj, { format: 'dag-cbor', hashAlg: 'sha2-256' })
114114
console.log(cid.toString())
115115
// zdpuAmtur968yprkhG9N5Zxn6MFVoqAWBbhUAkNLJs2UtkTq5
116116

117-
async function getAndLog(cidPath) {
118-
const result = await ipfs.dag.get(cidPath)
117+
async function getAndLog(cid, path) {
118+
const result = await ipfs.dag.get(cid, { path })
119119
console.log(result.value)
120120
}
121121

122-
await getAndLog('zdpuAmtur968yprkhG9N5Zxn6MFVoqAWBbhUAkNLJs2UtkTq5/a')
122+
await getAndLog(cid, '/a')
123123
// Logs:
124124
// 1
125125

126-
await getAndLog('zdpuAmtur968yprkhG9N5Zxn6MFVoqAWBbhUAkNLJs2UtkTq5/b')
126+
await getAndLog(cid, '/b')
127127
// Logs:
128128
// [1, 2, 3]
129129

130-
await getAndLog('zdpuAmtur968yprkhG9N5Zxn6MFVoqAWBbhUAkNLJs2UtkTq5/c')
130+
await getAndLog(cid, '/c')
131131
// Logs:
132132
// {
133133
// ca: [5, 6, 7],
134134
// cb: 'foo'
135135
// }
136136

137-
await getAndLog('zdpuAmtur968yprkhG9N5Zxn6MFVoqAWBbhUAkNLJs2UtkTq5/c/ca/1')
137+
await getAndLog(cid, '/c/ca/1')
138138
// Logs:
139139
// 6
140140
```
141141

142142
A great source of [examples][] can be found in the tests for this API.
143143

144-
## `ipfs.dag.tree(cid, [path,] [options])`
144+
## `ipfs.dag.tree(cid, [options])`
145145

146146
> Enumerate all the entries in a graph
147147
@@ -150,14 +150,14 @@ A great source of [examples][] can be found in the tests for this API.
150150
| Name | Type | Description |
151151
| ---- | ---- | ----------- |
152152
| cid | [CID][] | A DAG node that follows one of the supported IPLD formats |
153-
| path | `String` | An optional path within the DAG to resolve |
154153

155154
### Options
156155

157156
An optional object which may have the following keys:
158157

159158
| Name | Type | Default | Description |
160159
| ---- | ---- | ------- | ----------- |
160+
| path | `String` | An optional path within the DAG to resolve |
161161
| recursive | `boolean` | `false` | If set to true, it will follow the links and continuously run tree on them, returning all the paths in the graph |
162162
| timeout | `Number` | `undefined` | A timeout in ms |
163163
| signal | [AbortSignal][] | `undefined` | Can be used to cancel any long running requests started as a result of this call |

docs/core-api/FILES.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ _Explore the Mutable File System through interactive coding challenges in our [P
7272
- [Options](#options-12)
7373
- [Returns](#returns-11)
7474
- [Example](#example-8)
75-
- [`ipfs.files.flush([path,] [options])`](#ipfsfilesflushpath-options)
75+
- [`ipfs.files.flush(path, [options])`](#ipfsfilesflushpath-options)
7676
- [Parameters](#parameters-13)
7777
- [Options](#options-13)
7878
- [Returns](#returns-12)
79-
- [`ipfs.files.ls([path], [options])`](#ipfsfileslspath-options)
79+
- [`ipfs.files.ls(path, [options])`](#ipfsfileslspath-options)
8080
- [Parameters](#parameters-14)
8181
- [Options](#options-14)
8282
- [Returns](#returns-13)
@@ -869,15 +869,15 @@ If `from` is an IPFS path and the content does not exist in your node's repo, on
869869

870870
All values of `from` will be removed after the operation is complete unless they are an IPFS path.
871871

872-
### `ipfs.files.flush([path,] [options])`
872+
### `ipfs.files.flush(path, [options])`
873873

874874
> Flush a given path's data to the disk
875875
876876
#### Parameters
877877

878878
| Name | Type | Description |
879879
| ---- | ---- | ----------- |
880-
| path | `String` | Optional [MFS path][] to flush, defaults to `'/'` |
880+
| path | `String` | The [MFS path][] to flush |
881881

882882
#### Options
883883

@@ -900,15 +900,15 @@ An optional object which may have the following keys:
900900
const cid = await ipfs.files.flush('/')
901901
```
902902

903-
### `ipfs.files.ls([path], [options])`
903+
### `ipfs.files.ls(path, [options])`
904904

905905
> List directories in the local mutable namespace
906906
907907
#### Parameters
908908

909909
| Name | Type | Description |
910910
| ---- | ---- | ----------- |
911-
| path | `String` | Optional [MFS path][] to list, defaults to `'/'` |
911+
| path | `String` | The [MFS path][] to list |
912912

913913
#### Options
914914

0 commit comments

Comments
 (0)