/**
 * Copyright (c) "Neo4j"
 * Neo4j Sweden AB [https://neo4j.com]
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import ResultSummary from './result-summary';
import Record, { RecordShape } from './record';
import { Query, PeekableAsyncIterator } from './types';
import { observer, connectionHolder } from './internal';
import { NumberOrInteger } from './graph-types';
import Integer from './integer';
import { GenericConstructor, Rules } from './mapping.highlevel';
interface GenericQueryResult<R> {
    records: R[];
    summary: ResultSummary;
}
/**
 * The query result is the combination of the {@link ResultSummary} and
 * the array {@link Record[]} produced by the query
 */
interface QueryResult<R extends RecordShape = RecordShape> extends GenericQueryResult<Record<R>> {
}
/**
 * The query result is the combination of the {@link ResultSummary} and
 * an array of mapped objects produced by the query.
 */
interface MappedQueryResult<R> extends GenericQueryResult<R> {
}
/**
 * Interface to observe updates on the Result which is being produced.
 *
 */
interface GenericResultObserver<R> {
    /**
     * Receive the keys present on the record whenever this information is available
     *
     * @param {string[]} keys The keys present on the {@link Record}
     */
    onKeys?: (keys: string[]) => void;
    /**
     * Receive the each record present on the {@link @Result}
     * @param {Record} record The {@link Record} produced
     */
    onNext?: (record: R) => void;
    /**
     * Called when the result is fully received
     * @param {ResultSummary} summary The result summary
     */
    onCompleted?: (summary: ResultSummary) => void;
    /**
     * Called when some error occurs during the result processing or query execution
     * @param {Error} error The error ocurred
     */
    onError?: (error: Error, runError?: boolean) => void;
}
interface ResultObserver<R extends RecordShape = RecordShape> extends GenericResultObserver<Record<R>> {
}
declare class GenericResult<R, T extends GenericQueryResult<R>> implements Promise<T> {
    private readonly _stack;
    private _streamObserverPromise;
    private _p;
    private readonly _query;
    private readonly _parameters;
    private readonly _connectionHolder;
    private _keys;
    private _summary;
    private _error;
    private readonly _watermarks;
    private _mapper;
    private readonly _retry;
    private readonly _ownedObservers;
    private _retriedError;
    /**
     * Inject the observer to be used.
     * @constructor
     * @access private
     * @param {Promise<observer.ResultStreamObserver>} streamObserverPromise
     * @param {mixed} query - Cypher query to execute
     * @param {Object} parameters - Map with parameters to use in query
     * @param {ConnectionHolder} connectionHolder - to be notified when result is either fully consumed or error happened.
     */
    constructor(streamObserverPromise: Promise<observer.ResultStreamObserver>, query: Query, parameters?: any, connectionHolder?: connectionHolder.ConnectionHolder, watermarks?: {
        high: number;
        low: number;
    }, retry?: () => Promise<observer.ResultStreamObserver>);
    as<T extends {} = Object>(rules: Rules): MappedResult<T>;
    as<T extends {} = Object>(genericConstructor: GenericConstructor<T>, rules?: Rules): MappedResult<T>;
    /**
     * Returns a promise for the field keys.
     *
     * *Should not be combined with {@link Result#subscribe} function.*
     *
     * @public
     * @returns {Promise<string[]>} - Field keys, in the order they will appear in records.
     }
     */
    keys(): Promise<string[]>;
    /**
     * Returns a promise for the result summary.
     *
     * *Should not be combined with {@link Result#subscribe} function.*
     *
     * @public
     * @returns {Promise<ResultSummary<T>>} - Result summary.
     *
     */
    summary<T extends NumberOrInteger = Integer>(): Promise<ResultSummary<T>>;
    /**
     * Create and return new Promise
     *
     * @private
     * @return {Promise} new Promise.
     */
    private _getOrCreatePromise;
    /**
     * Provides a async iterator over the records in the result.
     *
     * *Should not be combined with {@link Result#subscribe} or {@link Result#then} functions.*
     *
     * @public
     * @returns {PeekableAsyncIterator<R, ResultSummary>} The async iterator for the Results
     */
    [Symbol.asyncIterator](): PeekableAsyncIterator<R, ResultSummary>;
    /**
     * Waits for all results and calls the passed in function with the results.
     *
     * *Should not be combined with {@link Result#subscribe} function.*
     *
     * @param {function(result: {records:Array<Record>, summary: ResultSummary})} onFulfilled - function to be called
     * when finished.
     * @param {function(error: {message:string, code:string})} onRejected - function to be called upon errors.
     * @return {Promise} promise.
     */
    then<TResult1 = T, TResult2 = never>(onFulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null, onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
    /**
     * Catch errors when using promises.
     *
     * *Should not be combined with {@link Result#subscribe} function.*
     *
     * @param {function(error: Neo4jError)} onRejected - Function to be called upon errors.
     * @return {Promise} promise.
     */
    catch<TResult = never>(onRejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null): Promise<T | TResult>;
    /**
     * Called when finally the result is done
     *
     * *Should not be combined with {@link Result#subscribe} function.*
     * @param {function()|null} onfinally - function when the promise finished
     * @return {Promise} promise.
     */
    [Symbol.toStringTag]: string;
    finally(onfinally?: (() => void) | null): Promise<T>;
    /**
     * Stream records to observer as they come in, this is a more efficient method
     * of handling the results, and allows you to handle arbitrarily large results.
     *
     * @param {Object} observer - Observer object
     * @param {function(keys: string[])} observer.onKeys - handle stream head, the field keys.
     * @param {function(record: Record)} observer.onNext - handle records, one by one.
     * @param {function(summary: ResultSummary)} observer.onCompleted - handle stream tail, the result summary.
     * @param {function(error: {message:string, code:string})} observer.onError - handle errors.
     * @return {void}
     */
    subscribe(observer: GenericResultObserver<R>): void;
    /**
     * Check if this result is active, i.e., neither a summary nor an error has been received by the result.
     * @return {boolean} `true` when neither a summary or nor an error has been received by the result.
     */
    isOpen(): boolean;
    /**
     * Stream records to observer as they come in, this is a more efficient method
     * of handling the results, and allows you to handle arbitrarily large results.
     *
     * @access private
     * @param {GenericResultObserver} observer The observer to send records to.
     * @param {boolean} paused The flag to indicate if the stream should be started paused
     * @returns {Promise<observer.ResultStreamObserver>} The result stream observer.
     */
    _subscribe(observer: GenericResultObserver<R>, paused?: boolean, skipOnCompleted?: boolean): Promise<observer.ResultStreamObserver>;
    /**
     * Decorates the ResultObserver with the necessary methods.
     *
     * @access private
     * @param {ResultObserver} observer The ResultObserver to decorate.
     * @returns The decorated result observer
     */
    _decorateObserver(observer: GenericResultObserver<R>, skipOnCompleted?: boolean): GenericResultObserver<R>;
    /**
     * Signals the stream observer that the future records should be discarded on the server.
     *
     * @protected
     * @since 4.0.0
     * @returns {void}
     */
    _cancel(): void;
    /**
     * @access private
     * @param metadata
     * @returns
     */
    private _releaseConnectionAndGetSummary;
    /**
     * @access private
     */
    private _createQueuedResultObserver;
}
/**
 * A stream of {@link Record} representing the result of a query.
 * Can be consumed eagerly as {@link Promise} resolved with array of records and {@link ResultSummary}
 * summary, or rejected with error that contains {@link string} code and {@link string} message.
 * Alternatively can be consumed lazily using {@link Result#subscribe} function.
 * @access public
 */
declare class Result<R extends RecordShape = RecordShape> extends GenericResult<Record<R>, QueryResult<R>> {
}
/**
 * A stream of mapped Objects representing the result of a query as mapped with a Record Object Mapping function.
 * Can be consumed eagerly as {@link Promise} resolved with array of records and {@link ResultSummary}
 * summary, or rejected with error that contains {@link string} code and {@link string} message.
 * Alternatively can be consumed lazily using {@link MappedResult#subscribe} function.
 * @access public
 */
declare class MappedResult<R> extends GenericResult<R, MappedQueryResult<R>> {
}
export default Result;
export type { MappedQueryResult, QueryResult, ResultObserver, GenericResultObserver };
