You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 12, 2024. It is now read-only.
feat: store pins in datastore instead of a DAG (#2771)
Adds a `.pins` datastore to `ipfs-repo` and uses that to store pins as cbor binary keyed by multihash.
### Format
As stored in the datastore, each pin has several fields:
```javascript
{
codec: // optional Number, the codec from the CID that this multihash was pinned with, if omitted, treated as 'dag-pb'
version: // optional Number, the version number from the CID that this multihash was pinned with, if omitted, treated as v0
depth: // Number Infinity = recursive pin, 0 = direct, 1+ = pinned to a depth
comments: // optional String user-friendly description of the pin
metadata: // optional Object, user-defined data for the pin
}
```
Notes:
`.codec` and `.version` are stored so we can recreate the original CID when listing pins.
### Metadata
The intention is for us to be able to add extra fields that have technical meaning to the root of the object, and the user can store application-specific data in the `metadata` field.
### CLI
```console
$ ipfs pin add bafyfoo --metadata key1=value1,key2=value2
$ ipfs pin add bafyfoo --metadata-format=json --metadata '{"key1":"value1","key2":"value2"}'
$ ipfs pin list
bafyfoo
$ ipfs pin list -l
CID Name Type Metadata
bafyfoo My pin Recursive {"key1":"value1","key2":"value2"}
$ ipfs pin metadata Qmfoo --format=json
{"key1":"value1","key2":"value2"}
```
### HTTP API
* '/api/v0/pin/add' route adds new `metadata` argument, accepts a json string
* '/api/v0/pin/metadata' returns metadata as json
### Core API
* `ipfs.pin.addAll` accepts and returns an async iterator
* `ipfs.pin.rmAll` accepts and returns an async iterator
```javascript
// pass a cid or IPFS Path with options
const { cid } = await ipfs.pin.add(new CID('/ipfs/Qmfoo'), {
recursive: false,
metadata: {
key: 'value
},
timeout: 2000
}))
// pass an iterable of CIDs
const [{ cid: cid1 }, { cid: cid2 }] = await all(ipfs.pin.addAll([
new CID('/ipfs/Qmfoo'),
new CID('/ipfs/Qmbar')
], { timeout: '2s' }))
// pass an iterable of objects with options
const [{ cid: cid1 }, { cid: cid2 }] = await all(ipfs.pin.addAll([
{ cid: new CID('/ipfs/Qmfoo'), recursive: true, comments: 'A recursive pin' },
{ cid: new CID('/ipfs/Qmbar'), recursive: false, comments: 'A direct pin' }
], { timeout: '2s' }))
```
* ipfs.pin.rmAll accepts and returns an async generator (other input types are available)
```javascript
// pass an IPFS Path or CID
const { cid } = await ipfs.rm(new CID('/ipfs/Qmfoo/file.txt'))
// pass options
const { cid } = await all(ipfs.rm(new CID('/ipfs/Qmfoo'), { recursive: true }))
// pass an iterable of CIDs or objects with options
const [{ cid }] = await all(ipfs.rmAll([{ cid: new CID('/ipfs/Qmfoo'), recursive: true }]))
```
Bonus: Lets us pipe the output of one command into another:
```javascript
await pipe(
ipfs.pin.ls({ type: 'recursive' }),
(source) => ipfs.pin.rmAll(source)
)
// or
await all(ipfs.pin.rmAll(ipfs.pin.ls({ type: 'recursive'})))
```
BREAKING CHANGES:
* pins are now stored in a datastore, a repo migration will occur on startup
* All deps of this module now use Uint8Arrays in place of node Buffers
0 commit comments