UNPKG

rx-nostr

Version:

A library based on RxJS, which allows Nostr applications to easily communicate with relays.

113 lines 4.99 kB
import { MonoTypeOperatorFunction, ObservableInput, OperatorFunction } from 'rxjs'; import { EventVerifier } from './config/verifier.js'; import { MatchFilterOptions } from './nostr/filter.js'; import { EventPacket, LazyFilter, MessagePacket, OkPacket, ReqPacket } from './packet.js'; import * as Nostr from "nostr-typedef"; /** * Remove the events once seen. */ export declare function uniq<P extends EventPacket>(flushes?: ObservableInput<unknown>): MonoTypeOperatorFunction<P>; /** * Create a customizable uniq operator. * * If `keyFn()` returns a non-null key, the key is stored in `Set`. * The operator filters packets with keys already stored. * * The `Set` returned in the second value of the tuple * can be manipulated externally or in optional event handlers. * For example, you can call `Set#clear()` to forget all keys. */ export declare function createUniq<P extends EventPacket, T>(keyFn: (packet: P) => T | null, options?: CreateUniqOptions<T>): [MonoTypeOperatorFunction<P>, Set<T>]; /** * Drop the event if it has already been seen, * then record on which relay the event was seen. */ export declare function tie<P extends EventPacket>(flushes?: ObservableInput<unknown>): OperatorFunction<P, P & { seenOn: Set<string>; }>; /** * Create a customizable tie operator. */ export declare function createTie<P extends EventPacket>(): [ OperatorFunction<P, P & { seenOn: Set<string>; isNew: boolean; }>, Map<string, Set<string>> ]; /** * Only the latest events are allowed to pass. */ export declare function latest<P extends EventPacket>(): MonoTypeOperatorFunction<P>; /** * For each key, only the latest events are allowed to pass. */ export declare function latestEach<P extends EventPacket, K>(key: (packet: P) => K): MonoTypeOperatorFunction<P>; /** * Only events with a valid signature are allowed to pass. */ export declare function verify<P extends EventPacket>(verifier: EventVerifier): MonoTypeOperatorFunction<P>; /** * Only events with given kind are allowed to pass. */ export declare function filterByKind<P extends EventPacket>(kind: number, options?: NotOption): MonoTypeOperatorFunction<P>; /** * Only events with given kinds are allowed to pass. */ export declare function filterByKinds<P extends EventPacket>(kinds: number[], options?: NotOption): MonoTypeOperatorFunction<P>; /** * Filter events based on a REQ filter object. */ export declare function filterBy<P extends EventPacket>(filters: LazyFilter | LazyFilter[], options?: MatchFilterOptions & NotOption): MonoTypeOperatorFunction<P>; /** * Accumulate latest events in order of new arrival (based on `created_at`). */ export declare function timeline<P extends EventPacket>(limit?: number): OperatorFunction<P, P[]>; export declare function sortEvents<P extends EventPacket>(bufferTime: number, compareFn?: (a: P, b: P) => number): MonoTypeOperatorFunction<P>; /** * Remove expired events. See also [NIP-40](https://github.com/nostr-protocol/nips/blob/master/40.md). */ export declare function dropExpiredEvents<P extends EventPacket>(now?: Date): MonoTypeOperatorFunction<P>; export declare function filterByType<T extends Nostr.ToClientMessage.Type>(type: T): OperatorFunction<MessagePacket, MessagePacket & { type: T; }>; /** * Only events with given kind are allowed to pass. */ export declare function filterByEventId<P extends OkPacket>(eventId: string, options?: NotOption): MonoTypeOperatorFunction<P>; /** * Map REQ packets into a single REQ packet. * * It is useful to reduce REQ requests in a time interval. */ export declare function batch( /** Function used for merge REQ filters. Default behavior is simple concatenation. */ mergeFilter?: MergeFilter): OperatorFunction<ReqPacket[], ReqPacket>; /** * Chunk a REQ packet into multiple REQ packets. * * It is useful to avoid to send large REQ filter. */ export declare function chunk(predicate: (f: LazyFilter[]) => boolean, toChunks: (f: LazyFilter[]) => LazyFilter[][]): MonoTypeOperatorFunction<ReqPacket>; export declare function filterAsync<T>(predicate: (x: T, index: number) => Promise<boolean>): MonoTypeOperatorFunction<T>; /** * Almost RxJS's `timeout`, but won't throw. */ export declare function completeOnTimeout<T>(time: number): MonoTypeOperatorFunction<T>; /** * Buffer the received values for a specified time * and return the values in sorted order as possible. */ export declare function sort<T>(bufferTime: number, compareFn: (a: T, b: T) => number): MonoTypeOperatorFunction<T>; export declare function filterBySubId<P extends { subId: string; }>(subId: string, options?: NotOption): OperatorFunction<P, P>; export type MergeFilter = (a: LazyFilter[], b: LazyFilter[]) => LazyFilter[]; export interface CreateUniqOptions<T> { onCache?: (packet: EventPacket, cache: Set<T>) => void; onHit?: (packet: EventPacket, cache: Set<T>) => void; } export interface NotOption { not: boolean; } //# sourceMappingURL=operator.d.ts.map