import { Db, ChangeStream } from "mongodb";
import { TokenUser, Base, mapFunc, finalizeFunc, reduceFunc, UpdateOneMessage, UpdateManyMessage, InsertOrUpdateOneMessage, Role } from "@openiap/openflow-api";
import { ValueRecorder } from "@opentelemetry/api-metrics";
import { Span } from "@opentelemetry/api";
export declare class DatabaseConnection {
    private mongodburl;
    private cli;
    db: Db;
    private _dbname;
    static mongodb_query: ValueRecorder;
    static mongodb_aggregate: ValueRecorder;
    static mongodb_insert: ValueRecorder;
    static mongodb_update: ValueRecorder;
    static mongodb_replace: ValueRecorder;
    static mongodb_delete: ValueRecorder;
    static mongodb_deletemany: ValueRecorder;
    constructor(mongodburl: string, dbname: string);
    static toArray(iterator: any): Promise<any[]>;
    isConnected: boolean;
    /**
     * Connect to MongoDB
     * @returns Promise<void>
     */
    connect(parent?: Span): Promise<void>;
    ListCollections(jwt: string): Promise<any[]>;
    DropCollection(collectionname: string, jwt: string, parent: Span): Promise<void>;
    WellknownIdsArray: string[];
    CleanACL<T extends Base>(item: T, user: TokenUser, parent: Span): Promise<T>;
    Cleanmembers<T extends Role>(item: T, original: T): Promise<T>;
    /**
     * Send a query to the database.
     * @param {any} query MongoDB Query
     * @param {Object} projection MongoDB projection
     * @param {number} top Limit result to X number of results
     * @param {number} skip Skip a number of records (Paging)
     * @param {Object|string} orderby MongoDB orderby, or string with name of a single field to orderby
     * @param {string} collectionname What collection to query
     * @param {string} jwt JWT of user who is making the query, to limit results based on permissions
     * @returns Promise<T[]> Array of results
     */
    query<T extends Base>(query: any, projection: Object, top: number, skip: number, orderby: Object | string, collectionname: string, jwt: string, queryas: string, hint: Object | string, parent: Span): Promise<T[]>;
    GetDocumentVersion<T extends Base>(collectionname: string, id: string, version: number, jwt: string, parent: Span): Promise<T>;
    /**
     * Get a single item based on id
     * @param  {string} id Id to search for
     * @param  {string} collectionname Collection to search
     * @param  {string} jwt JWT of user who is making the query, to limit results based on permissions
     * @returns Promise<T>
     */
    getbyid<T extends Base>(id: string, collectionname: string, jwt: string, parent: Span): Promise<T>;
    /**
     * Do MongoDB aggregation
     * @param  {any} aggregates
     * @param  {string} collectionname
     * @param  {string} jwt
     * @returns Promise
     */
    aggregate<T extends Base>(aggregates: object[], collectionname: string, jwt: string, hint: Object | string, parent: Span): Promise<T[]>;
    /**
     * Do MongoDB watch
     * @param  {any} aggregates
     * @param  {string} collectionname
     * @param  {string} jwt
     * @returns Promise
     */
    watch<T extends Base>(aggregates: object[], collectionname: string, jwt: string): Promise<ChangeStream>;
    /**
     * Do MongoDB map reduce
     * @param  {any} aggregates
     * @param  {string} collectionname
     * @param  {string} jwt
     * @returns Promise
     */
    MapReduce<T>(map: mapFunc, reduce: reduceFunc, finalize: finalizeFunc, query: any, out: string | any, collectionname: string, scope: any, jwt: string): Promise<T[]>;
    /**
     * Create a new document in the database
     * @param  {T} item Item to create
     * @param  {string} collectionname The collection to create item in
     * @param  {number} w Write Concern ( 0:no acknowledgment, 1:Requests acknowledgment, 2: Requests acknowledgment from 2, 3:Requests acknowledgment from 3)
     * @param  {boolean} j Ensure is written to the on-disk journal.
     * @param  {string} jwt JWT of the user, creating the item, to ensure rights and permission
     * @returns Promise<T> Returns the new item added
     */
    InsertOne<T extends Base>(item: T, collectionname: string, w: number, j: boolean, jwt: string, parent: Span): Promise<T>;
    synRawUpdateOne(collection: string, query: any, updatedoc: any, measure: boolean, cb: any): void;
    rawUpdateOne(collection: string, query: any, updatedoc: any, measure: boolean): Promise<void>;
    /**
     * Update entity in database
     * @param  {T} item Item to update
     * @param  {string} collectionname Collection containing item
     * @param  {number} w Write Concern ( 0:no acknowledgment, 1:Requests acknowledgment, 2: Requests acknowledgment from 2, 3:Requests acknowledgment from 3)
     * @param  {boolean} j Ensure is written to the on-disk journal.
     * @param  {string} jwt JWT of user who is doing the update, ensuring rights
     * @returns Promise<T>
     */
    _UpdateOne<T extends Base>(query: any, item: T, collectionname: string, w: number, j: boolean, jwt: string, parent: Span): Promise<T>;
    UpdateOne<T extends Base>(q: UpdateOneMessage, parent: Span): Promise<UpdateOneMessage>;
    /**
    * Update multiple documents in database based on update document
    * @param {any} query MongoDB Query
    * @param  {T} item Update document
    * @param  {string} collectionname Collection containing item
    * @param  {number} w Write Concern ( 0:no acknowledgment, 1:Requests acknowledgment, 2: Requests acknowledgment from 2, 3:Requests acknowledgment from 3)
    * @param  {boolean} j Ensure is written to the on-disk journal.
    * @param  {string} jwt JWT of user who is doing the update, ensuring rights
    * @returns Promise<T>
    */
    UpdateMany<T extends Base>(q: UpdateManyMessage): Promise<UpdateManyMessage>;
    private static InsertOrUpdateOneSemaphore;
    /**
    * Insert or Update depending on document allready exists.
    * @param  {T} item Item to insert or update
    * @param  {string} collectionname Collection containing item
    * @param  {string} uniqeness List of fields to combine for uniqeness
    * @param  {number} w Write Concern ( 0:no acknowledgment, 1:Requests acknowledgment, 2: Requests acknowledgment from 2, 3:Requests acknowledgment from 3)
    * @param  {boolean} j Ensure is written to the on-disk journal.
    * @param  {string} jwt JWT of user who is doing the update, ensuring rights
    * @returns Promise<T>
    */
    InsertOrUpdateOne<T extends Base>(q: InsertOrUpdateOneMessage, parent: Span): Promise<InsertOrUpdateOneMessage>;
    private _DeleteFile;
    /**
     * @param  {string} id id of object to delete
     * @param  {string} collectionname collectionname Collection containing item
     * @param  {string} jwt JWT of user who is doing the delete, ensuring rights
     * @returns Promise<void>
     */
    DeleteOne(id: string | any, collectionname: string, jwt: string): Promise<void>;
    /**
     * @param  {string} id id of object to delete
     * @param  {string} collectionname collectionname Collection containing item
     * @param  {string} jwt JWT of user who is doing the delete, ensuring rights
     * @returns Promise<void>
     */
    DeleteMany(query: string | any, ids: string[], collectionname: string, jwt: string): Promise<number>;
    /**
     * Helper function used to check if field needs to be encrypted
     * @param  {string[]} keys List of fields that needs to be encrypted
     * @param  {string} key Current field
     * @param  {object=null} value value of field, ensuring we can actully encrypt the field
     * @returns boolean
     */
    private _shouldEncryptValue;
    /**
     * Enumerate object, encrypting fields that needs to be encrypted
     * @param  {T} item Item to enumerate
     * @returns T Object with encrypted fields
     */
    encryptentity(item: Base): Base;
    /**
     * Enumerate object, decrypting fields that needs to be decrypted
     * @param  {T} item Item to enumerate
     * @returns T Object with decrypted fields
     */
    decryptentity<T extends Base>(item: T): T;
    /**
     * Create a MongoDB query filtering result based on permission of current user and requested permission
     * @param  {string} jwt JWT of the user creating the query
     * @param  {number[]} bits Permission wanted on objects
     * @returns Object MongoDB query
     */
    getbasequery(jwt: string, field: string, bits: number[]): Object;
    private getbasequeryuserid;
    /**
     * Ensure _type and _acs on object
     * @param  {T} item Object to validate
     * @returns T Validated object
     */
    ensureResource<T extends Base>(item: T): T;
    /**
     * Validated user has rights to perform the requested action ( create is missing! )
     * @param  {TokenUser} user User requesting permission
     * @param  {any} item Item permission is needed on
     * @param  {Rights} action Permission wanted (create, update, delete)
     * @returns boolean Is allowed
     */
    hasAuthorization(user: TokenUser, item: Base, action: number): boolean;
    static replaceAll(target: any, search: any, replacement: any): any;
    /**
     * Helper function to clean item before saving in MongoDB ( normalize ACE rights and remove illegal key $$ )
     * @param  {object} o Item to clean
     * @returns void Clean object
     */
    static traversejsonencode(o: any): void;
    static traversejsondecode(o: any): void;
    SaveUpdateDiff<T extends Base>(q: UpdateOneMessage, user: TokenUser, parent: Span): Promise<number>;
    visit(obj: any, func: any): void;
    SaveDiff(collectionname: string, original: any, item: any, parent: Span): Promise<number>;
    createIndex(collectionname: string, name: string, keypath: any, options: any, parent: Span): Promise<unknown>;
    deleteIndex(collectionname: string, name: string, parent: Span): Promise<unknown>;
    ensureindexes(parent: Span): Promise<void>;
}
