@helia/routers 2.0.0 → 2.1.0-1aa6c8d

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
+ import type { DelegatedRoutingV1HttpApiClientInit } from '@helia/delegated-routing-v1-http-api-client';
1
2
  import type { Routing } from '@helia/interface';
2
3
  /**
3
4
  * 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.
4
5
  */
5
- export declare function delegatedHTTPRouting(url: string | URL): Routing;
6
+ export declare function delegatedHTTPRouting(url: string | URL, init?: DelegatedRoutingV1HttpApiClientInit): Routing;
6
7
  //# sourceMappingURL=delegated-http-routing.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"delegated-http-routing.d.ts","sourceRoot":"","sources":["../../src/delegated-http-routing.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAY,OAAO,EAAkB,MAAM,kBAAkB,CAAA;AAoFzE;;GAEG;AACH,wBAAgB,oBAAoB,CAAE,GAAG,EAAE,MAAM,GAAG,GAAG,GAAG,OAAO,CAEhE"}
1
+ {"version":3,"file":"delegated-http-routing.d.ts","sourceRoot":"","sources":["../../src/delegated-http-routing.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAmC,mCAAmC,EAAE,MAAM,6CAA6C,CAAA;AACvI,OAAO,KAAK,EAAY,OAAO,EAAkB,MAAM,kBAAkB,CAAA;AAwFzE;;GAEG;AACH,wBAAgB,oBAAoB,CAAE,GAAG,EAAE,MAAM,GAAG,GAAG,EAAE,IAAI,CAAC,EAAE,mCAAmC,GAAG,OAAO,CAG5G"}
@@ -6,18 +6,22 @@ import map from 'it-map';
6
6
  import { CID } from 'multiformats/cid';
7
7
  import { equals as uint8ArrayEquals } from 'uint8arrays/equals';
8
8
  import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
9
+ import { delegatedHTTPRoutingDefaults } from './utils/delegated-http-routing-defaults.js';
9
10
  const IPNS_PREFIX = uint8ArrayFromString('/ipns/');
10
11
  function isIPNSKey(key) {
11
12
  return uint8ArrayEquals(key.subarray(0, IPNS_PREFIX.byteLength), IPNS_PREFIX);
12
13
  }
13
14
  class DelegatedHTTPRouter {
14
15
  client;
15
- constructor(url) {
16
- this.client = createDelegatedRoutingV1HttpApiClient(url);
16
+ constructor(url, init = {}) {
17
+ this.client = createDelegatedRoutingV1HttpApiClient(url, init);
17
18
  }
18
19
  async provide(cid, options) {
19
20
  // noop
20
21
  }
22
+ async cancelReprovide(cid, options) {
23
+ // noop
24
+ }
21
25
  async *findProviders(cid, options) {
22
26
  yield* map(this.client.getProviders(cid, options), (record) => {
23
27
  return {
@@ -72,7 +76,8 @@ class DelegatedHTTPRouter {
72
76
  /**
73
77
  * 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.
74
78
  */
75
- export function delegatedHTTPRouting(url) {
76
- return new DelegatedHTTPRouter(new URL(url));
79
+ export function delegatedHTTPRouting(url, init) {
80
+ const config = init ?? delegatedHTTPRoutingDefaults();
81
+ return new DelegatedHTTPRouter(new URL(url), config);
77
82
  }
78
83
  //# sourceMappingURL=delegated-http-routing.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"delegated-http-routing.js","sourceRoot":"","sources":["../../src/delegated-http-routing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qCAAqC,EAAE,MAAM,6CAA6C,CAAA;AACnG,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,iBAAiB,EAAE,2BAA2B,EAAE,mBAAmB,EAAE,MAAM,MAAM,CAAA;AAC1F,OAAO,KAAK,MAAM,UAAU,CAAA;AAC5B,OAAO,GAAG,MAAM,QAAQ,CAAA;AACxB,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AACtC,OAAO,EAAE,MAAM,IAAI,gBAAgB,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MAAM,CAAC,CAAA;QAClC,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,wEAAwE;YACxE,+BAA+B;YAC/B,IAAI,GAAG,CAAC,IAAI,KAAK,kBAAkB,EAAE,CAAC;gBACpC,MAAM,IAAI,aAAa,CAAC,WAAW,CAAC,CAAA;YACtC,CAAC;YAED,MAAM,GAAG,CAAA;QACX,CAAC;IACH,CAAC;IAED,KAAK,CAAC,QAAQ,CAAE,MAAc,EAAE,OAAwB;QACtD,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;QAE/D,IAAI,IAAI,IAAI,IAAI,EAAE,CAAC;YACjB,OAAO;gBACL,EAAE,EAAE,IAAI,CAAC,EAAE;gBACX,UAAU,EAAE,IAAI,CAAC,KAAK,IAAI,EAAE;aAC7B,CAAA;QACH,CAAC;QAED,MAAM,IAAI,aAAa,CAAC,WAAW,CAAC,CAAA;IACtC,CAAC;IAED,KAAK,CAAC,CAAE,eAAe,CAAE,GAAe,EAAE,OAAwB;QAChE,OAAO;IACT,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAE,GAAiB,EAAE,IAA0C;IACjG,MAAM,MAAM,GAAG,IAAI,IAAI,4BAA4B,EAAE,CAAA;IACrD,OAAO,IAAI,mBAAmB,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAAA;AACtD,CAAC"}
@@ -4,6 +4,7 @@
4
4
  * Abstraction layer over different content and peer routing mechanisms.
5
5
  */
6
6
  export { delegatedHTTPRouting } from './delegated-http-routing.js';
7
+ export { delegatedHTTPRoutingDefaults } from './utils/delegated-http-routing-defaults.js';
7
8
  export { httpGatewayRouting } from './http-gateway-routing.js';
8
9
  export type { HTTPGatwayRouterInit } from './http-gateway-routing.js';
9
10
  export { libp2pRouting } from './libp2p-routing.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAC9D,YAAY,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AAClE,OAAO,EAAE,4BAA4B,EAAE,MAAM,4CAA4C,CAAA;AACzF,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAC9D,YAAY,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA"}
package/dist/src/index.js CHANGED
@@ -4,6 +4,7 @@
4
4
  * Abstraction layer over different content and peer routing mechanisms.
5
5
  */
6
6
  export { delegatedHTTPRouting } from './delegated-http-routing.js';
7
+ export { delegatedHTTPRoutingDefaults } from './utils/delegated-http-routing-defaults.js';
7
8
  export { httpGatewayRouting } from './http-gateway-routing.js';
8
9
  export { libp2pRouting } from './libp2p-routing.js';
9
10
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAE9D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AAClE,OAAO,EAAE,4BAA4B,EAAE,MAAM,4CAA4C,CAAA;AACzF,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAE9D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"libp2p-routing.d.ts","sourceRoot":"","sources":["../../src/libp2p-routing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAY,OAAO,EAAkB,MAAM,kBAAkB,CAAA;AACzE,OAAO,KAAK,EAAE,MAAM,EAAoB,MAAM,mBAAmB,CAAA;AAmCjE,wBAAgB,aAAa,CAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAEtD"}
1
+ {"version":3,"file":"libp2p-routing.d.ts","sourceRoot":"","sources":["../../src/libp2p-routing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAY,OAAO,EAAkB,MAAM,kBAAkB,CAAA;AACzE,OAAO,KAAK,EAAE,MAAM,EAAoB,MAAM,mBAAmB,CAAA;AAuCjE,wBAAgB,aAAa,CAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAEtD"}
@@ -6,6 +6,9 @@ class Libp2pRouter {
6
6
  async provide(cid, options) {
7
7
  await this.libp2p.contentRouting.provide(cid, options);
8
8
  }
9
+ async cancelReprovide(key, options) {
10
+ await this.libp2p.contentRouting.cancelReprovide(key, options);
11
+ }
9
12
  async *findProviders(cid, options) {
10
13
  yield* this.libp2p.contentRouting.findProviders(cid, options);
11
14
  }
@@ -1 +1 @@
1
- {"version":3,"file":"libp2p-routing.js","sourceRoot":"","sources":["../../src/libp2p-routing.ts"],"names":[],"mappings":"AAIA,MAAM,YAAY;IACC,MAAM,CAAQ;IAE/B,YAAa,MAAc;QACzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAED,KAAK,CAAC,OAAO,CAAE,GAAQ,EAAE,OAA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
1
+ import type { DelegatedRoutingV1HttpApiClientInit } from '@helia/delegated-routing-v1-http-api-client';
2
+ export declare function delegatedHTTPRoutingDefaults(): DelegatedRoutingV1HttpApiClientInit;
3
+ //# sourceMappingURL=delegated-http-routing-defaults.browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delegated-http-routing-defaults.browser.d.ts","sourceRoot":"","sources":["../../../src/utils/delegated-http-routing-defaults.browser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,6CAA6C,CAAA;AAEtG,wBAAgB,4BAA4B,IAAK,mCAAmC,CAKnF"}
@@ -0,0 +1,7 @@
1
+ export function delegatedHTTPRoutingDefaults() {
2
+ return {
3
+ filterProtocols: ['unknown', 'transport-bitswap', 'transport-ipfs-gateway-http'],
4
+ filterAddrs: ['https', 'webtransport', 'webrtc', 'webrtc-direct', 'wss', 'tls']
5
+ };
6
+ }
7
+ //# sourceMappingURL=delegated-http-routing-defaults.browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delegated-http-routing-defaults.browser.js","sourceRoot":"","sources":["../../../src/utils/delegated-http-routing-defaults.browser.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,4BAA4B;IAC1C,OAAO;QACL,eAAe,EAAE,CAAC,SAAS,EAAE,mBAAmB,EAAE,6BAA6B,CAAC;QAChF,WAAW,EAAE,CAAC,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,eAAe,EAAE,KAAK,EAAE,KAAK,CAAC;KAChF,CAAA;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { DelegatedRoutingV1HttpApiClientInit } from '@helia/delegated-routing-v1-http-api-client';
2
+ export declare function delegatedHTTPRoutingDefaults(): DelegatedRoutingV1HttpApiClientInit;
3
+ //# sourceMappingURL=delegated-http-routing-defaults.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delegated-http-routing-defaults.d.ts","sourceRoot":"","sources":["../../../src/utils/delegated-http-routing-defaults.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,6CAA6C,CAAA;AAEtG,wBAAgB,4BAA4B,IAAK,mCAAmC,CAKnF"}
@@ -0,0 +1,7 @@
1
+ export function delegatedHTTPRoutingDefaults() {
2
+ return {
3
+ filterProtocols: ['unknown', 'transport-bitswap', 'transport-ipfs-gateway-http'],
4
+ filterAddrs: ['https', 'tcp', 'webrtc', 'webrtc-direct', 'wss', 'tls']
5
+ };
6
+ }
7
+ //# sourceMappingURL=delegated-http-routing-defaults.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delegated-http-routing-defaults.js","sourceRoot":"","sources":["../../../src/utils/delegated-http-routing-defaults.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,4BAA4B;IAC1C,OAAO;QACL,eAAe,EAAE,CAAC,SAAS,EAAE,mBAAmB,EAAE,6BAA6B,CAAC;QAChF,WAAW,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,KAAK,EAAE,KAAK,CAAC;KACvE,CAAA;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@helia/routers",
3
- "version": "2.0.0",
3
+ "version": "2.1.0-1aa6c8d",
4
4
  "description": "Routers for Helia",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/ipfs/helia/tree/main/packages/routers#readme",
@@ -54,8 +54,8 @@
54
54
  "test:electron-main": "aegir test -t electron-main"
55
55
  },
56
56
  "dependencies": {
57
- "@helia/delegated-routing-v1-http-api-client": "^4.0.0",
58
- "@helia/interface": "^5.0.0",
57
+ "@helia/delegated-routing-v1-http-api-client": "^4.1.0",
58
+ "@helia/interface": "5.0.0-1aa6c8d",
59
59
  "@libp2p/peer-id": "^5.0.0",
60
60
  "@libp2p/interface": "^2.0.0",
61
61
  "@multiformats/uri-to-multiaddr": "^8.0.0",
@@ -67,10 +67,13 @@
67
67
  },
68
68
  "devDependencies": {
69
69
  "@libp2p/crypto": "^5.0.0",
70
- "aegir": "^44.0.1",
70
+ "aegir": "^45.0.1",
71
71
  "it-all": "^3.0.4",
72
72
  "it-drain": "^3.0.5",
73
73
  "sinon-ts": "^2.0.0"
74
74
  },
75
+ "browser": {
76
+ "./dist/src/utils/delegated-http-routing-defaults.js": "./dist/src/utils/delegated-http-routing-defaults.browser.js"
77
+ },
75
78
  "sideEffects": false
76
79
  }
@@ -6,7 +6,8 @@ import map from 'it-map'
6
6
  import { CID } from 'multiformats/cid'
7
7
  import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
8
8
  import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
9
- import type { DelegatedRoutingV1HttpApiClient } from '@helia/delegated-routing-v1-http-api-client'
9
+ import { delegatedHTTPRoutingDefaults } from './utils/delegated-http-routing-defaults.js'
10
+ import type { DelegatedRoutingV1HttpApiClient, DelegatedRoutingV1HttpApiClientInit } from '@helia/delegated-routing-v1-http-api-client'
10
11
  import type { Provider, Routing, RoutingOptions } from '@helia/interface'
11
12
  import type { PeerId, PeerInfo } from '@libp2p/interface'
12
13
  import type { Version } from 'multiformats'
@@ -20,15 +21,19 @@ function isIPNSKey (key: Uint8Array): boolean {
20
21
  class DelegatedHTTPRouter implements Routing {
21
22
  private readonly client: DelegatedRoutingV1HttpApiClient
22
23
 
23
- constructor (url: URL) {
24
- this.client = createDelegatedRoutingV1HttpApiClient(url)
24
+ constructor (url: URL, init: DelegatedRoutingV1HttpApiClientInit = {}) {
25
+ this.client = createDelegatedRoutingV1HttpApiClient(url, init)
25
26
  }
26
27
 
27
- async provide (cid: CID, options?: RoutingOptions | undefined): Promise<void> {
28
+ async provide (cid: CID, options?: RoutingOptions): Promise<void> {
28
29
  // noop
29
30
  }
30
31
 
31
- async * findProviders (cid: CID<unknown, number, number, Version>, options?: RoutingOptions | undefined): AsyncIterable<Provider> {
32
+ async cancelReprovide (cid?: CID, options?: RoutingOptions): Promise<void> {
33
+ // noop
34
+ }
35
+
36
+ async * findProviders (cid: CID<unknown, number, number, Version>, options?: RoutingOptions): AsyncIterable<Provider> {
32
37
  yield * map(this.client.getProviders(cid, options), (record) => {
33
38
  return {
34
39
  id: record.ID,
@@ -38,7 +43,7 @@ class DelegatedHTTPRouter implements Routing {
38
43
  })
39
44
  }
40
45
 
41
- async put (key: Uint8Array, value: Uint8Array, options?: RoutingOptions | undefined): Promise<void> {
46
+ async put (key: Uint8Array, value: Uint8Array, options?: RoutingOptions): Promise<void> {
42
47
  if (!isIPNSKey(key)) {
43
48
  return
44
49
  }
@@ -50,7 +55,7 @@ class DelegatedHTTPRouter implements Routing {
50
55
  await this.client.putIPNS(cid, record, options)
51
56
  }
52
57
 
53
- async get (key: Uint8Array, options?: RoutingOptions | undefined): Promise<Uint8Array> {
58
+ async get (key: Uint8Array, options?: RoutingOptions): Promise<Uint8Array> {
54
59
  if (!isIPNSKey(key)) {
55
60
  throw new NotFoundError('Not found')
56
61
  }
@@ -73,7 +78,7 @@ class DelegatedHTTPRouter implements Routing {
73
78
  }
74
79
  }
75
80
 
76
- async findPeer (peerId: PeerId, options?: RoutingOptions | undefined): Promise<PeerInfo> {
81
+ async findPeer (peerId: PeerId, options?: RoutingOptions): Promise<PeerInfo> {
77
82
  const peer = await first(this.client.getPeers(peerId, options))
78
83
 
79
84
  if (peer != null) {
@@ -86,7 +91,7 @@ class DelegatedHTTPRouter implements Routing {
86
91
  throw new NotFoundError('Not found')
87
92
  }
88
93
 
89
- async * getClosestPeers (key: Uint8Array, options?: RoutingOptions | undefined): AsyncIterable<PeerInfo> {
94
+ async * getClosestPeers (key: Uint8Array, options?: RoutingOptions): AsyncIterable<PeerInfo> {
90
95
  // noop
91
96
  }
92
97
  }
@@ -94,6 +99,7 @@ class DelegatedHTTPRouter implements Routing {
94
99
  /**
95
100
  * 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.
96
101
  */
97
- export function delegatedHTTPRouting (url: string | URL): Routing {
98
- return new DelegatedHTTPRouter(new URL(url))
102
+ export function delegatedHTTPRouting (url: string | URL, init?: DelegatedRoutingV1HttpApiClientInit): Routing {
103
+ const config = init ?? delegatedHTTPRoutingDefaults()
104
+ return new DelegatedHTTPRouter(new URL(url), config)
99
105
  }
package/src/index.ts CHANGED
@@ -4,6 +4,7 @@
4
4
  * Abstraction layer over different content and peer routing mechanisms.
5
5
  */
6
6
  export { delegatedHTTPRouting } from './delegated-http-routing.js'
7
+ export { delegatedHTTPRoutingDefaults } from './utils/delegated-http-routing-defaults.js'
7
8
  export { httpGatewayRouting } from './http-gateway-routing.js'
8
9
  export type { HTTPGatwayRouterInit } from './http-gateway-routing.js'
9
10
  export { libp2pRouting } from './libp2p-routing.js'
@@ -13,6 +13,10 @@ class Libp2pRouter implements Routing {
13
13
  await this.libp2p.contentRouting.provide(cid, options)
14
14
  }
15
15
 
16
+ async cancelReprovide (key: CID, options?: RoutingOptions): Promise<void> {
17
+ await this.libp2p.contentRouting.cancelReprovide(key, options)
18
+ }
19
+
16
20
  async * findProviders (cid: CID, options?: RoutingOptions): AsyncIterable<Provider> {
17
21
  yield * this.libp2p.contentRouting.findProviders(cid, options)
18
22
  }
@@ -0,0 +1,8 @@
1
+ import type { DelegatedRoutingV1HttpApiClientInit } from '@helia/delegated-routing-v1-http-api-client'
2
+
3
+ export function delegatedHTTPRoutingDefaults (): DelegatedRoutingV1HttpApiClientInit {
4
+ return {
5
+ filterProtocols: ['unknown', 'transport-bitswap', 'transport-ipfs-gateway-http'],
6
+ filterAddrs: ['https', 'webtransport', 'webrtc', 'webrtc-direct', 'wss', 'tls']
7
+ }
8
+ }
@@ -0,0 +1,8 @@
1
+ import type { DelegatedRoutingV1HttpApiClientInit } from '@helia/delegated-routing-v1-http-api-client'
2
+
3
+ export function delegatedHTTPRoutingDefaults (): DelegatedRoutingV1HttpApiClientInit {
4
+ return {
5
+ filterProtocols: ['unknown', 'transport-bitswap', 'transport-ipfs-gateway-http'],
6
+ filterAddrs: ['https', 'tcp', 'webrtc', 'webrtc-direct', 'wss', 'tls']
7
+ }
8
+ }
@@ -1,6 +0,0 @@
1
- {
2
- "HTTPGatwayRouterInit": "https://ipfs.github.io/helia/interfaces/_helia_routers.HTTPGatwayRouterInit.html",
3
- "delegatedHTTPRouting": "https://ipfs.github.io/helia/functions/_helia_routers.delegatedHTTPRouting.html",
4
- "httpGatewayRouting": "https://ipfs.github.io/helia/functions/_helia_routers.httpGatewayRouting.html",
5
- "libp2pRouting": "https://ipfs.github.io/helia/functions/_helia_routers.libp2pRouting.html"
6
- }