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

feat: store pins in datastore instead of a DAG #2771

Merged
merged 47 commits into from
Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
582be49
feat: store pins in datastore instead of a DAG
achingbrain Mar 3, 2020
b65c94b
chore: revert update of ipfs-repo in mfs dev deps
achingbrain Mar 4, 2020
a8e1a06
chore: fix interop tests
achingbrain Mar 5, 2020
6ff3a10
chore: dedupe pinning tests
achingbrain Mar 5, 2020
e9ab233
chore: fix up http tests
achingbrain Mar 5, 2020
68345b2
feat: new api
achingbrain Mar 6, 2020
1d304db
fix: handle invalid paths in http routes
achingbrain Mar 6, 2020
8aeb819
chore: fix up tests
achingbrain Mar 6, 2020
ab70c18
chore: responding to pr comments
achingbrain Mar 10, 2020
1185cb9
chore: responding to pr comments
achingbrain Mar 10, 2020
d213521
Merge remote-tracking branch 'origin/master' into refactor/store-pins…
achingbrain Jun 30, 2020
591b7f2
chore: fix tests
achingbrain Jun 30, 2020
b534a61
Merge remote-tracking branch 'origin/master' into refactor/store-pins…
achingbrain Jul 2, 2020
96399fd
chore: fix tests
achingbrain Jul 3, 2020
af90886
Merge remote-tracking branch 'origin/master' into refactor/store-pins…
achingbrain Jul 21, 2020
d89a330
chore: split pin.add and pin.rm into pin.addAll and pin.rmAll
achingbrain Jul 21, 2020
b8a2640
chore: fix tests
achingbrain Jul 21, 2020
00e3671
chore: fix more tests
achingbrain Jul 21, 2020
c98b50c
chore: make depth infinity for recursive pins
achingbrain Jul 21, 2020
d4f3796
chore: keep multihash prefix for key
achingbrain Jul 21, 2020
692664d
chore: correct multihash
achingbrain Jul 21, 2020
2864906
Merge remote-tracking branch 'origin/master' into refactor/store-pins…
achingbrain Aug 5, 2020
94204f8
chore: updating deps
achingbrain Aug 10, 2020
ea82cf9
chore: update deps
achingbrain Aug 11, 2020
8a1d959
Merge remote-tracking branch 'origin/master' into refactor/store-pins…
achingbrain Aug 12, 2020
e8c2543
chore: replace node buffers with uint8arrays
achingbrain Aug 14, 2020
0d3a1a1
chore: add missing dep
achingbrain Aug 15, 2020
aa591c7
chore: add missing deps
achingbrain Aug 15, 2020
86bcd70
chore: fix up normalisation tests
achingbrain Aug 15, 2020
cdd80ef
chore: fix typo
achingbrain Aug 15, 2020
bfc74d6
chore: fix failing test
achingbrain Aug 15, 2020
173905f
chore: fix pubsub tests
achingbrain Aug 15, 2020
d072a40
chore: remove unused dep
achingbrain Aug 15, 2020
5879a49
chore: fix failing test
achingbrain Aug 15, 2020
caf8ba5
chore: use base64pad and print migration progress
achingbrain Aug 15, 2020
50ad0f2
chore: fix object data
achingbrain Aug 15, 2020
903e2cf
chore: fix base string
achingbrain Aug 15, 2020
ba5c29b
chore: fix failing tests
achingbrain Aug 16, 2020
5ad0906
chore: fix up examples
achingbrain Aug 16, 2020
a73ec06
chore: fix circuit relay test
achingbrain Aug 16, 2020
a069f4c
chore: ignore invalid messages
achingbrain Aug 17, 2020
b2a73f7
chore: update ipfs-utils version
achingbrain Aug 24, 2020
27d1866
chore: update dep versions
achingbrain Aug 24, 2020
ce097df
Merge remote-tracking branch 'origin/master' into refactor/store-pins…
achingbrain Aug 24, 2020
6efcc3a
chore: stringify ipns record properly
achingbrain Aug 24, 2020
2cff1c8
chore: update dep version
achingbrain Aug 24, 2020
8914194
Merge remote-tracking branch 'origin/master' into refactor/store-pins…
achingbrain Aug 24, 2020
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
120 changes: 102 additions & 18 deletions docs/core-api/PIN.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,40 @@
# Pin API <!-- omit in toc -->

- [`ipfs.pin.add(cid, [options])`](#ipfspinaddcid-options)
- [`ipfs.pin.add(ipfsPath, [options])`](#ipfspinaddipfspath-options)
- [Parameters](#parameters)
- [Options](#options)
- [Returns](#returns)
- [Example](#example)
- [`ipfs.pin.ls([options])`](#ipfspinlsoptions)
- [`ipfs.pin.addAll(source, [options])`](#ipfspinaddallsource-options)
- [Parameters](#parameters-1)
- [Options](#options-1)
- [Returns](#returns-1)
- [Example](#example-1)
- [`ipfs.pin.rm(cid, [options])`](#ipfspinrmcid-options)
- [`ipfs.pin.ls([options])`](#ipfspinlsoptions)
- [Parameters](#parameters-2)
- [Options](#options-2)
- [Returns](#returns-2)
- [Example](#example-2)

## `ipfs.pin.add(cid, [options])`
- [`ipfs.pin.rm(ipfsPath, [options])`](#ipfspinrmipfspath-options)
- [Parameters](#parameters-3)
- [Options](#options-3)
- [Returns](#returns-3)
- [Example](#example-3)
- [`ipfs.pin.rmAll(source, [options])`](#ipfspinrmallsource-options)
- [Parameters](#parameters-4)
- [Options](#options-4)
- [Returns](#returns-4)
- [Example](#example-4)

## `ipfs.pin.add(ipfsPath, [options])`

> Adds an IPFS object to the pinset and also stores it to the IPFS repo. pinset is the set of hashes currently pinned (not gc'able)

### Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| cid | [CID][] | Pin this CID in your repo |
| source | [CID][] or String | A CID or IPFS Path to pin in your repo |

### Options

Expand All @@ -40,9 +50,45 @@ An optional object which may have the following keys:

| Type | Description |
| -------- | -------- |
| `Promise<{ cid: CID }>` | An array of objects that represent the files that were pinned |
| [CID[] | The CIDs that was pinned |

### Example

```JavaScript
const cid of ipfs.pin.add(new CID('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u'))
console.log(cid)
// Logs:
// CID('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u')
```

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

## `ipfs.pin.addAll(source, [options])`

> Adds multiple IPFS objects to the pinset and also stores it to the IPFS repo. pinset is the set of hashes currently pinned (not gc'able)

### Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| source | `AsyncIterable<{ cid: CID, path: String, recursive: Boolean, comments: String }>` | One or more CIDs or IPFS Paths to pin in your repo |

### Options

An optional object which may have the following keys:

| Name | Type | Default | Description |
| ---- | ---- | ------- | ----------- |
| timeout | `Number` | `undefined` | A timeout in ms |
| signal | [AbortSignal][] | `undefined` | Can be used to cancel any long running requests started as a result of this call |

### Returns

| Type | Description |
| -------- | -------- |
| `AsyncIterable<CID>` | An async iterable that yields the CIDs that were pinned |

an array of objects is returned, each of the form:
Each yielded object has the form:

```JavaScript
{
Expand All @@ -53,10 +99,11 @@ an array of objects is returned, each of the form:
### Example

```JavaScript
const pinset = await ipfs.pin.add('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u')
console.log(pinset)
for await (const cid of ipfs.pin.addAll(new CID('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u'))) {
console.log(cid)
}
// Logs:
// [ { cid: CID('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u') } ]
// CID('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u')
```

A great source of [examples][] can be found in the tests for this API.
Expand Down Expand Up @@ -111,15 +158,15 @@ for await (const { cid, type } of ipfs.pin.ls({

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

## `ipfs.pin.rm(cid, [options])`
## `ipfs.pin.rm(ipfsPath, [options])`

> Unpin this block from your repo

### Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| cid | [CID][] | Unpin this CID |
| ipfsPath | [CID][] of String | Unpin this CID or IPFS Path |

### Options

Expand All @@ -135,15 +182,52 @@ An optional object which may have the following keys:

| Type | Description |
| -------- | -------- |
| `Promise<{ cid: CID }>` | An array of unpinned objects |
| [CID][] | The CIDs that was unpinned |

### Example

```JavaScript
const pinset = await ipfs.pin.rm('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u')
console.log(pinset)
// prints the hashes that were unpinned
// [ { cid: CID('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u') } ]
const cid of ipfs.pin.rm(new CID('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u'))
console.log(cid)
// prints the CID that was unpinned
// CID('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u')
```

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

## `ipfs.pin.rmAll(source, [options])`

> Unpin one or more blocks from your repo

### Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| source | [CID][], String or `AsyncIterable<{ cid: CID, path: String, recursive: Boolean }>` | Unpin this CID |

### Options

An optional object which may have the following keys:

| Name | Type | Default | Description |
| ---- | ---- | ------- | ----------- |
| timeout | `Number` | `undefined` | A timeout in ms |
| signal | [AbortSignal][] | `undefined` | Can be used to cancel any long running requests started as a result of this call |

### Returns

| Type | Description |
| -------- | -------- |
| `AsyncIterable<CID>` | An async iterable that yields the CIDs that were unpinned |

### Example

```JavaScript
for await (const cid of ipfs.pin.rmAll(new CID('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u'))) {
console.log(cid)
}
// prints the CIDs that were unpinned
// CID('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u')
```

A great source of [examples][] can be found in the tests for this API.
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-ipfs-repo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"dependencies": {
"datastore-fs": "^1.1.0",
"ipfs": "^0.48.0",
"ipfs-repo": "^4.0.0",
"ipfs-repo": "^5.0.0",
"it-all": "^1.0.1"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions packages/interface-ipfs-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"it-concat": "^1.0.0",
"it-drain": "^1.0.1",
"it-last": "^1.0.1",
"it-map": "^1.0.2",
"it-pushable": "^1.3.1",
"multiaddr": "^7.4.3",
"multibase": "^1.0.1",
Expand Down
10 changes: 5 additions & 5 deletions packages/interface-ipfs-core/src/block/rm.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { Buffer } = require('buffer')
const { getDescribe, getIt, expect } = require('../utils/mocha')
const { nanoid } = require('nanoid')
const all = require('it-all')
const last = require('it-last')
const drain = require('it-drain')
const CID = require('cids')
const testTimeout = require('../utils/test-timeout')
Expand Down Expand Up @@ -151,13 +152,12 @@ module.exports = (common, options) => {
format: 'raw',
hashAlg: 'sha2-256'
})
await ipfs.pin.add(cid.toString())
await ipfs.pin.add(cid)

const result = await all(ipfs.block.rm(cid))
const result = await last(ipfs.block.rm(cid))

expect(result).to.be.an('array').and.to.have.lengthOf(1)
expect(result[0]).to.have.property('error')
expect(result[0].error.message).to.include('pinned')
expect(result).to.have.property('error').that.is.an('Error')
.with.property('message').that.includes('pinned')
})
})
}
128 changes: 128 additions & 0 deletions packages/interface-ipfs-core/src/pin/add-all.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/* eslint-env mocha */
'use strict'

const { fixtures, clearPins } = require('./utils')
const { getDescribe, getIt, expect } = require('../utils/mocha')
const all = require('it-all')
const drain = require('it-drain')
const testTimeout = require('../utils/test-timeout')
const CID = require('cids')

/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
/**
* @param {Factory} common
* @param {Object} options
*/
module.exports = (common, options) => {
const describe = getDescribe(options)
const it = getIt(options)

describe('.pin.addAll', function () {
this.timeout(50 * 1000)

let ipfs
before(async () => {
ipfs = (await common.spawn()).api

await drain(
ipfs.addAll(
fixtures.files.map(file => ({ content: file.data })), {
pin: false
}
)
)

await drain(
ipfs.addAll(fixtures.directory.files.map(
file => ({
path: file.path,
content: file.data
})
), {
pin: false
})
)
})

after(() => common.clean())

beforeEach(() => {
return clearPins(ipfs)
})

async function testAddPinInput (source) {
const pinset = await all(ipfs.pin.addAll(source))

expect(pinset).to.have.deep.members([
fixtures.files[0].cid,
fixtures.files[1].cid
])
}

it('should add an array of CIDs', () => {
return testAddPinInput([
fixtures.files[0].cid,
fixtures.files[1].cid
])
})

it('should add a generator of CIDs', () => {
return testAddPinInput(function * () {
yield fixtures.files[0].cid
yield fixtures.files[1].cid
}())
})

it('should add an async generator of CIDs', () => {
return testAddPinInput(async function * () { // eslint-disable-line require-await
yield fixtures.files[0].cid
yield fixtures.files[1].cid
}())
})

it('should add an array of pins with options', () => {
return testAddPinInput([
{
cid: fixtures.files[0].cid,
recursive: false
},
{
cid: fixtures.files[1].cid,
recursive: true
}
])
})

it('should add a generator of pins with options', () => {
return testAddPinInput(function * () {
yield {
cid: fixtures.files[0].cid,
recursive: false
}
yield {
cid: fixtures.files[1].cid,
recursive: true
}
}())
})

it('should add an async generator of pins with options', () => {
return testAddPinInput(async function * () { // eslint-disable-line require-await
yield {
cid: fixtures.files[0].cid,
recursive: false
}
yield {
cid: fixtures.files[1].cid,
recursive: true
}
}())
})

it('should respect timeout option when pinning a block', () => {
return testTimeout(() => ipfs.pin.addAll([new CID('Qmd7qZS4T7xXtsNFdRoK1trfMs5zU94EpokQ9WFtxdPxsZ')], {
timeout: 1
}))
})
})
}
Loading