import { Datastore } from 'interface-datastore'; import { BaseDatastore } from 'datastore-core'; import type { Message, PubSub } from '@libp2p/interface-pubsub'; import type { PeerId } from '@libp2p/interface-peer-id'; import type { SelectFn, ValidateFn } from '@libp2p/interface-dht'; import type { AbortOptions } from 'interface-store'; export interface SubscriptionKeyFn { (key: Uint8Array): Promise | Uint8Array; } /** * DatastorePubsub is responsible for providing an api for pubsub to be used as a datastore with * [TieredDatastore]{@link https://github.com/ipfs/js-datastore-core/blob/master/src/tiered.js} */ export declare class PubSubDatastore extends BaseDatastore { private readonly _pubsub; private readonly _datastore; private readonly _peerId; private readonly _validator; private readonly _selector; private readonly _handleSubscriptionKeyFn?; constructor(pubsub: PubSub, datastore: Datastore, peerId: PeerId, validator: ValidateFn, selector: SelectFn, subscriptionKeyFn?: SubscriptionKeyFn); /** * Publishes a value through pubsub. * * @param {Uint8Array} key - identifier of the value to be published. * @param {Uint8Array} val - value to be propagated. * @param {AbortOptions} [options] */ put(key: Uint8Array, val: Uint8Array, options?: AbortOptions): Promise; /** * Try to subscribe a topic with Pubsub and returns the local value if available */ get(key: Uint8Array, options?: AbortOptions): Promise; /** * Unsubscribe topic */ unsubscribe(key: Uint8Array): void; /** * Get record from local datastore */ _getLocal(key: Uint8Array, options?: AbortOptions): Promise; /** * handles pubsub subscription messages */ _onMessage(evt: CustomEvent): Promise; /** * Store the received record if it is better than the current stored */ _storeIfSubscriptionIsBetter(key: Uint8Array, data: Uint8Array, options?: AbortOptions): Promise; /** * Validate record according to the received validation function */ _validateRecord(key: Uint8Array, value: Uint8Array): Promise; /** * Select the best record according to the received select function */ _selectRecord(key: Uint8Array, records: Uint8Array[]): Promise; /** * Verify if the record received through pubsub is valid and better than the one currently stored */ _isBetter(key: Uint8Array, val: Uint8Array): Promise; /** * add record to datastore */ _storeRecord(key: Uint8Array, data: Uint8Array, options?: AbortOptions): Promise; } //# sourceMappingURL=index.d.ts.map