@fairdatasociety/fdp-lokijs-adapter
Version:
fdp-storage LokiJS DB Adapter
57 lines (56 loc) • 2.88 kB
TypeScript
import { BatchId, Bee, Reference, Signer, Topic } from '@ethersphere/bee-js';
import type { SingleOwnerChunk } from '@ethersphere/bee-js/dist/src/chunk/soc';
import type { ChunkReference } from '@ethersphere/bee-js/dist/src/feed';
import type { EthAddress, HexEthAddress } from '@ethersphere/bee-js/dist/src/utils/eth';
import { Bytes } from './utils';
export declare const FEED_TYPES: readonly ["sequential", "fault-tolerant-stream"];
export declare type FeedData = {
timestamp: number;
reference: ChunkReference;
};
export declare type FeedType = typeof FEED_TYPES[number];
export declare type FeedIndex<T extends FeedType> = T extends 'sequential' ? number : T extends 'fault-tolerant-stream' ? number : never;
export declare type useSwarmFeed<T extends FeedType> = (type: T) => SwarmFeed<T>;
export interface FeedChunk<Index = number> extends SingleOwnerChunk {
index: Index;
reference: Reference;
timestamp: number;
}
export interface SwarmFeedHandler {
readonly type: FeedType;
readonly owner: HexEthAddress;
readonly topic: Topic;
}
/** Interface for feed type classes */
export interface SwarmFeed<Index> {
/** Feed type identifier */
readonly type: FeedType;
/** initialised BeeJS instance */
readonly bee: Bee;
/** get Feed interface with read operations */
makeFeedR(topic: Topic | Uint8Array | string, owner: EthAddress | Uint8Array | string, ...options: any[]): SwarmFeedR<Index>;
/** get Feed interface with write and read operations */
makeFeedRW(topic: Topic | Uint8Array | string, signer: Signer | Uint8Array | string, options?: any): SwarmFeedRW<Index>;
/** Get Single Owner Chunk identifier */
getIdentifier(topic: Bytes<32>, index: Index): Bytes<32>;
}
/** Swarm Feed Read operations */
export interface SwarmFeedR<Index = number> extends SwarmFeedHandler {
getLastIndex(): Promise<Index> | Index;
findLastUpdate(options?: any): Promise<FeedChunk<Index>>;
getUpdate(index: Index): Promise<FeedChunk<Index>>;
getUpdates(indices: Index[]): Promise<FeedChunk<Index>[]>;
}
/** Swarm Feed Read and operations */
export interface SwarmFeedRW<Index = number> extends SwarmFeedR {
setLastUpdate(postageBatchId: string | BatchId, reference: Reference): Promise<Reference>;
setUpdate(index: Index, postageBatchId: string | BatchId, reference: Reference): Promise<Reference>;
}
export declare function extractDataFromSocPayload(payload: Uint8Array): FeedData;
export declare function mapSocToFeed<Index = number>(socChunk: SingleOwnerChunk, index: Index): FeedChunk<Index>;
export declare function assembleSocPayload(reference: ChunkReference, options?: {
at?: number;
}): Uint8Array;
/** Converts feedIndex response to integer */
export declare function fetchIndexToInt(fetchIndex: string): number;
export declare function makeTopic(topic: Uint8Array | string): Topic;