UNPKG

@ethersphere/bee-js

Version:
107 lines (106 loc) 4.02 kB
import { Optional, Uint8ArrayReader } from 'cafe-utility'; import { Bee, BeeRequestOptions, DownloadOptions, UploadOptions, UploadResult } from '..'; import { FeedPayloadResult } from '../modules/feed'; import { Bytes } from '../utils/bytes'; import { BatchId, Reference } from '../utils/typed-bytes'; export declare class Fork { prefix: Uint8Array; node: MantarayNode; constructor(prefix: Uint8Array, node: MantarayNode); static split(a: Fork, b: Fork): Fork; marshal(): Uint8Array; static unmarshal(reader: Uint8ArrayReader, addressLength: number): Fork; } interface MantarayNodeOptions { selfAddress?: Uint8Array; targetAddress?: Uint8Array; obfuscationKey?: Uint8Array; metadata?: Record<string, string> | null; path?: Uint8Array | null; parent?: MantarayNode | null; } export declare class MantarayNode { obfuscationKey: Uint8Array; selfAddress: Uint8Array | null; targetAddress: Uint8Array; metadata: Record<string, string> | undefined | null; path: Uint8Array; forks: Map<number, Fork>; parent: MantarayNode | null; constructor(options?: MantarayNodeOptions); get fullPath(): Uint8Array; get fullPathString(): string; /** * Returns the metadata at the `/` path to access idiomatic properties. */ getRootMetadata(): Optional<Record<string, string>>; /** * Returns the `swarm-index-document` and `swarm-error-document` metadata values. */ getDocsMetadata(): { indexDocument: string | null; errorDocument: string | null; }; /** * Attempts to resolve the manifest as a feed, returning the latest update. */ resolveFeed(bee: Bee, requestOptions?: BeeRequestOptions): Promise<Optional<FeedPayloadResult>>; /** * Gets the binary representation of the node. */ marshal(): Promise<Uint8Array>; /** * Downloads and unmarshals a MantarayNode from the given reference. * * Do not forget calling `loadRecursively` on the returned node to load the entire tree. */ static unmarshal(bee: Bee, reference: Reference | Uint8Array | string, options?: DownloadOptions, requestOptions?: BeeRequestOptions): Promise<MantarayNode>; /** * Unmarshals a MantarayNode from the given data. * * Do not forget calling `loadRecursively` on the returned node to load the entire tree. */ static unmarshalFromData(data: Uint8Array, selfAddress: Uint8Array): MantarayNode; /** * Adds a fork to the node. */ addFork(path: string | Uint8Array, reference: string | Uint8Array | Bytes | Reference, metadata?: Record<string, string> | null): void; /** * Removes a fork from the node. */ removeFork(path: string | Uint8Array): void; /** * Calculates the self address of the node. */ calculateSelfAddress(): Promise<Reference>; /** * Saves the node and its children recursively. */ saveRecursively(bee: Bee, postageBatchId: string | BatchId, options?: UploadOptions, requestOptions?: BeeRequestOptions): Promise<UploadResult>; /** * Loads the node and its children recursively. */ loadRecursively(bee: Bee, options?: DownloadOptions, requestOptions?: BeeRequestOptions): Promise<void>; /** * Finds a node in the tree by its path. */ find(path: string | Uint8Array): MantarayNode | null; /** * Finds the closest node in the tree to the given path. */ findClosest(path: string | Uint8Array, current?: Uint8Array): [MantarayNode, Uint8Array]; /** * Returns an array of all nodes in the tree which have a target address set. * * Must be called after `loadRecursively`. */ collect(nodes?: MantarayNode[]): MantarayNode[]; /** * Returns a path:reference map of all nodes in the tree which have a target address set. * * Must be called after `loadRecursively`. */ collectAndMap(): Record<string, string>; determineType(): number; } export {};