Skip to content

Commit 08877af

Browse files
authored
refactor!: extract fetch to separate module (#2223)
BREAKING CHANGE: imports from `libp2p/fetch` should be updated to `@libp2p/fetch`
1 parent 2b8ef3c commit 08877af

File tree

23 files changed

+847
-730
lines changed

23 files changed

+847
-730
lines changed

.release-please.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"packages/peer-store": {},
2424
"packages/protocol-autonat": {},
2525
"packages/protocol-dcutr": {},
26+
"packages/protocol-fetch": {},
2627
"packages/protocol-identify": {},
2728
"packages/protocol-perf": {},
2829
"packages/protocol-ping": {},

doc/migrations/v0.46-v1.0.0.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ A migration guide for refactoring your application code from libp2p `v0.46` to `
99
- [Ping](#ping)
1010
- [Identify](#identify)
1111
- [DCUtR](#dcutr)
12+
- [Fetch](#fetch)
1213
- [KeyChain](#keychain)
1314
- [UPnPNat](#upnpnat)
1415
- [Plaintext](#plaintext)
@@ -117,7 +118,7 @@ import { dcutrService } from 'libp2p/dcutr'
117118

118119
const node = await createLibp2p({
119120
services: {
120-
identify: dcutrService()
121+
dcutr: dcutrService()
121122
}
122123
})
123124
```
@@ -135,6 +136,36 @@ const node = await createLibp2p({
135136
})
136137
```
137138

139+
## Fetch
140+
141+
The Fetch service is now published in its own package.
142+
143+
**Before**
144+
145+
```ts
146+
import { createLibp2p } from 'libp2p'
147+
import { fetchService } from 'libp2p/fetch'
148+
149+
const node = await createLibp2p({
150+
services: {
151+
fetch: fetchService()
152+
}
153+
})
154+
```
155+
156+
**After**
157+
158+
```ts
159+
import { createLibp2p } from 'libp2p'
160+
import { fetch } from '@libp2p/fetch'
161+
162+
const node = await createLibp2p({
163+
services: {
164+
fetch: fetch()
165+
}
166+
})
167+
```
168+
138169
## KeyChain
139170

140171
The KeyChain object is no longer included on Libp2p and must be instantiated explicitly if desired.

packages/libp2p/.aegir.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export default {
1818
const { plaintext } = await import('@libp2p/plaintext')
1919
const { circuitRelayServer, circuitRelayTransport } = await import('@libp2p/circuit-relay-v2')
2020
const { identify } = await import('@libp2p/identify')
21-
const { fetchService } = await import('./dist/src/fetch/index.js')
2221

2322
const peerId = await createEd25519PeerId()
2423
const libp2p = await createLibp2p({
@@ -46,7 +45,6 @@ export default {
4645
],
4746
services: {
4847
identify: identify(),
49-
fetch: fetchService(),
5048
relay: circuitRelayServer({
5149
reservations: {
5250
maxReservations: Infinity

packages/libp2p/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@
2828

2929
> JavaScript implementation of libp2p, a modular peer to peer network stack
3030
31+
# About
32+
33+
Use the `createLibp2p` function to create a libp2p node.
34+
35+
## Example
36+
37+
```typescript
38+
import { createLibp2p } from 'libp2p'
39+
40+
const node = await createLibp2p({
41+
// ...other options
42+
})
43+
```
44+
3145
# Project status
3246

3347
We've come a long way, but this project is still in Alpha, lots of development is happening, API might change, beware of the Dragons 🐉..

packages/libp2p/package.json

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,6 @@
2121
],
2222
"type": "module",
2323
"types": "./dist/src/index.d.ts",
24-
"typesVersions": {
25-
"*": {
26-
"*": [
27-
"*",
28-
"dist/*",
29-
"dist/src/*",
30-
"dist/src/*/index"
31-
],
32-
"src/*": [
33-
"*",
34-
"dist/*",
35-
"dist/src/*",
36-
"dist/src/*/index"
37-
]
38-
}
39-
},
4024
"files": [
4125
"src",
4226
"dist",
@@ -47,10 +31,6 @@
4731
".": {
4832
"types": "./dist/src/index.d.ts",
4933
"import": "./dist/src/index.js"
50-
},
51-
"./fetch": {
52-
"types": "./dist/src/fetch/index.d.ts",
53-
"import": "./dist/src/fetch/index.js"
5434
}
5535
},
5636
"eslintConfig": {
@@ -71,12 +51,6 @@
7151
"dep-check": "aegir dep-check",
7252
"prepublishOnly": "node scripts/update-version.js && npm run build",
7353
"build": "aegir build",
74-
"generate": "run-s generate:proto:*",
75-
"generate:proto:circuit-relay": "protons ./src/circuit-relay/pb/index.proto",
76-
"generate:proto:dcutr": "protons ./src/dcutr/pb/message.proto",
77-
"generate:proto:fetch": "protons ./src/fetch/pb/proto.proto",
78-
"generate:proto:identify": "protons ./src/identify/pb/message.proto",
79-
"generate:proto:plaintext": "protons ./src/insecure/pb/proto.proto",
8054
"test": "aegir test",
8155
"test:node": "aegir test -t node -f \"./dist/test/**/*.{node,spec}.js\" --cov",
8256
"test:chrome": "aegir test -t browser -f \"./dist/test/**/*.spec.js\" --cov",
@@ -108,7 +82,6 @@
10882
"it-drain": "^3.0.2",
10983
"it-filter": "^3.0.1",
11084
"it-first": "^3.0.1",
111-
"it-length-prefixed": "^9.0.1",
11285
"it-map": "^3.0.3",
11386
"it-merge": "^3.0.0",
11487
"it-pipe": "^3.0.1",
@@ -118,7 +91,6 @@
11891
"p-defer": "^4.0.0",
11992
"p-queue": "^7.3.4",
12093
"private-ip": "^3.0.0",
121-
"protons-runtime": "^5.0.0",
12294
"rate-limiter-flexible": "^3.0.0",
12395
"uint8arraylist": "^2.4.3",
12496
"uint8arrays": "^4.0.6"
@@ -145,11 +117,9 @@
145117
"execa": "^8.0.1",
146118
"go-libp2p": "^1.1.1",
147119
"it-pushable": "^3.2.0",
148-
"npm-run-all": "^4.1.5",
149120
"p-event": "^6.0.0",
150121
"p-times": "^4.0.0",
151122
"p-wait-for": "^5.0.2",
152-
"protons": "^7.0.2",
153123
"sinon": "^17.0.0",
154124
"sinon-ts": "^2.0.0"
155125
},

packages/libp2p/src/fetch/README.md

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)