Skip to content

Commit 1c79dae

Browse files
committed
deps!: update delegated routing client (#937)
BREAKING CHANGE: pass the endpoint URL to the delegated routing router as a `url` property of an init object
1 parent 14e7873 commit 1c79dae

6 files changed

Lines changed: 16 additions & 28 deletions

File tree

packages/interop/src/ipns-http.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ describe('@helia/ipns - http', () => {
2525
kubo = await createKuboNode()
2626
helia = await createHeliaHTTP({
2727
routers: [
28-
delegatedHTTPRouting('http://127.0.0.1:8180')
28+
delegatedHTTPRouting({
29+
url: 'http://127.0.0.1:8180'
30+
})
2931
]
3032
})
3133
name = ipns(helia)

packages/routers/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,9 @@
4747
"test:electron-main": "aegir test -t electron-main"
4848
},
4949
"dependencies": {
50-
"@helia/delegated-routing-v1-http-api-client": "^5.1.2",
50+
"@helia/delegated-routing-v1-http-api-client": "^6.0.0",
5151
"@helia/interface": "^6.0.2",
5252
"@libp2p/interface": "^3.1.0",
53-
"@libp2p/logger": "^6.2.0",
5453
"@libp2p/peer-id": "^6.0.3",
5554
"@multiformats/uri-to-multiaddr": "^10.0.0",
5655
"ipns": "^10.1.2",
@@ -61,6 +60,7 @@
6160
},
6261
"devDependencies": {
6362
"@libp2p/crypto": "^5.1.12",
63+
"@libp2p/logger": "^6.2.0",
6464
"aegir": "^47.0.22",
6565
"it-all": "^3.0.9",
6666
"it-drain": "^3.0.10",

packages/routers/src/delegated-http-routing.ts

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { delegatedRoutingV1HttpApiClient } from '@helia/delegated-routing-v1-http-api-client'
22
import { NotFoundError } from '@libp2p/interface'
3-
import { defaultLogger } from '@libp2p/logger'
43
import { marshalIPNSRecord, multihashFromIPNSRoutingKey, unmarshalIPNSRecord } from 'ipns'
54
import first from 'it-first'
65
import map from 'it-map'
@@ -22,7 +21,7 @@ function isIPNSKey (key: Uint8Array): boolean {
2221
class DelegatedHTTPRouter implements Routing {
2322
private readonly client: DelegatedRoutingV1HttpApiClient
2423

25-
constructor (components: DelegatedRoutingV1HttpApiClientComponents, init: DelegatedRoutingV1HttpApiClientInit & { url: string | URL }) {
24+
constructor (components: DelegatedRoutingV1HttpApiClientComponents, init: DelegatedRoutingV1HttpApiClientInit) {
2625
this.client = delegatedRoutingV1HttpApiClient(init)(components)
2726
}
2827

@@ -105,24 +104,6 @@ class DelegatedHTTPRouter implements Routing {
105104
/**
106105
* Creates a Helia Router that connects to an endpoint that supports the [Delegated Routing V1 HTTP API](https://specs.ipfs.tech/routing/http-routing-v1/) spec.
107106
*/
108-
export function delegatedHTTPRouting (init: DelegatedRoutingV1HttpApiClientInit & { url: string | URL }): (components: any) => Routing
109-
/**
110-
* @deprecated Use `delegatedHTTPRouting(init)` instead
111-
*/
112-
export function delegatedHTTPRouting (url: string | URL, init?: DelegatedRoutingV1HttpApiClientInit): Routing
113-
export function delegatedHTTPRouting (url: string | URL | (DelegatedRoutingV1HttpApiClientInit & { url: string | URL }), init?: DelegatedRoutingV1HttpApiClientInit): Routing | ((components: any) => Routing) {
114-
if (typeof url === 'string' || url instanceof URL) {
115-
return new DelegatedHTTPRouter({
116-
logger: defaultLogger()
117-
}, {
118-
...delegatedHTTPRoutingDefaults(),
119-
...init,
120-
url: new URL(url)
121-
})
122-
}
123-
124-
return (components: any) => new DelegatedHTTPRouter(components, {
125-
...delegatedHTTPRoutingDefaults(),
126-
...url
127-
})
107+
export function delegatedHTTPRouting (init: DelegatedRoutingV1HttpApiClientInit): (components: any) => Routing {
108+
return (components: any) => new DelegatedHTTPRouter(components, delegatedHTTPRoutingDefaults(init))
128109
}

packages/routers/src/utils/delegated-http-routing-defaults.browser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { DelegatedRoutingV1HttpApiClientInit } from '@helia/delegated-routing-v1-http-api-client'
22

3-
export function delegatedHTTPRoutingDefaults (init?: DelegatedRoutingV1HttpApiClientInit): DelegatedRoutingV1HttpApiClientInit & { url: string } {
3+
export function delegatedHTTPRoutingDefaults (init?: DelegatedRoutingV1HttpApiClientInit): DelegatedRoutingV1HttpApiClientInit {
44
return {
55
url: 'https://delegated-ipfs.dev',
66
filterProtocols: ['unknown', 'transport-bitswap', 'transport-ipfs-gateway-http'],

packages/routers/src/utils/delegated-http-routing-defaults.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { DelegatedRoutingV1HttpApiClientInit } from '@helia/delegated-routing-v1-http-api-client'
22

3-
export function delegatedHTTPRoutingDefaults (init?: DelegatedRoutingV1HttpApiClientInit): DelegatedRoutingV1HttpApiClientInit & { url: string } {
3+
export function delegatedHTTPRoutingDefaults (init?: DelegatedRoutingV1HttpApiClientInit): DelegatedRoutingV1HttpApiClientInit {
44
return {
55
url: 'https://delegated-ipfs.dev',
66
filterProtocols: ['unknown', 'transport-bitswap', 'transport-ipfs-gateway-http'],

packages/routers/test/delegated-http-routing.spec.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { generateKeyPair } from '@libp2p/crypto/keys'
2+
import { defaultLogger } from '@libp2p/logger'
23
import { peerIdFromString } from '@libp2p/peer-id'
34
import { expect } from 'aegir/chai'
45
import { multihashToIPNSRoutingKey, createIPNSRecord, marshalIPNSRecord } from 'ipns'
@@ -17,7 +18,11 @@ describe('delegated-http-routing', () => {
1718
beforeEach(() => {
1819
client = stubInterface<DelegatedRoutingV1HttpApiClient>()
1920

20-
router = delegatedHTTPRouting('http://127.0.0.1')
21+
router = delegatedHTTPRouting({
22+
url: 'http://127.0.0.1'
23+
})({
24+
logger: defaultLogger()
25+
})
2126
// @ts-expect-error private field
2227
router.client = client
2328
})

0 commit comments

Comments
 (0)