This repository was archived by the owner on Feb 12, 2024. It is now read-only.
Commit 64b7fe4
authored
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 Buffers1 parent 84cfa55 commit 64b7fe4
File tree
318 files changed
+2811
-2810
lines changed- docs
- core-api
- examples
- browser-exchange-files
- public
- browser-parceljs/public
- browser-webpack/src/components
- circuit-relaying
- src
- custom-ipfs-repo
- custom-libp2p
- http-client-browser-pubsub
- http-client-name-api
- ipfs-101
- test-ipfs-example
- traverse-ipld-graphs
- packages
- interface-ipfs-core
- src
- block
- config
- dag
- dht
- files
- miscellaneous
- name-pubsub
- name
- object
- patch
- pin
- pubsub
- repo
- utils
- ipfs-core-utils
- src
- files/normalise-input
- pins
- test
- files
- pins
- utils
- ipfs-http-client
- src
- block
- config
- dag
- dht
- files
- object
- patch
- pin
- pubsub
- refs
- test
- node
- ipfs-message-port-client
- src
- test
- ipfs-message-port-protocol
- src
- test
- ipfs-message-port-server
- src
- test
- ipfs
- src
- cli
- commands
- block
- dag
- object
- pin
- pubsub
- core
- components
- files
- utils
- object
- patch
- pin
- repo
- ipns
- routing
- runtime
- http
- api/resources
- gateway/resources
- utils
- test
- cli
- files
- core
- gateway
- http-api/inject
- mfs
- utils
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
318 files changed
+2811
-2810
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
| 69 | + | |
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
| 174 | + | |
174 | 175 | | |
175 | 176 | | |
176 | | - | |
| 177 | + | |
177 | 178 | | |
178 | 179 | | |
179 | 180 | | |
| |||
185 | 186 | | |
186 | 187 | | |
187 | 188 | | |
| 189 | + | |
188 | 190 | | |
189 | 191 | | |
190 | | - | |
| 192 | + | |
191 | 193 | | |
192 | 194 | | |
193 | 195 | | |
| |||
201 | 203 | | |
202 | 204 | | |
203 | 205 | | |
| 206 | + | |
204 | 207 | | |
205 | 208 | | |
206 | | - | |
| 209 | + | |
207 | 210 | | |
208 | 211 | | |
209 | 212 | | |
| |||
216 | 219 | | |
217 | 220 | | |
218 | 221 | | |
| 222 | + | |
219 | 223 | | |
220 | 224 | | |
221 | | - | |
| 225 | + | |
222 | 226 | | |
223 | 227 | | |
224 | 228 | | |
| |||
238 | 242 | | |
239 | 243 | | |
240 | 244 | | |
| 245 | + | |
241 | 246 | | |
242 | | - | |
| 247 | + | |
243 | 248 | | |
244 | 249 | | |
245 | | - | |
| 250 | + | |
246 | 251 | | |
247 | 252 | | |
248 | 253 | | |
| |||
251 | 256 | | |
252 | 257 | | |
253 | 258 | | |
254 | | - | |
| 259 | + | |
255 | 260 | | |
256 | 261 | | |
257 | 262 | | |
| |||
260 | 265 | | |
261 | 266 | | |
262 | 267 | | |
| 268 | + | |
263 | 269 | | |
264 | | - | |
| 270 | + | |
265 | 271 | | |
266 | 272 | | |
267 | | - | |
| 273 | + | |
268 | 274 | | |
269 | 275 | | |
270 | 276 | | |
| |||
273 | 279 | | |
274 | 280 | | |
275 | 281 | | |
276 | | - | |
| 282 | + | |
277 | 283 | | |
278 | 284 | | |
279 | 285 | | |
280 | 286 | | |
281 | 287 | | |
282 | 288 | | |
| 289 | + | |
283 | 290 | | |
284 | | - | |
| 291 | + | |
285 | 292 | | |
286 | 293 | | |
287 | 294 | | |
| |||
292 | 299 | | |
293 | 300 | | |
294 | 301 | | |
| 302 | + | |
295 | 303 | | |
296 | | - | |
| 304 | + | |
297 | 305 | | |
298 | 306 | | |
299 | | - | |
| 307 | + | |
300 | 308 | | |
301 | 309 | | |
302 | 310 | | |
| |||
305 | 313 | | |
306 | 314 | | |
307 | 315 | | |
308 | | - | |
| 316 | + | |
309 | 317 | | |
310 | 318 | | |
311 | 319 | | |
| |||
315 | 323 | | |
316 | 324 | | |
317 | 325 | | |
| 326 | + | |
318 | 327 | | |
319 | | - | |
| 328 | + | |
320 | 329 | | |
321 | 330 | | |
322 | | - | |
| 331 | + | |
323 | 332 | | |
324 | 333 | | |
325 | 334 | | |
| |||
328 | 337 | | |
329 | 338 | | |
330 | 339 | | |
331 | | - | |
| 340 | + | |
332 | 341 | | |
333 | 342 | | |
334 | 343 | | |
| |||
472 | 481 | | |
473 | 482 | | |
474 | 483 | | |
| 484 | + | |
| 485 | + | |
475 | 486 | | |
476 | 487 | | |
477 | 488 | | |
478 | | - | |
| 489 | + | |
479 | 490 | | |
480 | 491 | | |
481 | 492 | | |
| |||
486 | 497 | | |
487 | 498 | | |
488 | 499 | | |
| 500 | + | |
| 501 | + | |
489 | 502 | | |
490 | | - | |
| 503 | + | |
491 | 504 | | |
492 | 505 | | |
493 | 506 | | |
| |||
500 | 513 | | |
501 | 514 | | |
502 | 515 | | |
| 516 | + | |
| 517 | + | |
503 | 518 | | |
504 | 519 | | |
505 | 520 | | |
506 | | - | |
| 521 | + | |
507 | 522 | | |
508 | 523 | | |
509 | 524 | | |
| |||
515 | 530 | | |
516 | 531 | | |
517 | 532 | | |
| 533 | + | |
518 | 534 | | |
519 | 535 | | |
520 | 536 | | |
521 | 537 | | |
522 | | - | |
| 538 | + | |
523 | 539 | | |
524 | 540 | | |
525 | 541 | | |
| |||
538 | 554 | | |
539 | 555 | | |
540 | 556 | | |
| 557 | + | |
| 558 | + | |
541 | 559 | | |
542 | 560 | | |
543 | 561 | | |
544 | | - | |
| 562 | + | |
545 | 563 | | |
546 | 564 | | |
547 | 565 | | |
| |||
551 | 569 | | |
552 | 570 | | |
553 | 571 | | |
| 572 | + | |
554 | 573 | | |
555 | 574 | | |
556 | 575 | | |
557 | 576 | | |
558 | 577 | | |
559 | 578 | | |
560 | | - | |
| 579 | + | |
561 | 580 | | |
562 | 581 | | |
563 | 582 | | |
| |||
640 | 659 | | |
641 | 660 | | |
642 | 661 | | |
643 | | - | |
644 | | - | |
| 662 | + | |
| 663 | + | |
645 | 664 | | |
646 | 665 | | |
647 | 666 | | |
| |||
654 | 673 | | |
655 | 674 | | |
656 | 675 | | |
657 | | - | |
658 | | - | |
| 676 | + | |
| 677 | + | |
659 | 678 | | |
660 | 679 | | |
661 | 680 | | |
| |||
669 | 688 | | |
670 | 689 | | |
671 | 690 | | |
672 | | - | |
673 | | - | |
| 691 | + | |
| 692 | + | |
674 | 693 | | |
675 | 694 | | |
676 | 695 | | |
| |||
682 | 701 | | |
683 | 702 | | |
684 | 703 | | |
685 | | - | |
686 | | - | |
| 704 | + | |
| 705 | + | |
687 | 706 | | |
688 | 707 | | |
689 | 708 | | |
| |||
695 | 714 | | |
696 | 715 | | |
697 | 716 | | |
698 | | - | |
699 | | - | |
| 717 | + | |
| 718 | + | |
700 | 719 | | |
701 | 720 | | |
702 | 721 | | |
| |||
711 | 730 | | |
712 | 731 | | |
713 | 732 | | |
714 | | - | |
715 | | - | |
| 733 | + | |
| 734 | + | |
716 | 735 | | |
717 | 736 | | |
718 | 737 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
95 | | - | |
| 95 | + | |
| 96 | + | |
96 | 97 | | |
97 | 98 | | |
98 | 99 | | |
99 | | - | |
| 100 | + | |
100 | 101 | | |
101 | 102 | | |
102 | 103 | | |
| |||
105 | 106 | | |
106 | 107 | | |
107 | 108 | | |
108 | | - | |
| 109 | + | |
109 | 110 | | |
110 | 111 | | |
111 | 112 | | |
112 | 113 | | |
113 | | - | |
| 114 | + | |
114 | 115 | | |
115 | 116 | | |
116 | 117 | | |
| |||
0 commit comments