import type { CID } from 'multiformats/cid'; import { CUSTOM_INSPECT_SYMBOL } from '../proving/custom-inspect-symbol.js'; import type { ElementOf, Newable, Opaque, Writable } from 'ts-essentials'; import type { Kind, Type, $, List } from 'hkt-toolbelt'; /** * Represents an [IPLD Data Model](https://ipld.io/) `Null`. */ export declare class NullKind { readonly tag = "null-kind"; readonly value: null; /** * Binds the describe method of the current object to `util.inspect.custom` symbol. * @see {CUSTOM_INSPECT_SYMBOL} * @internal */ private [CUSTOM_INSPECT_SYMBOL]; /** * Return human-readable description of the value. */ describe(): string; } /** * Represents an [IPLD Data Model](https://ipld.io/) `Boolean`. */ export declare class BooleanKind { readonly value: boolean; readonly tag = "boolean-kind"; constructor(value: boolean); /** * Binds the describe method of the current object to `util.inspect.custom` symbol. * @see {CUSTOM_INSPECT_SYMBOL} * @internal */ private [CUSTOM_INSPECT_SYMBOL]; /** * Return human-readable description of the value. */ describe(): string; } /** * Represents an [IPLD Data Model](https://ipld.io/) `Integer`. */ export declare class IntegerKind { readonly value: number; readonly tag = "integer-kind"; constructor(value: number); /** * Binds the describe method of the current object to `util.inspect.custom` symbol. * @see {CUSTOM_INSPECT_SYMBOL} * @internal */ private [CUSTOM_INSPECT_SYMBOL]; /** * Return human-readable description of the value. */ describe(): string; } /** * Represents an [IPLD Data Model](https://ipld.io/) `Float`. */ export declare class FloatKind { readonly value: number; readonly tag = "float-kind"; constructor(value: number); /** * Binds the describe method of the current object to `util.inspect.custom` symbol. * @see {CUSTOM_INSPECT_SYMBOL} * @internal */ private [CUSTOM_INSPECT_SYMBOL]; /** * Return human-readable description of the value. */ describe(): string; } /** * Represents an [IPLD Data Model](https://ipld.io/) `String`. */ export declare class StringKind { readonly value: string; readonly tag = "string-kind"; constructor(value: string); /** * Binds the describe method of the current object to `util.inspect.custom` symbol. * @see {CUSTOM_INSPECT_SYMBOL} * @internal */ private [CUSTOM_INSPECT_SYMBOL]; /** * Return human-readable description of the value. */ describe(): string; } /** * Represents an [IPLD Data Model](https://ipld.io/) `Bytes`. */ export declare class BytesKind { readonly value: Uint8Array; readonly tag = "bytes-kind"; constructor(value: Uint8Array); /** * Binds the describe method of the current object to `util.inspect.custom` symbol. * @see {CUSTOM_INSPECT_SYMBOL} * @internal */ private [CUSTOM_INSPECT_SYMBOL]; /** * Return human-readable description of the value. */ describe(): string; } /** * Represents an [IPLD Data Model](https://ipld.io/) `List`. */ export declare class ListKind { readonly value: Kind[]; readonly tag = "list-kind"; constructor(value: Kind[]); /** * Binds the describe method of the current object to `util.inspect.custom` symbol. * @see {CUSTOM_INSPECT_SYMBOL} * @internal */ private [CUSTOM_INSPECT_SYMBOL]; /** * Return human-readable description of the value. */ describe(): string; } /** * Represents an [IPLD Data Model](https://ipld.io/) `Map`. */ export declare class MapKind { readonly value: Record; readonly tag = "map-kind"; constructor(value: Record); /** * Binds the describe method of the current object to `util.inspect.custom` symbol. * @see {CUSTOM_INSPECT_SYMBOL} * @internal */ private [CUSTOM_INSPECT_SYMBOL]; /** * Return human-readable description of the value. */ describe(): string; } /** * Represents an [IPLD Data Model](https://ipld.io/) `Link`. */ export declare class LinkKind { readonly value: CID; readonly tag = "link-kind"; constructor(value: CID); /** * Binds the describe method of the current object to `util.inspect.custom` symbol. * @see {CUSTOM_INSPECT_SYMBOL} * @internal */ private [CUSTOM_INSPECT_SYMBOL]; /** * Return human-readable description of the value. */ describe(): string; } /** * Constructors of scalar kinds we support. * @see {ScalarKind} */ declare const ScalarKinds: readonly [typeof NullKind, typeof BooleanKind, typeof IntegerKind, typeof StringKind]; /** * HKT type of `InstanceType<_>`. */ interface InstanceTypeKind extends Kind.Kind { f(x: Type._$cast>): InstanceType; } /** * Union of scalar i.e. non-recursive IPLD kinds, that we support here. */ export type ScalarKind = ElementOf<$<$, Writable>>; /** * Determines if the given [IPLD Data Model](https://ipld.io/) kind is `ScalarKind`. * @param input - An instance to be checked. * @return Returns true if ipld is of scalar kind, false otherwise. */ export declare function isScalarKind(input: Kind): input is ScalarKind; /** * Recursive [IPLD Data Model](https://ipld.io/) kinds, i.e. the ones containing other IPLD values. */ type RecursiveKind = ListKind | MapKind; /** * Represents an unsupported scalar kind in a system. * @desc An unsupported scalar kind will indicate that a specific type of scalar value is not supported in the system. */ type UnsupportedScalarKind = FloatKind | BytesKind | LinkKind; /** * All possible [IPLD Data Model](https://ipld.io/) kinds. */ type Kind = ScalarKind | UnsupportedScalarKind | RecursiveKind; /** * Represents an error when the provided JS input could not be presented as an [IPLD Data Model](https://ipld.io/) kind. */ export declare class BadInputError extends Error { constructor(value: any, kind: string); } export declare function fromJS(input: Array): ListKind; export declare function fromJS(input: Record): MapKind; export declare function fromJS(input: string): StringKind; export declare function fromJS(input: number): IntegerKind | FloatKind; export declare function fromJS(input: boolean): BooleanKind; export declare function fromJS(input: unknown): Kind; /** * A string that represents a JSON pointer to a scalar value of an IPLD model block. * @todo Maybe it makes sense to use dot-notation ^ and get rid of '0 */ export type LinearPath = Opaque; /** * Marks `input` string as `LinearPath`. * @see {LinearPath} */ export declare function LinearPath(input: string): LinearPath; export declare namespace LinearPath { var make: (name: string, parent?: string & import("ts-essentials").WithOpaque<"linear-path">) => string & import("ts-essentials").WithOpaque<"linear-path">; var fromElements: (...input: string[]) => string & import("ts-essentials").WithOpaque<"linear-path">; } /** * Element of a linearized IPLD document. */ export declare class LinearElement { readonly path: LinearPath; readonly value: ScalarKind; constructor(path: LinearPath, value: ScalarKind); } /** * Represents an error that is thrown when an unsupported scalar kind is encountered during linearization. */ export declare class UnsupportedScalarKindError extends Error { constructor(kind: UnsupportedScalarKind['tag']); } /** * Converts an IPLD structure to an array of linear elements. * * @param ipld - The IPLD structure to be converted. * @param [parent=""] - The parent path of the IPLD structure. * @returns An array of linear elements. * @throws {UnsupportedScalarKindError} If the IPLD structure contains an unsupported scalar kind. * @throws {UnreachableCaseError} If the IPLD structure contains an unreachable case. Used for exhaustiveness check. */ export declare function toLinearElements(ipld: Kind, parent?: LinearPath): Array; /** * Linearized version of an IPLD document. */ export declare class LinearModel { #private; private constructor(); /** * The number of items in the linearized document. */ get size(): number; /** * Returns an IterableIterator containing key-value pairs of LinearPath and ScalarKind. */ entries(): IterableIterator<[LinearPath, ScalarKind]>; /** * Create a LinearModel from a given IPLD object. * * @param ipld The IPLD object. * @return The LinearModel created from the IPLD object. */ static fromIPLD(ipld: Kind): LinearModel; /** * Creates a new instance of LinearModel from a JavaScript object. * * @param input - The input JavaScript object. * @returns A new instance of LinearModel. */ static fromJS(input: unknown): LinearModel; } export {};