/**
@license
Copyright 2018 The Advanced REST client authors <arc@mulesoft.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 { ContextChangeRecord, ContextDeleteBulkEvent, ContextDeleteEvent, ContextDeleteRecord, ContextListEvent, ContextListOptions, ContextListResult, ContextReadBulkEvent, ContextReadEvent, ContextUpdateBulkEvent, ContextUpdateEvent, IAuthorizationData, IBulkOperationResult, ICertificate, IHostRule, IUrl } from '@api-client/core/build/browser.js';
import { DBSchema, IDBPDatabase } from 'idb/with-async-ittr';
export type StoreName = 'UrlHistory' | 'WsHistory' | 'AuthCache' | 'Certificates' | 'Hosts' | 'Environments';
export interface IBaseQueryOptions {
    /**
     * The number of records in the response.
     */
    limit?: number;
    /**
     * Whether to use the `descending` order.
     */
    descending?: boolean;
    /**
     * The key to start paginating from.
     */
    startKey?: string;
    /**
     * The number of records to skip before start capturing records.
     */
    skip?: number;
}
export interface IEntityMeta {
    deleted?: boolean;
}
export interface IStoredEntity<T = unknown> {
    meta: IEntityMeta;
    data: T;
}
export interface IGetOptions {
    /**
     * Whether to return a deleted document.
     */
    deleted?: boolean;
}
interface HttpClientDB extends DBSchema {
    UrlHistory: {
        key: string;
        value: IStoredEntity<IUrl>;
    };
    WsHistory: {
        key: string;
        value: IStoredEntity<IUrl>;
    };
    AuthCache: {
        key: string;
        value: IStoredEntity<IAuthorizationData>;
    };
    Certificates: {
        key: string;
        value: IStoredEntity<ICertificate>;
    };
    Hosts: {
        key: string;
        value: IStoredEntity<IHostRule>;
    };
    Environments: {
        key: string;
        value: IStoredEntity<unknown>;
    };
}
/**
 * A base class for all models.
 *
 * All models have to:
 *
 * - have the `key` property that is a unique identifier of the entity. if the entity has duplicated entity it will replace the previous entity.
 */
export declare class Base {
    /**
     * Set with `listen()` method or separately. When set the model dispatch events on this node.
     * When not set the model does not dispatch events.
     */
    eventsTarget: EventTarget;
    /**
     * The name of the store.
     */
    name: StoreName;
    constructor(name: StoreName);
    protected _db?: IDBPDatabase<HttpClientDB>;
    /**
     * Opens the ARC store.
     * @returns The reference to the database
     */
    open(): Promise<IDBPDatabase<HttpClientDB>>;
    /**
     * Database query options for pagination.
     */
    get defaultQueryOptions(): IBaseQueryOptions;
    /**
     * Handles any exception in the model in a unified way.
     * @param e An error object
     * @param noThrow If set the function will not throw error.
     * This allow to do the logic without stopping program.
     */
    protected _handleException(e: Error | unknown, noThrow?: boolean): void;
    /**
     * Deletes current datastore.
     * Note that `name` property must be set before calling this function.
     */
    deleteModel(): Promise<void>;
    /**
     * Checks if event can be processed giving it's cancellation status or if
     * it was dispatched by current element.
     * @param e Event to test
     * @returns True if event is already cancelled or dispatched by self.
     */
    protected _eventCancelled(e: Event): boolean;
    /**
     * Decodes passed page token back to the passed parameters object.
     * @param token The page token value.
     * @return Restored page query parameters or null if error
     */
    decodePageToken(token: string): IBaseQueryOptions | null;
    /**
     * Encodes page parameters into a page token.
     * @param params Parameters to encode
     * @returns Page token
     */
    encodePageToken(params: IBaseQueryOptions): string;
    /**
     * Lists all objects in the store.
     *
     * @param opts Query options.
     * @returns A promise resolved to a list of entities.
     */
    list(opts?: ContextListOptions): Promise<ContextListResult<unknown>>;
    protected _listEntities(db: IDBPDatabase<HttpClientDB>, storeName: StoreName, opts: IBaseQueryOptions): Promise<unknown[]>;
    /**
     * A specialized method to perform an update operation.
     * By default it calls `put()` which replaces the whole object.
     * Implement own logic that can perform a PATCH operation instead, if needed.
     *
     * @param value The object to update.
     */
    update(value: unknown): Promise<ContextChangeRecord<unknown>>;
    put(value: unknown): Promise<ContextChangeRecord<unknown>>;
    putBulk(values: unknown[]): Promise<IBulkOperationResult<ContextChangeRecord<any>>>;
    get(key: string, opts?: IGetOptions): Promise<unknown | undefined>;
    getBulk(keys: string[], opts?: IGetOptions): Promise<IBulkOperationResult<unknown>>;
    delete(key: string): Promise<ContextDeleteRecord | undefined>;
    deleteBulk(keys: string[]): Promise<IBulkOperationResult<ContextDeleteRecord>>;
    restore(key: string): Promise<ContextChangeRecord<unknown> | undefined>;
    restoreBulk(keys: string[]): Promise<(ContextChangeRecord<unknown> | undefined)[]>;
    /**
     * A handler for the model list event. To be setup in the child class.
     */
    protected _listHandler(e: ContextListEvent<unknown>): void;
    protected _readHandler(e: ContextReadEvent<unknown>): void;
    protected _readBulkHandler(e: ContextReadBulkEvent<unknown>): void;
    protected _updateHandler(e: ContextUpdateEvent<any>): void;
    protected _createHandler(e: ContextUpdateEvent<any>): void;
    protected _updateBulkHandler(e: ContextUpdateBulkEvent<any>): void;
    protected _deleteHandler(e: ContextDeleteEvent): void;
    protected _deleteBulkHandler(e: ContextDeleteBulkEvent): void;
    protected _readDeletedRecordKeys(records: ContextDeleteRecord[]): string[];
}
export {};
//# sourceMappingURL=Base.d.ts.map