@helia/ipns 3.0.1 → 4.0.0

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,21 +1,21 @@
1
1
  import { CustomProgressEvent, type ProgressEvent } from 'progress-events'
2
2
  import type { GetOptions, PutOptions } from './index.js'
3
3
  import type { IPNSRouting } from '../index.js'
4
- import type { ContentRouting } from '@libp2p/interface/content-routing'
4
+ import type { ContentRouting } from '@libp2p/interface'
5
5
 
6
- export interface DHTRoutingComponents {
6
+ export interface Libp2pContentRoutingComponents {
7
7
  libp2p: {
8
8
  contentRouting: ContentRouting
9
9
  }
10
10
  }
11
11
 
12
- export type DHTProgressEvents =
13
- ProgressEvent<'ipns:routing:dht:error', Error>
12
+ export type Libp2pContentRoutingProgressEvents =
13
+ ProgressEvent<'ipns:routing:libp2p:error', Error>
14
14
 
15
- export class DHTRouting implements IPNSRouting {
15
+ export class Libp2pContentRouting implements IPNSRouting {
16
16
  private readonly contentRouting: ContentRouting
17
17
 
18
- constructor (components: DHTRoutingComponents) {
18
+ constructor (components: Libp2pContentRoutingComponents) {
19
19
  this.contentRouting = components.libp2p.contentRouting
20
20
  }
21
21
 
@@ -23,7 +23,7 @@ export class DHTRouting implements IPNSRouting {
23
23
  try {
24
24
  await this.contentRouting.put(routingKey, marshaledRecord, options)
25
25
  } catch (err: any) {
26
- options.onProgress?.(new CustomProgressEvent<Error>('ipns:routing:dht:error', err))
26
+ options.onProgress?.(new CustomProgressEvent<Error>('ipns:routing:libp2p:error', err))
27
27
  }
28
28
  }
29
29
 
@@ -31,13 +31,17 @@ export class DHTRouting implements IPNSRouting {
31
31
  try {
32
32
  return await this.contentRouting.get(routingKey, options)
33
33
  } catch (err: any) {
34
- options.onProgress?.(new CustomProgressEvent<Error>('ipns:routing:dht:error', err))
34
+ options.onProgress?.(new CustomProgressEvent<Error>('ipns:routing:libp2p:error', err))
35
35
  }
36
36
 
37
37
  throw new Error('Not found')
38
38
  }
39
39
  }
40
40
 
41
- export function dht (components: DHTRoutingComponents): IPNSRouting {
42
- return new DHTRouting(components)
41
+ /**
42
+ * The libp2p routing uses any available Content Routers configured on the
43
+ * passed libp2p node. This could be KadDHT, HTTP API Delegated Routing, etc.
44
+ */
45
+ export function libp2p (components: Libp2pContentRoutingComponents): IPNSRouting {
46
+ return new Libp2pContentRouting(components)
43
47
  }
@@ -1,4 +1,4 @@
1
- import { CodeError } from '@libp2p/interface/errors'
1
+ import { CodeError } from '@libp2p/interface'
2
2
  import { logger } from '@libp2p/logger'
3
3
  import { peerIdToRoutingKey } from 'ipns'
4
4
  import { ipnsSelector } from 'ipns/selector'
@@ -9,8 +9,7 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
9
9
  import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
10
10
  import { localStore, type LocalStore } from './local-store.js'
11
11
  import type { GetOptions, IPNSRouting, PutOptions } from './index.js'
12
- import type { PeerId } from '@libp2p/interface/peer-id'
13
- import type { Message, PublishResult, PubSub } from '@libp2p/interface/pubsub'
12
+ import type { PeerId, Message, PublishResult, PubSub } from '@libp2p/interface'
14
13
  import type { Datastore } from 'interface-datastore'
15
14
 
16
15
  const log = logger('helia:ipns:routing:pubsub')
@@ -30,14 +29,6 @@ export type PubSubProgressEvents =
30
29
  ProgressEvent<'ipns:pubsub:subscribe', { topic: string }> |
31
30
  ProgressEvent<'ipns:pubsub:error', Error>
32
31
 
33
- /**
34
- * This IPNS routing receives IPNS record updates via dedicated
35
- * pubsub topic.
36
- *
37
- * Note we must first be subscribed to the topic in order to receive
38
- * updated records, so the first call to `.get` should be expected
39
- * to fail!
40
- */
41
32
  class PubSubRouting implements IPNSRouting {
42
33
  private subscriptions: string[]
43
34
  private readonly localStore: LocalStore
@@ -192,6 +183,14 @@ function topicToKey (topic: string): Uint8Array {
192
183
  return uint8ArrayFromString(key, 'base64url')
193
184
  }
194
185
 
186
+ /**
187
+ * This IPNS routing receives IPNS record updates via dedicated
188
+ * pubsub topic.
189
+ *
190
+ * Note we must first be subscribed to the topic in order to receive
191
+ * updated records, so the first call to `.get` should be expected
192
+ * to fail!
193
+ */
195
194
  export function pubsub (components: PubsubRoutingComponents): IPNSRouting {
196
195
  return new PubSubRouting(components)
197
196
  }
package/src/utils/dns.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { CodeError } from '@libp2p/interface/errors'
1
+ import { CodeError } from '@libp2p/interface'
2
2
  import * as isIPFS from 'is-ipfs'
3
3
  import type { DNSResolver, ResolveDnsLinkOptions } from '../index.js'
4
4
 
@@ -1,18 +0,0 @@
1
- import { type ProgressEvent } from 'progress-events';
2
- import type { GetOptions, PutOptions } from './index.js';
3
- import type { IPNSRouting } from '../index.js';
4
- import type { ContentRouting } from '@libp2p/interface/content-routing';
5
- export interface DHTRoutingComponents {
6
- libp2p: {
7
- contentRouting: ContentRouting;
8
- };
9
- }
10
- export type DHTProgressEvents = ProgressEvent<'ipns:routing:dht:error', Error>;
11
- export declare class DHTRouting implements IPNSRouting {
12
- private readonly contentRouting;
13
- constructor(components: DHTRoutingComponents);
14
- put(routingKey: Uint8Array, marshaledRecord: Uint8Array, options?: PutOptions): Promise<void>;
15
- get(routingKey: Uint8Array, options?: GetOptions): Promise<Uint8Array>;
16
- }
17
- export declare function dht(components: DHTRoutingComponents): IPNSRouting;
18
- //# sourceMappingURL=dht.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dht.d.ts","sourceRoot":"","sources":["../../../src/routing/dht.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAA;AACzE,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAA;AAEvE,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE;QACN,cAAc,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