/// <reference types="node" />
import EventEmitter from 'events';
import React from 'react';
import { QueryLink } from './client_types.js';
import { Observable } from '@apollo/client/index.js';
export type Id = number | string;
export interface LinkPlain<Ref extends Id> {
    id: Ref;
    type_id: Ref;
    from_id?: Ref;
    to_id?: Ref;
    value?: any;
}
export interface LinkRelations<Ref extends Id, L extends Link<Ref>> {
    typed: L[];
    type: L;
    in: L[];
    inByType: {
        [id: string]: L[];
    };
    out: L[];
    outByType: {
        [id: string]: L[];
    };
    from: L;
    to: L;
    value?: any;
    _applies: string[];
    _namespaces: string[];
    ml?: MinilinkCollection<MinilinksGeneratorOptions, L>;
}
export interface LinkHashFields {
    [key: Id]: any;
}
export interface Link<Ref extends Id> extends LinkPlain<Ref>, LinkRelations<Id, Link<Ref>>, LinkHashFields {
    _id?: Id;
    _type_id?: Id;
    _from_id?: Id;
    _to_id?: Id;
    displayId: Id;
}
export type MinilinksQueryOptionAggregate = 'count' | 'sum' | 'avg' | 'min' | 'max';
export interface MinilinksQueryOptions<A = MinilinksQueryOptionAggregate> {
    aggregate?: A;
}
export type MinilinksApplyInput = {
    data: any[];
    deep?: any;
    return?: any;
    [key: string]: any;
};
export interface MinilinksResult<L extends Link<Id>> {
    virtual: {
        [id: Id]: Id;
    };
    virtualCounter: number;
    links: L[];
    types: {
        [id: Id]: L[];
    };
    byId: {
        [id: Id]: L;
    };
    byFrom: {
        [id: Id]: L[];
    };
    byTo: {
        [id: Id]: L[];
    };
    byType: {
        [id: Id]: L[];
    };
    options: MinilinksGeneratorOptions;
    emitter: EventEmitter;
    query(query: QueryLink | Id): L[] | any;
    select(query: QueryLink | Id): L[] | any;
    subscribe(query: QueryLink | Id): Observable<L[] | any>;
    add(linksArray: any[]): {
        anomalies?: MinilinkError[];
        errors?: MinilinkError[];
    };
    remove(idsArray: any[]): {
        anomalies?: MinilinkError[];
        errors?: MinilinkError[];
    };
    _updating: boolean;
    apply(linksArray: any[] | MinilinksApplyInput, applyName?: string, applyOptions?: ApplyOptions): {
        errors?: MinilinkError[];
        anomalies?: MinilinkError[];
    };
    update(linksArray: any[]): {
        errors?: MinilinkError[];
        anomalies?: MinilinkError[];
    };
}
export declare function toPlain<Ref extends Id>(link: any): LinkPlain<Ref>;
export declare class MinilinksLink<Ref extends Id> {
    ml?: MinilinkCollection<any, any>;
    _id: Ref;
    id: Ref;
    _type_id: Ref;
    _from_id?: Ref;
    _to_id?: Ref;
    get type_id(): Ref;
    get from_id(): Ref;
    get to_id(): Ref;
    set type_id(id: Ref);
    set from_id(id: Ref);
    set to_id(id: Ref);
    get typed(): MinilinksLink<Ref>[];
    get type(): MinilinksLink<Ref>[];
    get in(): MinilinksLink<Ref>[];
    get inByType(): MinilinksLink<Ref>[];
    get out(): MinilinksLink<Ref>[];
    get outByType(): MinilinksLink<Ref>[];
    get from(): MinilinksLink<Ref>[];
    get to(): MinilinksLink<Ref>[];
    get displayId(): Id;
    get value(): any;
    string?: any;
    number?: any;
    object?: any;
    _applies: string[];
    _namespaces: string[];
    constructor(link: any);
    toPlain(): LinkPlain<Ref>;
    is(query: QueryLink): boolean;
}
export interface MinilinksGeneratorOptions {
    id: any;
    type_id: any;
    type: any;
    typed: any;
    from_id: any;
    from: any;
    out: any;
    to_id: any;
    to: any;
    in: any;
    inByType: any;
    outByType: any;
    handler?: (link: any, result: any) => any;
    equal: (oldLink: any, newLink: any) => boolean;
    Link: any;
}
export declare const MinilinksGeneratorOptionsDefault: MinilinksGeneratorOptions;
export interface MinilinksInstance<L extends Link<Id>> {
    (linksArray: L[], memory?: MinilinksResult<L>): MinilinksResult<L>;
}
export declare function Minilinks<MGO extends MinilinksGeneratorOptions, L extends Link<Id>>(options: MGO): MinilinksInstance<L>;
export interface MinilinkError extends Error {
}
export interface ApplyReturnOptions {
    [key: string]: ApplyOptions;
}
export interface ApplyOptions {
    return?: ApplyReturnOptions;
    [key: string]: any;
}
export declare class MinilinkCollection<MGO extends MinilinksGeneratorOptions = typeof MinilinksGeneratorOptionsDefault, L extends Link<Id> = Link<Id>> {
    useMinilinksQuery: typeof useMinilinksQuery;
    useMinilinksFilter: typeof useMinilinksFilter;
    useMinilinksApply: typeof useMinilinksApply;
    useMinilinksSubscription: typeof useMinilinksSubscription;
    useMinilinksHandle: typeof useMinilinksHandle;
    virtual: {
        [id: Id]: Id;
    };
    virtualInverted: {
        [id: Id]: Id;
    };
    virtualCounter: number;
    types: {
        [id: Id]: L[];
    };
    byId: {
        [id: Id]: L;
    };
    byFrom: {
        [id: Id]: L[];
    };
    byTo: {
        [id: Id]: L[];
    };
    byType: {
        [id: Id]: L[];
    };
    links: L[];
    options: MGO;
    emitter: EventEmitter;
    query<A>(query: QueryLink | Id, options?: MinilinksQueryOptions<A>): A extends string ? any : L[];
    select(query: QueryLink | Id, options?: MinilinksQueryOptions): L[] | any;
    subscribe(query: QueryLink | Id): Observable<L[] | any>;
    add(linksArray: any[], applyName?: string): {
        anomalies?: MinilinkError[];
        errors?: MinilinkError[];
    };
    remove(idsArray: any[]): {
        anomalies?: MinilinkError[];
        errors?: MinilinkError[];
    };
    _updating: boolean;
    _toPlainLinksArray(linkOrLinks: any, applyOptions: any, plainLinksArray: any, returnLinksPathsById: any): void;
    apply(_input: any[] | MinilinksApplyInput, applyName?: string, applyOptions?: ApplyOptions): {
        errors?: MinilinkError[];
        anomalies?: MinilinkError[];
    };
    update(linksArray: any[]): {
        errors?: MinilinkError[];
        anomalies?: MinilinkError[];
    };
    constructor(options?: MGO, memory?: any);
}
export declare const minilinks: MinilinksInstance<Link<Id>>;
export interface MinilinksHookInstance<L extends Link<Id>> {
    ml: MinilinksResult<L>;
    ref: {
        current: MinilinksResult<L>;
    };
}
export declare function useMinilinksConstruct<L extends Link<Id>>(options?: any): MinilinksHookInstance<L>;
export declare function useMinilinksFilter<L extends Link<Id>, R = any>(ml: any, filter: (currentLink: L, oldLink: L, newLink: L) => boolean, results: (l?: L, ml?: any, oldLink?: L, newLink?: L) => R, interval?: number): R;
export declare function useMinilinksHandle<L extends Link<Id>>(ml: any, handler: (event: any, oldLink: any, newLink: any) => any): void;
export declare function useMinilinksApply<L extends Link<Id>>(ml: any, name: string, data?: L[] | MinilinksApplyInput): any;
export declare function useMinilinksQuery<L extends Link<Id>>(ml: any, query: QueryLink | Id): any;
export declare function useMinilinksSubscription<L extends Link<Id>>(ml: any, query: QueryLink | Id): any;
export declare function useMinilinksGenerator(minilinks?: MinilinkCollection): MinilinkCollection<MinilinksGeneratorOptions, Link<Id>>;
export declare const MinilinksContext: React.Context<MinilinkCollection<MinilinksGeneratorOptions, Link<Id>>>;
export declare function MinilinksProvider({ minilinks: initialMinilinks, children, }: {
    minilinks?: MinilinkCollection;
    children: any;
}): React.JSX.Element;
export declare function useMinilinks(): MinilinkCollection<MinilinksGeneratorOptions, Link<Id>>;
