Skip to content

Commit 7d335bf

Browse files
committed
Merge branch 'main' into fix/locking
* main: chore(release): 1.0.4 [skip ci] docs: add usage example (#97) chore: bump aegir from 38.1.8 to 39.0.4 (#111) chore: Update CODEOWNERS [skip ci] docs: add system diagram (#93) deps(dev): bump libp2p from 0.43.4 to 0.44.0 (#96)
2 parents ddd740f + a4477ca commit 7d335bf

29 files changed

Lines changed: 267 additions & 112 deletions

README.md

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,118 @@
1111
[![codecov](https://img.shields.io/codecov/c/github/ipfs/helia.svg?style=flat-square)](https://codecov.io/gh/ipfs/helia)
1212
[![CI](https://img.shields.io/github/actions/workflow/status/ipfs/helia/main.yml?branch=main\&style=flat-square)](https://github.com/ipfs/helia/actions/workflows/main.yml?query=branch%3Amain)
1313

14+
## 🌟 Usage
15+
16+
A quick overview of how to get different types of data in and out of your Helia
17+
node.
18+
19+
### 🪢 Strings
20+
21+
You can use the [@helia/strings](https://www.npmjs.com/package/@helia/strings)
22+
module to easily add and get strings from your Helia node:
23+
24+
```js
25+
import { createHelia } from 'helia'
26+
import { strings } from '@helia/strings'
27+
28+
const helia = await createHelia()
29+
const s = strings(helia)
30+
31+
const myImmutableAddress = await s.add('hello world')
32+
33+
console.log(await s.get(myImmutableAddress))
34+
// hello world
35+
```
36+
37+
### 🌃 JSON
38+
39+
The [@helia/json](https://www.npmjs.com/package/@helia/json) module lets you add
40+
or get plain JS objects:
41+
42+
```js
43+
import { createHelia } from 'helia'
44+
import { json } from '@helia/json'
45+
46+
const helia = await createHelia()
47+
const j = json(helia)
48+
49+
const myImmutableAddress = await j.add({ hello: 'world' })
50+
51+
console.log(await j.get(myImmutableAddress))
52+
// { hello: 'world' }
53+
```
54+
55+
### 🌠 DAG-JSON
56+
57+
The [@helia/dag-json](https://www.npmjs.com/package/@helia/dag-json) allows you
58+
to store references to linked objects as
59+
[CIDs](https://docs.ipfs.tech/concepts/content-addressing):
60+
61+
```js
62+
import { createHelia } from 'helia'
63+
import { dagJson } from '@helia/dag-json'
64+
65+
const helia = await createHelia()
66+
const d = dagJson(helia)
67+
68+
const object1 = { hello: 'world' }
69+
const myImmutableAddress1 = await d.add(object1)
70+
71+
const object2 = { link: myImmutableAddress1 }
72+
const myImmutableAddress2 = await d.add(object2)
73+
74+
const retrievedObject = await d.get(myImmutableAddress2)
75+
console.log(retrievedObject)
76+
// { link: CID(baguqeerasor...) }
77+
78+
console.log(await d.get(retrievedObject.link))
79+
// { hello: 'world' }
80+
```
81+
82+
### 🌌 DAG-CBOR
83+
84+
[@helia/dag-cbor](https://www.npmjs.com/package/@helia/dag-json) works in a
85+
similar way to `@helia/dag-json` but stores objects using
86+
[Concise Binary Object Representation](https://cbor.io/):
87+
88+
```js
89+
import { createHelia } from 'helia'
90+
import { dagCbor } from '@helia/dag-cbor'
91+
92+
const helia = await createHelia()
93+
const d = dagJson(helia)
94+
95+
const object1 = { hello: 'world' }
96+
const myImmutableAddress1 = await d.add(object1)
97+
98+
const object2 = { link: myImmutableAddress1 }
99+
const myImmutableAddress2 = await d.add(object2)
100+
101+
const retrievedObject = await d.get(myImmutableAddress2)
102+
console.log(retrievedObject)
103+
// { link: CID(baguqeerasor...) }
104+
105+
console.log(await d.get(retrievedObject.link))
106+
// { hello: 'world' }
107+
```
108+
109+
### 🐾 Next steps
110+
111+
Check out the [helia-examples](https://github.com/ipfs-examples/helia-examples)
112+
repo for how to do mostly anything with your Helia node.
113+
14114
## Table of contents <!-- omit in toc -->
15115

116+
- [🌟 Usage](#-usage)
117+
- [🪢 Strings](#-strings)
118+
- [🌃 JSON](#-json)
119+
- [🌠 DAG-JSON](#-dag-json)
120+
- [🌌 DAG-CBOR](#-dag-cbor)
121+
- [🐾 Next steps](#-next-steps)
16122
- [🥅 Purpose and goals](#-purpose-and-goals)
17123
- [🏃‍♀️ Getting Started](#️-getting-started)
18124
- [📒 API Docs](#-api-docs)
125+
- [📐 System diagram](#-system-diagram)
19126
- [🏭 Code Structure](#-code-structure)
20127
- [📣 Project status](#-project-status)
21128
- [🛣️ Roadmap](#️-roadmap)
@@ -39,11 +146,43 @@ Check out the [Helia examples repo](https://github.com/ipfs-examples/helia-examp
39146

40147
- https://ipfs.github.io/helia
41148

149+
## 📐 System diagram
150+
151+
```mermaid
152+
graph TD;
153+
User["User or application"]-->IPNS["@helia/ipns"];
154+
User-->UnixFS["@helia/unixfs"];
155+
User-->Libp2p;
156+
User-->Datastore;
157+
User-->Blockstore;
158+
UnixFS-->Blockstore;
159+
IPNS-->Datastore;
160+
subgraph helia [Helia]
161+
Datastore
162+
Blockstore-->Bitswap;
163+
Libp2p-->DHT;
164+
Libp2p-->PubSub;
165+
Libp2p-->IPNI;
166+
Libp2p-->Reframe;
167+
end
168+
Blockstore-->BlockStorage["File system/IDB/S3/etc"]
169+
Datastore-->DataStorage["Level/S3/IDB/etc"]
170+
Bitswap-->Network;
171+
DHT-->Network;
172+
PubSub-->Network;
173+
IPNI-->Network;
174+
Reframe-->Network;
175+
```
176+
42177
## 🏭 Code Structure
43178
Helia embraces a modular approach and encourages users to bring their own implementations of interfacing libraries to suit their needs. Helia also ships supplemental libraries and tools including:
44179

45180
- [`@helia/UnixFS`](https://github.com/ipfs/helia-unixfs)
46181
- [`@helia/ipns`](https://github.com/ipfs/helia-ipns)
182+
- [`@helia/strings`](https://github.com/ipfs/helia-strings)
183+
- [`@helia/json`](https://github.com/ipfs/helia-json)
184+
- [`@helia/dag-json`](https://github.com/ipfs/helia-dag-json)
185+
- [`@helia/dag-cbor`](https://github.com/ipfs/helia-dag-cbor)
47186

48187
These libraries are by no means the "one true implementation", but instead instead provide optionality depending on one's needs.
49188

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
"dep-check": "aegir run dep-check",
3939
"release": "npm run docs:no-publish && aegir run release && npm run docs"
4040
},
41-
"dependencies": {
42-
"aegir": "^38.1.0"
41+
"devDependencies": {
42+
"aegir": "^39.0.4"
4343
},
4444
"type": "module",
4545
"workspaces": [

packages/helia/CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
## [helia-v1.0.4](https://github.com/ipfs/helia/compare/helia-v1.0.3...helia-v1.0.4) (2023-05-04)
2+
3+
4+
### Bug Fixes
5+
6+
* **types:** Add missing types ([#95](https://github.com/ipfs/helia/issues/95)) ([e858b8d](https://github.com/ipfs/helia/commit/e858b8dbbff548b42dde225db674f0edd1990ed3))
7+
8+
9+
### Dependencies
10+
11+
* **dev:** bump libp2p from 0.43.4 to 0.44.0 ([#96](https://github.com/ipfs/helia/issues/96)) ([6e37d9f](https://github.com/ipfs/helia/commit/6e37d9f8be58955c5ddc5472fe3adb4bd9a0459c))
12+
13+
14+
### Trivial Changes
15+
16+
* bump aegir from 38.1.8 to 39.0.4 ([#111](https://github.com/ipfs/helia/issues/111)) ([2156568](https://github.com/ipfs/helia/commit/215656870cb821dd6be2f8054dc39932ba25af14))
17+
118
## [helia-v1.0.3](https://github.com/ipfs/helia/compare/helia-v1.0.2...helia-v1.0.3) (2023-04-05)
219

320

packages/helia/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "helia",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"description": "An implementation of IPFS in JavaScript",
55
"license": "Apache-2.0 OR MIT",
66
"homepage": "https://github.com/ipfs/helia/tree/master/packages/helia#readme",
@@ -167,9 +167,10 @@
167167
"@ipld/dag-cbor": "^9.0.0",
168168
"@ipld/dag-json": "^10.0.1",
169169
"@libp2p/websockets": "^5.0.3",
170-
"aegir": "^38.1.0",
170+
"@types/sinon": "^10.0.14",
171+
"aegir": "^39.0.4",
171172
"delay": "^5.0.0",
172-
"libp2p": "^0.43.0",
173+
"libp2p": "^0.44.0",
173174
"sinon": "^15.0.2",
174175
"sinon-ts": "^1.0.0"
175176
},

packages/helia/src/helia.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1+
import { logger } from '@libp2p/logger'
2+
import { MemoryBlockstore } from 'blockstore-core'
3+
import { MemoryDatastore } from 'datastore-core'
4+
import { type Bitswap, createBitswap } from 'ipfs-bitswap'
5+
import drain from 'it-drain'
6+
import { identity } from 'multiformats/hashes/identity'
7+
import { sha256, sha512 } from 'multiformats/hashes/sha2'
8+
import { CustomProgressEvent } from 'progress-events'
9+
import { PinsImpl } from './pins.js'
10+
import { BlockStorage } from './storage.js'
11+
import { assertDatastoreVersionIsCurrent } from './utils/datastore-version.js'
12+
import type { HeliaInit } from '.'
113
import type { GCOptions, Helia } from '@helia/interface'
14+
import type { Pins } from '@helia/interface/pins'
215
import type { Libp2p } from '@libp2p/interface-libp2p'
316
import type { Datastore } from 'interface-datastore'
417
import type { CID } from 'multiformats/cid'
5-
import { identity } from 'multiformats/hashes/identity'
6-
import { sha256, sha512 } from 'multiformats/hashes/sha2'
718
import type { MultihashHasher } from 'multiformats/hashes/interface'
8-
import type { HeliaInit } from '.'
9-
import { Bitswap, createBitswap } from 'ipfs-bitswap'
10-
import { BlockStorage } from './storage.js'
11-
import type { Pins } from '@helia/interface/pins'
12-
import { PinsImpl } from './pins.js'
13-
import { assertDatastoreVersionIsCurrent } from './utils/datastore-version.js'
14-
import drain from 'it-drain'
15-
import { CustomProgressEvent } from 'progress-events'
16-
import { MemoryDatastore } from 'datastore-core'
17-
import { MemoryBlockstore } from 'blockstore-core'
18-
import { logger } from '@libp2p/logger'
1919

2020
const log = logger('helia')
2121

packages/helia/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
* ```
2626
*/
2727

28+
import { HeliaImpl } from './helia.js'
2829
import type { Helia } from '@helia/interface'
2930
import type { Libp2p } from '@libp2p/interface-libp2p'
3031
import type { Blockstore } from 'interface-blockstore'
3132
import type { Datastore } from 'interface-datastore'
3233
import type { CID } from 'multiformats/cid'
3334
import type { MultihashHasher } from 'multiformats/hashes/interface'
34-
import { HeliaImpl } from './helia.js'
3535

3636
/**
3737
* DAGWalkers take a block and yield CIDs encoded in that block

packages/helia/src/pins.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import type { AddOptions, IsPinnedOptions, LsOptions, Pin, Pins, RmOptions } from '@helia/interface/pins'
2-
import { Datastore, Key } from 'interface-datastore'
3-
import { CID, Version } from 'multiformats/cid'
41
import * as cborg from 'cborg'
2+
import { type Datastore, Key } from 'interface-datastore'
53
import { base36 } from 'multiformats/bases/base36'
6-
import type { Blockstore } from 'interface-blockstore'
4+
import { CID, type Version } from 'multiformats/cid'
5+
import defer from 'p-defer'
76
import PQueue from 'p-queue'
8-
import type { AbortOptions } from '@libp2p/interfaces'
97
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
10-
import defer from 'p-defer'
11-
import type { DAGWalker } from './index.js'
128
import { cborWalker, dagPbWalker, jsonWalker, rawWalker } from './utils/dag-walkers.js'
9+
import type { DAGWalker } from './index.js'
10+
import type { AddOptions, IsPinnedOptions, LsOptions, Pin, Pins, RmOptions } from '@helia/interface/pins'
11+
import type { AbortOptions } from '@libp2p/interfaces'
12+
import type { Blockstore } from 'interface-blockstore'
1313

1414
const DEFAULT_DAG_WALKERS = [
1515
rawWalker,
@@ -233,6 +233,6 @@ export class PinsImpl implements Pins {
233233
async isPinned (cid: CID, options: IsPinnedOptions = {}): Promise<boolean> {
234234
const blockKey = new Key(`${DATASTORE_BLOCK_PREFIX}${DATASTORE_ENCODING.encode(cid.multihash.bytes)}`)
235235

236-
return await this.datastore.has(blockKey, options)
236+
return this.datastore.has(blockKey, options)
237237
}
238238
}

packages/helia/src/storage.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import filter from 'it-filter'
2-
import type { Blockstore } from 'interface-blockstore'
2+
import forEach from 'it-foreach'
3+
import createMortice from 'mortice'
4+
import { CustomProgressEvent, type ProgressOptions } from 'progress-events'
35
import type { Blocks, Pair, DeleteManyBlocksProgressEvents, DeleteBlockProgressEvents, GetBlockProgressEvents, GetManyBlocksProgressEvents, PutManyBlocksProgressEvents, PutBlockProgressEvents, GetAllBlocksProgressEvents } from '@helia/interface/blocks'
4-
import type { Bitswap } from 'ipfs-bitswap'
5-
import type { CID } from 'multiformats/cid'
6+
import type { Pins } from '@helia/interface/pins'
67
import type { AbortOptions } from '@libp2p/interfaces'
8+
import type { Blockstore } from 'interface-blockstore'
79
import type { AwaitIterable } from 'interface-store'
10+
import type { Bitswap } from 'ipfs-bitswap'
811
import type { Mortice } from 'mortice'
9-
import createMortice from 'mortice'
10-
import type { Pins } from '@helia/interface/pins'
11-
import forEach from 'it-foreach'
12-
import { CustomProgressEvent, ProgressOptions } from 'progress-events'
12+
import type { CID } from 'multiformats/cid'
1313

1414
export interface BlockStorageInit {
1515
holdGcLock?: boolean

packages/helia/src/utils/dag-walkers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import * as dagPb from '@ipld/dag-pb'
44
import * as cborg from 'cborg'
55
import { Type, Token } from 'cborg'
66
import * as cborgJson from 'cborg/json'
7-
import type { DAGWalker } from '../index.js'
8-
import * as raw from 'multiformats/codecs/raw'
97
import { CID } from 'multiformats'
108
import { base64 } from 'multiformats/bases/base64'
9+
import * as raw from 'multiformats/codecs/raw'
10+
import type { DAGWalker } from '../index.js'
1111

1212
/**
1313
* Dag walker for dag-pb CIDs

packages/helia/src/utils/datastore-version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Datastore, Key } from 'interface-datastore'
1+
import { type Datastore, Key } from 'interface-datastore'
22
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
33
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
44

0 commit comments

Comments
 (0)