@helia/ipns 9.1.9-eaeb734d → 9.2.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.
@@ -180,8 +180,8 @@
180
180
  */
181
181
  import { ipnsValidator } from 'ipns/validator';
182
182
  import { CID } from 'multiformats/cid';
183
- import type { IPNSResolverComponents } from './ipns/resolver.js';
184
- import type { IPNSRouting, IPNSRoutingProgressEvents } from './routing/index.js';
183
+ import type { IPNSResolverComponents } from './ipns/resolver.ts';
184
+ import type { IPNSRouting, IPNSRoutingProgressEvents } from './routing/index.ts';
185
185
  import type { Routing, HeliaEvents } from '@helia/interface';
186
186
  import type { AbortOptions, ComponentLogger, Libp2p, PeerId, PublicKey, TypedEventEmitter } from '@libp2p/interface';
187
187
  import type { Keychain } from '@libp2p/keychain';
@@ -318,7 +318,7 @@ export interface IPNS {
318
318
  */
319
319
  unpublish(keyName: string, options?: AbortOptions): Promise<void>;
320
320
  }
321
- export type { IPNSRouting } from './routing/index.js';
321
+ export type { IPNSRouting } from './routing/index.ts';
322
322
  export type { IPNSRecord } from 'ipns';
323
323
  export interface IPNSComponents {
324
324
  datastore: Datastore;
package/dist/src/index.js CHANGED
@@ -180,10 +180,10 @@
180
180
  */
181
181
  import { ipnsValidator } from 'ipns/validator';
182
182
  import { CID } from 'multiformats/cid';
183
- import { IPNSResolver as IPNSResolverClass } from './ipns/resolver.js';
184
- import { IPNS as IPNSClass } from './ipns.js';
183
+ import { IPNSResolver as IPNSResolverClass } from "./ipns/resolver.js";
184
+ import { IPNS as IPNSClass } from "./ipns.js";
185
185
  import { localStore } from "./local-store.js";
186
- import { helia } from './routing/index.js';
186
+ import { helia } from "./routing/index.js";
187
187
  import { localStoreRouting } from "./routing/local-store.js";
188
188
  export function ipns(components, options = {}) {
189
189
  return new IPNSClass(components, options);
@@ -1,7 +1,7 @@
1
1
  import { CID } from 'multiformats/cid';
2
- import type { IPNSPublishResult, PublishOptions } from '../index.js';
3
- import type { LocalStore } from '../local-store.js';
4
- import type { IPNSRouting } from '../routing/index.js';
2
+ import type { IPNSPublishResult, PublishOptions } from '../index.ts';
3
+ import type { LocalStore } from '../local-store.ts';
4
+ import type { IPNSRouting } from '../routing/index.ts';
5
5
  import type { AbortOptions, ComponentLogger, Libp2p, PeerId, PublicKey } from '@libp2p/interface';
6
6
  import type { Keychain } from '@libp2p/keychain';
7
7
  import type { Datastore } from 'interface-datastore';
@@ -1,5 +1,5 @@
1
- import type { LocalStore } from '../local-store.js';
2
- import type { IPNSRouting } from '../routing/index.js';
1
+ import type { LocalStore } from '../local-store.ts';
2
+ import type { IPNSRouting } from '../routing/index.ts';
3
3
  import type { ComponentLogger, Libp2p } from '@libp2p/interface';
4
4
  import type { Keychain } from '@libp2p/keychain';
5
5
  export interface IPNSRepublisherComponents {
@@ -1,7 +1,7 @@
1
1
  import { Queue, repeatingTask } from '@libp2p/utils';
2
2
  import { createIPNSRecord, marshalIPNSRecord, unmarshalIPNSRecord } from 'ipns';
3
3
  import { DEFAULT_REPUBLISH_CONCURRENCY, DEFAULT_REPUBLISH_INTERVAL_MS, DEFAULT_TTL_NS } from "../constants.js";
4
- import { shouldRepublish } from '../utils.js';
4
+ import { shouldRepublish } from "../utils.js";
5
5
  export class IPNSRepublisher {
6
6
  routers;
7
7
  localStore;
@@ -1,7 +1,7 @@
1
1
  import { CID } from 'multiformats/cid';
2
- import type { IPNSResolveResult, ResolveOptions } from '../index.js';
3
- import type { LocalStore } from '../local-store.js';
4
- import type { IPNSRouting } from '../routing/index.js';
2
+ import type { IPNSResolveResult, ResolveOptions } from '../index.ts';
3
+ import type { LocalStore } from '../local-store.ts';
4
+ import type { IPNSRouting } from '../routing/index.ts';
5
5
  import type { Routing } from '@helia/interface';
6
6
  import type { ComponentLogger, PeerId, PublicKey } from '@libp2p/interface';
7
7
  import type { Datastore } from 'interface-datastore';
@@ -7,8 +7,8 @@ import { base58btc } from 'multiformats/bases/base58';
7
7
  import { CID } from 'multiformats/cid';
8
8
  import * as Digest from 'multiformats/hashes/digest';
9
9
  import { DEFAULT_TTL_NS } from "../constants.js";
10
- import { InvalidValueError, RecordNotFoundError, RecordsFailedValidationError, UnsupportedMultibasePrefixError, UnsupportedMultihashCodecError } from '../errors.js';
11
- import { isCodec, IDENTITY_CODEC, SHA2_256_CODEC, isLibp2pCID } from '../utils.js';
10
+ import { InvalidValueError, RecordNotFoundError, RecordsFailedValidationError, UnsupportedMultibasePrefixError, UnsupportedMultihashCodecError } from "../errors.js";
11
+ import { isCodec, IDENTITY_CODEC, SHA2_256_CODEC, isLibp2pCID } from "../utils.js";
12
12
  const bases = {
13
13
  [base36.prefix]: base36,
14
14
  [base58btc.prefix]: base58btc
@@ -1,6 +1,6 @@
1
1
  import { CID } from 'multiformats/cid';
2
- import type { IPNSComponents, IPNS as IPNSInterface, IPNSOptions, IPNSPublishResult, IPNSResolveResult, PublishOptions, ResolveOptions } from './index.js';
3
- import type { IPNSRouting } from './routing/index.js';
2
+ import type { IPNSComponents, IPNS as IPNSInterface, IPNSOptions, IPNSPublishResult, IPNSResolveResult, PublishOptions, ResolveOptions } from './index.ts';
3
+ import type { IPNSRouting } from './routing/index.ts';
4
4
  import type { AbortOptions, PeerId, PublicKey, Startable } from '@libp2p/interface';
5
5
  import type { MultihashDigest } from 'multiformats/hashes/interface';
6
6
  export declare class IPNS implements IPNSInterface, Startable {
package/dist/src/ipns.js CHANGED
@@ -2,8 +2,8 @@ import { CID } from 'multiformats/cid';
2
2
  import { IPNSPublisher } from "./ipns/publisher.js";
3
3
  import { IPNSRepublisher } from "./ipns/republisher.js";
4
4
  import { IPNSResolver } from "./ipns/resolver.js";
5
- import { localStore } from './local-store.js';
6
- import { helia } from './routing/helia.js';
5
+ import { localStore } from "./local-store.js";
6
+ import { helia } from "./routing/helia.js";
7
7
  import { localStoreRouting } from "./routing/local-store.js";
8
8
  export class IPNS {
9
9
  routers;
@@ -1,5 +1,5 @@
1
- import { IPNSPublishMetadata } from './pb/metadata.js';
2
- import type { DatastoreProgressEvents, GetOptions, PutOptions } from './routing/index.js';
1
+ import { IPNSPublishMetadata } from './pb/metadata.ts';
2
+ import type { DatastoreProgressEvents, GetOptions, PutOptions } from './routing/index.ts';
3
3
  import type { AbortOptions, Logger } from '@libp2p/interface';
4
4
  import type { Datastore } from 'interface-datastore';
5
5
  export interface GetResult {
@@ -2,8 +2,8 @@ import { Record } from '@libp2p/kad-dht';
2
2
  import { CustomProgressEvent } from 'progress-events';
3
3
  import { equals as uint8ArrayEquals } from 'uint8arrays/equals';
4
4
  import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
5
- import { IPNSPublishMetadata } from './pb/metadata.js';
6
- import { dhtRoutingKey, DHT_RECORD_PREFIX, ipnsMetadataKey } from './utils.js';
5
+ import { IPNSPublishMetadata } from "./pb/metadata.js";
6
+ import { dhtRoutingKey, DHT_RECORD_PREFIX, ipnsMetadataKey } from "./utils.js";
7
7
  /**
8
8
  * Read/write IPNS records to the datastore as DHT records.
9
9
  *
@@ -6,7 +6,16 @@ export interface IPNSPublishMetadata {
6
6
  }
7
7
  export declare namespace IPNSPublishMetadata {
8
8
  const codec: () => Codec<IPNSPublishMetadata>;
9
- const encode: (obj: Partial<IPNSPublishMetadata>) => Uint8Array;
10
- const decode: (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<IPNSPublishMetadata>) => IPNSPublishMetadata;
9
+ interface IPNSPublishMetadataKeyNameFieldEvent {
10
+ field: '$.keyName';
11
+ value: string;
12
+ }
13
+ interface IPNSPublishMetadataLifetimeFieldEvent {
14
+ field: '$.lifetime';
15
+ value: number;
16
+ }
17
+ function encode(obj: Partial<IPNSPublishMetadata>): Uint8Array;
18
+ function decode(buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<IPNSPublishMetadata>): IPNSPublishMetadata;
19
+ function stream(buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<IPNSPublishMetadata>): Generator<IPNSPublishMetadataKeyNameFieldEvent | IPNSPublishMetadataLifetimeFieldEvent>;
11
20
  }
12
21
  //# sourceMappingURL=metadata.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../../../src/pb/metadata.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,yBAAiB,mBAAmB,CAAC;IAG5B,MAAM,KAAK,QAAO,KAAK,CAAC,mBAAmB,CAoDjD,CAAA;IAEM,MAAM,MAAM,GAAI,KAAK,OAAO,CAAC,mBAAmB,CAAC,KAAG,UAE1D,CAAA;IAEM,MAAM,MAAM,GAAI,KAAK,UAAU,GAAG,cAAc,EAAE,OAAO,aAAa,CAAC,mBAAmB,CAAC,KAAG,mBAEpG,CAAA;CACF"}
1
+ {"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../../../src/pb/metadata.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,yBAAiB,mBAAmB,CAAC;IAG5B,MAAM,KAAK,QAAO,KAAK,CAAC,mBAAmB,CA+EjD,CAAA;IAED,UAAiB,oCAAoC;QACnD,KAAK,EAAE,WAAW,CAAA;QAClB,KAAK,EAAE,MAAM,CAAA;KACd;IAED,UAAiB,qCAAqC;QACpD,KAAK,EAAE,YAAY,CAAA;QACnB,KAAK,EAAE,MAAM,CAAA;KACd;IAED,SAAgB,MAAM,CAAE,GAAG,EAAE,OAAO,CAAC,mBAAmB,CAAC,GAAG,UAAU,CAErE;IAED,SAAgB,MAAM,CAAE,GAAG,EAAE,UAAU,GAAG,cAAc,EAAE,IAAI,CAAC,EAAE,aAAa,CAAC,mBAAmB,CAAC,GAAG,mBAAmB,CAExH;IAED,SAAgB,MAAM,CAAE,GAAG,EAAE,UAAU,GAAG,cAAc,EAAE,IAAI,CAAC,EAAE,aAAa,CAAC,mBAAmB,CAAC,GAAG,SAAS,CAAC,oCAAoC,GAAG,qCAAqC,CAAC,CAE5L;CACF"}
@@ -1,4 +1,4 @@
1
- import { decodeMessage, encodeMessage, message } from 'protons-runtime';
1
+ import { decodeMessage, encodeMessage, message, streamMessage } from 'protons-runtime';
2
2
  export var IPNSPublishMetadata;
3
3
  (function (IPNSPublishMetadata) {
4
4
  let _codec;
@@ -43,15 +43,46 @@ export var IPNSPublishMetadata;
43
43
  }
44
44
  }
45
45
  return obj;
46
+ }, function* (reader, length, prefix, opts = {}) {
47
+ const end = length == null ? reader.len : reader.pos + length;
48
+ while (reader.pos < end) {
49
+ const tag = reader.uint32();
50
+ switch (tag >>> 3) {
51
+ case 1: {
52
+ yield {
53
+ field: `${prefix}.keyName`,
54
+ value: reader.string()
55
+ };
56
+ break;
57
+ }
58
+ case 2: {
59
+ yield {
60
+ field: `${prefix}.lifetime`,
61
+ value: reader.uint32()
62
+ };
63
+ break;
64
+ }
65
+ default: {
66
+ reader.skipType(tag & 7);
67
+ break;
68
+ }
69
+ }
70
+ }
46
71
  });
47
72
  }
48
73
  return _codec;
49
74
  };
50
- IPNSPublishMetadata.encode = (obj) => {
75
+ function encode(obj) {
51
76
  return encodeMessage(obj, IPNSPublishMetadata.codec());
52
- };
53
- IPNSPublishMetadata.decode = (buf, opts) => {
77
+ }
78
+ IPNSPublishMetadata.encode = encode;
79
+ function decode(buf, opts) {
54
80
  return decodeMessage(buf, IPNSPublishMetadata.codec(), opts);
55
- };
81
+ }
82
+ IPNSPublishMetadata.decode = decode;
83
+ function stream(buf, opts) {
84
+ return streamMessage(buf, IPNSPublishMetadata.codec(), opts);
85
+ }
86
+ IPNSPublishMetadata.stream = stream;
56
87
  })(IPNSPublishMetadata || (IPNSPublishMetadata = {}));
57
88
  //# sourceMappingURL=metadata.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"metadata.js","sourceRoot":"","sources":["../../../src/pb/metadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AASvE,MAAM,KAAW,mBAAmB,CAgEnC;AAhED,WAAiB,mBAAmB;IAClC,IAAI,MAAkC,CAAA;IAEzB,yBAAK,GAAG,GAA+B,EAAE;QACpD,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;YACnB,MAAM,GAAG,OAAO,CAAsB,CAAC,GAAG,EAAE,CAAC,EAAE,IAAI,GAAG,EAAE,EAAE,EAAE;gBAC1D,IAAI,IAAI,CAAC,eAAe,KAAK,KAAK,EAAE,CAAC;oBACnC,CAAC,CAAC,IAAI,EAAE,CAAA;gBACV,CAAC;gBAED,IAAI,CAAC,GAAG,CAAC,OAAO,IAAI,IAAI,IAAI,GAAG,CAAC,OAAO,KAAK,EAAE,CAAC,EAAE,CAAC;oBAChD,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;oBACZ,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;gBACvB,CAAC;gBAED,IAAI,CAAC,GAAG,CAAC,QAAQ,IAAI,IAAI,IAAI,GAAG,CAAC,QAAQ,KAAK,CAAC,CAAC,EAAE,CAAC;oBACjD,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;oBACZ,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;gBACxB,CAAC;gBAED,IAAI,IAAI,CAAC,eAAe,KAAK,KAAK,EAAE,CAAC;oBACnC,CAAC,CAAC,MAAM,EAAE,CAAA;gBACZ,CAA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AAE,GAAG,MAAM,UAAU;gCAC1B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE;6BACvB,CAAA;4BACD,MAAK;wBACP,CAAC;wBACD,KAAK,CAAC,CAAC,CAAC,CAAC;4BACP,MAAM;gCACJ,KAAK,EAAE,GAAG,MAAM,WAAW;gCAC3B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE;6BACvB,CAAA;4BACD,MAAK;wBACP,CAAC;wBACD,OAAO,CAAC,CAAC,CAAC;4BACR,MAAM,CAAC,QAAQ,CAAC,GAAG,GAAG,CAAC,CAAC,CAAA;4BACxB,MAAK;wBACP,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC,CAAC,CAAA;QACJ,CAAC;QAED,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;IAYD,SAAgB,MAAM,CAAE,GAAiC;QACvD,OAAO,aAAa,CAAC,GAAG,EAAE,mBAAmB,CAAC,KAAK,EAAE,CAAC,CAAA;IACxD,CAAC;IAFe,0BAAM,SAErB,CAAA;IAED,SAAgB,MAAM,CAAE,GAAgC,EAAE,IAAyC;QACjG,OAAO,aAAa,CAAC,GAAG,EAAE,mBAAmB,CAAC,KAAK,EAAE,EAAE,IAAI,CAAC,CAAA;IAC9D,CAAC;IAFe,0BAAM,SAErB,CAAA;IAED,SAAgB,MAAM,CAAE,GAAgC,EAAE,IAAyC;QACjG,OAAO,aAAa,CAAC,GAAG,EAAE,mBAAmB,CAAC,KAAK,EAAE,EAAE,IAAI,CAAC,CAAA;IAC9D,CAAC;IAFe,0BAAM,SAErB,CAAA;AACH,CAAC,EAzGgB,mBAAmB,KAAnB,mBAAmB,QAyGnC"}
@@ -1,5 +1,5 @@
1
- import type { GetOptions, PutOptions } from './index.js';
2
- import type { IPNSRouting } from '../index.js';
1
+ import type { GetOptions, PutOptions } from './index.ts';
2
+ import type { IPNSRouting } from '../index.ts';
3
3
  import type { Routing } from '@helia/interface';
4
4
  import type { ProgressEvent } from 'progress-events';
5
5
  export interface HeliaRoutingComponents {
@@ -1,6 +1,6 @@
1
- import type { HeliaRoutingProgressEvents } from './helia.js';
2
- import type { DatastoreProgressEvents } from '../index.js';
3
- import type { PubSubProgressEvents } from './pubsub.js';
1
+ import type { HeliaRoutingProgressEvents } from './helia.ts';
2
+ import type { DatastoreProgressEvents } from '../index.ts';
3
+ import type { PubSubProgressEvents } from './pubsub.ts';
4
4
  import type { IPNSPublishMetadata } from '../pb/metadata.ts';
5
5
  import type { AbortOptions } from '@libp2p/interface';
6
6
  import type { ProgressOptions } from 'progress-events';
@@ -23,7 +23,7 @@ export type { DatastoreProgressEvents };
23
23
  export type { HeliaRoutingProgressEvents };
24
24
  export type { PubSubProgressEvents };
25
25
  export type IPNSRoutingProgressEvents = DatastoreProgressEvents | HeliaRoutingProgressEvents | PubSubProgressEvents;
26
- export { helia } from './helia.js';
27
- export { pubsub } from './pubsub.js';
28
- export type { PubsubRoutingComponents, PubSub, Message, PublishResult, PubSubEvents } from './pubsub.js';
26
+ export { helia } from './helia.ts';
27
+ export { pubsub } from './pubsub.ts';
28
+ export type { PubsubRoutingComponents, PubSub, Message, PublishResult, PubSubEvents } from './pubsub.ts';
29
29
  //# sourceMappingURL=index.d.ts.map
@@ -1,3 +1,3 @@
1
- export { helia } from './helia.js';
2
- export { pubsub } from './pubsub.js';
1
+ export { helia } from "./helia.js";
2
+ export { pubsub } from "./pubsub.js";
3
3
  //# sourceMappingURL=index.js.map
@@ -1,6 +1,8 @@
1
- import type { IPNSRouting } from './index.js';
2
- import type { PeerId, TypedEventTarget, ComponentLogger } from '@libp2p/interface';
1
+ import type { GetOptions, IPNSRouting, PutOptions } from './index.ts';
2
+ import type { Fetch } from '@libp2p/fetch';
3
+ import type { PeerId, PublicKey, TypedEventTarget, ComponentLogger, Startable, Metrics, Libp2p } from '@libp2p/interface';
3
4
  import type { Datastore } from 'interface-datastore';
5
+ import type { MultihashDigest } from 'multiformats/hashes/interface';
4
6
  import type { ProgressEvent } from 'progress-events';
5
7
  export interface Message {
6
8
  type: 'signed' | 'unsigned';
@@ -8,7 +10,16 @@ export interface Message {
8
10
  topic: string;
9
11
  data: Uint8Array;
10
12
  }
13
+ export interface Subscription {
14
+ topic: string;
15
+ subscribe: boolean;
16
+ }
17
+ export interface SubscriptionChangeData {
18
+ peerId: PeerId;
19
+ subscriptions: Subscription[];
20
+ }
11
21
  export interface PubSubEvents {
22
+ 'subscription-change': CustomEvent<SubscriptionChangeData>;
12
23
  message: CustomEvent<Message>;
13
24
  }
14
25
  export interface PublishResult {
@@ -24,12 +35,31 @@ export interface PubSub extends TypedEventTarget<PubSubEvents> {
24
35
  export interface PubsubRoutingComponents {
25
36
  datastore: Datastore;
26
37
  logger: ComponentLogger;
27
- libp2p: {
28
- peerId: PeerId;
29
- services: {
30
- pubsub: PubSub;
31
- };
32
- };
38
+ metrics?: Metrics;
39
+ libp2p: Pick<Libp2p<{
40
+ pubsub: PubSub;
41
+ fetch?: Fetch;
42
+ }>, 'peerId' | 'register' | 'unregister' | 'services'>;
43
+ }
44
+ export interface PubsubRoutingInit {
45
+ /**
46
+ * How many fetch requests to run concurrently
47
+ *
48
+ * @default 8
49
+ */
50
+ fetchConcurrency?: number;
51
+ /**
52
+ * How long to allow a fetch request to run for in ms
53
+ *
54
+ * @default 2_500
55
+ */
56
+ fetchTimeout?: number;
57
+ /**
58
+ * How many ms to wait before sending a fetch request to a topic peer
59
+ *
60
+ * @default 0
61
+ */
62
+ fetchDelay?: number;
33
63
  }
34
64
  export type PubSubProgressEvents = ProgressEvent<'ipns:pubsub:publish', {
35
65
  topic: string;
@@ -37,6 +67,41 @@ export type PubSubProgressEvents = ProgressEvent<'ipns:pubsub:publish', {
37
67
  }> | ProgressEvent<'ipns:pubsub:subscribe', {
38
68
  topic: string;
39
69
  }> | ProgressEvent<'ipns:pubsub:error', Error>;
70
+ export declare class PubSubRouting implements IPNSRouting, Startable {
71
+ #private;
72
+ private readonly subscriptions;
73
+ private readonly localStore;
74
+ private readonly libp2p;
75
+ private readonly fetchConcurrency;
76
+ private readonly fetchTimeout;
77
+ private readonly fetchDelay;
78
+ private readonly fetchQueue;
79
+ private readonly fetchPeers;
80
+ private shutdownController;
81
+ private fetchTopologyId?;
82
+ constructor(components: PubsubRoutingComponents, init?: PubsubRoutingInit);
83
+ /**
84
+ * Put a value to the pubsub datastore indexed by the received key properly encoded
85
+ */
86
+ put(routingKey: Uint8Array, marshaledRecord: Uint8Array, options?: PutOptions): Promise<void>;
87
+ /**
88
+ * Get a value from the pubsub datastore indexed by the received key properly encoded.
89
+ * Also, the identifier topic is subscribed to and the pubsub datastore records will be
90
+ * updated once new publishes occur
91
+ */
92
+ get(routingKey: Uint8Array, options?: GetOptions): Promise<Uint8Array>;
93
+ /**
94
+ * Get pubsub subscriptions related to ipns
95
+ */
96
+ getSubscriptions(): string[];
97
+ /**
98
+ * Cancel pubsub subscriptions related to ipns
99
+ */
100
+ cancel(key: PublicKey | MultihashDigest<0x00 | 0x12>): void;
101
+ toString(): string;
102
+ start(): Promise<void>;
103
+ stop(): void;
104
+ }
40
105
  /**
41
106
  * This IPNS routing receives IPNS record updates via dedicated
42
107
  * pubsub topic.
@@ -45,5 +110,5 @@ export type PubSubProgressEvents = ProgressEvent<'ipns:pubsub:publish', {
45
110
  * updated records, so the first call to `.get` should be expected
46
111
  * to fail!
47
112
  */
48
- export declare function pubsub(components: PubsubRoutingComponents): IPNSRouting;
113
+ export declare function pubsub(components: PubsubRoutingComponents, init?: PubsubRoutingInit): IPNSRouting;
49
114
  //# sourceMappingURL=pubsub.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pubsub.d.ts","sourceRoot":"","sources":["../../../src/routing/pubsub.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAc,WAAW,EAAc,MAAM,YAAY,CAAA;AAErE,OAAO,KAAK,EAAE,MAAM,EAAa,gBAAgB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAC7F,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBA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