import type * as Express from 'express';
import type * as Db from '../database-layer/db';
import type { Model } from '../config-loader/config-loader';
import type { AnyObject, RequiredField } from './common-types';
declare global {
    namespace Express {
        interface Request {
            tx?: Db.Tx;
            batch?: uriParser.UnparsedRequest[];
        }
    }
}
import * as Bluebird from 'bluebird';
import { TypedError } from 'typed-error';
declare type LFModel = any[];
import * as AbstractSQLCompiler from '@resin/abstract-sql-compiler';
import * as sbvrTypes from '@resin/sbvr-types';
import { PinejsClientCoreFactory } from 'pinejs-client-core';
import { generateODataMetadata } from '../odata-metadata/odata-metadata-generator';
import * as permissions from './permissions';
export * from './permissions';
import * as uriParser from './uri-parser';
export * from './errors';
import { HookBlueprint, InstantiatedHooks } from './hooks';
export declare let db: Db.Database;
export { sbvrTypes };
export { resolveOdataBind } from './abstract-sql';
export declare type ExecutableModel = RequiredField<Model, 'apiRoot' | 'modelText'> | RequiredField<Model, 'apiRoot' | 'abstractSql'>;
interface CompiledModel {
    vocab: string;
    se?: string;
    lf?: LFModel;
    abstractSql: AbstractSQLCompiler.AbstractSqlModel;
    sql: AbstractSQLCompiler.SqlModel;
    odataMetadata: ReturnType<typeof generateODataMetadata>;
}
export interface HookReq {
    user?: User;
    apiKey?: ApiKey;
    method: string;
    url: string;
    query: AnyObject;
    params: AnyObject;
    body: AnyObject;
    custom?: AnyObject;
    tx?: Db.Tx;
    hooks?: InstantiatedHooks<Hooks>;
}
export interface HookArgs {
    req: HookReq;
    request: HookRequest;
    api: PinejsClient;
    tx?: Db.Tx;
}
export declare type HookResponse = PromiseLike<any> | null | void;
export declare type HookRequest = uriParser.ODataRequest;
export interface Hooks {
    PREPARSE?: (options: HookArgs) => HookResponse;
    POSTPARSE?: (options: HookArgs) => HookResponse;
    PRERUN?: (options: HookArgs & {
        tx: Db.Tx;
    }) => HookResponse;
    POSTRUN?: (options: HookArgs & {
        tx: Db.Tx;
        result: any;
    }) => HookResponse;
    PRERESPOND?: (options: HookArgs & {
        tx: Db.Tx;
        result: any;
        res: any;
        data?: any;
    }) => HookResponse;
    'POSTRUN-ERROR'?: (options: HookArgs & {
        error: TypedError | any;
    }) => HookResponse;
}
declare type HookBlueprints = {
    [key in keyof Hooks]: HookBlueprint[];
};
interface VocabHooks {
    [resourceName: string]: HookBlueprints;
}
interface MethodHooks {
    [vocab: string]: VocabHooks;
}
declare const apiHooks: {
    all: MethodHooks;
    GET: MethodHooks;
    PUT: MethodHooks;
    POST: MethodHooks;
    PATCH: MethodHooks;
    MERGE: MethodHooks;
    DELETE: MethodHooks;
    OPTIONS: MethodHooks;
};
export interface Actor {
    permissions?: string[];
}
export interface User extends Actor {
    id: number;
    actor: number;
}
export interface ApiKey extends Actor {
    key: string;
    actor?: number;
}
export declare const resolveSynonym: (request: Pick<uriParser.ODataRequest, 'abstractSqlModel' | 'resourceName' | 'vocabulary'>) => string;
export declare const resolveNavigationResource: (request: Pick<uriParser.ODataRequest, 'resourceName' | 'vocabulary' | 'abstractSqlModel'>, navigationName: string) => string;
export declare const validateModel: (tx: Db.Tx, modelName: string, request?: uriParser.ODataRequest | undefined) => Bluebird<void>;
export declare const generateLfModel: (seModel: string) => LFModel;
export declare const generateAbstractSqlModel: (lfModel: LFModel) => AbstractSQLCompiler.AbstractSqlModel;
export declare const generateModels: (model: ExecutableModel, targetDatabaseEngine: AbstractSQLCompiler.Engines) => CompiledModel;
export declare const executeModel: (tx: Db.Tx, model: ExecutableModel) => Bluebird<void>;
export declare const executeModels: (arg1: Db.Tx, arg2: ExecutableModel[]) => Bluebird<void>;
declare type HookMethod = keyof typeof apiHooks;
export declare const deleteModel: (arg1: string) => Bluebird<void>;
export declare const getID: (vocab: string, request: uriParser.ODataRequest) => string | number | boolean | Date | AbstractSQLCompiler.DateNode | AbstractSQLCompiler.BooleanNode | AbstractSQLCompiler.InNode | AbstractSQLCompiler.AndNode | AbstractSQLCompiler.OrNode | AbstractSQLCompiler.BindNode | AbstractSQLCompiler.CastNode | AbstractSQLCompiler.CoalesceNode | AbstractSQLCompiler.NumberNode | AbstractSQLCompiler.ConcatenateNode | AbstractSQLCompiler.DurationNode | AbstractSQLCompiler.SelectQueryNode | AbstractSQLCompiler.SelectNode | AbstractSQLCompiler.ValuesNode | AbstractSQLCompiler.AbstractSqlType[] | {
    negative?: boolean | undefined;
    day?: number | undefined;
    hour?: number | undefined;
    minute?: number | undefined;
    second?: number | undefined;
} | AbstractSQLCompiler.FromNode | AbstractSQLCompiler.InnerJoinNode | AbstractSQLCompiler.LeftJoinNode | AbstractSQLCompiler.RightJoinNode | AbstractSQLCompiler.FullJoinNode | AbstractSQLCompiler.CrossJoinNode | AbstractSQLCompiler.GroupByNode | AbstractSQLCompiler.UnionQueryNode | undefined;
export declare const runRule: (arg1: string, arg2: string) => Bluebird<PinejsClientCoreFactory.AnyObject>;
export declare type Passthrough = AnyObject & {
    req?: {
        user?: User;
    };
    tx?: Db.Tx;
};
declare const PinejsClient_base: typeof PinejsClientCoreFactory.PinejsClientCore;
export declare class PinejsClient extends PinejsClient_base<PinejsClient, Bluebird<{}>, Bluebird<PinejsClientCoreFactory.PromiseResultTypes>> {
    passthrough: Passthrough;
    _request({ method, url, body, tx, req, custom, }: {
        method: string;
        url: string;
        body?: AnyObject;
        tx?: Db.Tx;
        req?: permissions.PermissionReq;
        custom?: AnyObject;
    }): Bluebird<PinejsClientCoreFactory.PromiseResultTypes>;
}
export declare type LoggingClient = PinejsClient & {
    logger: Console;
};
export declare const api: {
    [vocab: string]: LoggingClient;
};
export declare const runURI: (method: string, uri: string, body?: PinejsClientCoreFactory.AnyObject, tx?: Db.Tx | undefined, req?: permissions.PermissionReq | undefined, custom?: PinejsClientCoreFactory.AnyObject | undefined) => Bluebird<PinejsClientCoreFactory.PromiseResultTypes>;
export declare const getAbstractSqlModel: (request: Pick<uriParser.ODataRequest, 'vocabulary' | 'abstractSqlModel'>) => AbstractSQLCompiler.AbstractSqlModel;
export declare const getAffectedIds: (arg1: {
    req: HookReq;
    request: HookRequest;
    tx: Db.Tx;
}) => Bluebird<number[]>;
export declare const handleODataRequest: Express.Handler;
export declare const executeStandardModels: (arg1: Db.Tx) => Bluebird<void>;
export declare const addSideEffectHook: (method: HookMethod, apiRoot: string, resourceName: string, hooks: Hooks) => void;
export declare const addPureHook: (method: HookMethod, apiRoot: string, resourceName: string, hooks: Hooks) => void;
export declare const setup: (arg1: Express.Application, arg2: Db.Database) => Bluebird<void>;
