///
import * as events from "events";
import { Service, Executor, Logger, ConsoleLogger, Context, HttpContext } from "./index";
import { CoreModelDefinition } from "./models/coremodel";
/**
* @hidden
*/
declare const _extend: any;
interface Configuration {
[key: string]: any;
}
export interface RequestFilter {
checkCSRF(context: Context): Promise;
}
export declare function Bean(constructor: Function): void;
export declare function Route(route: string, methods?: string | string[], allowPath?: boolean, swagger?: any): (target: any, executor: string, descriptor: PropertyDescriptor) => void;
/**
* This is the main class of the framework, it handles the routing, the services initialization and resolution
*
* @class Webda
*/
declare class Webda extends events.EventEmitter {
/**
* Webda Services
* @hidden
*/
_services: Map;
/**
* Init promise to ensure, webda is initiated
* Used for init() method
*/
protected _init: Promise;
/**
* Known modules
* @hidden
*/
_modules: any;
/**
* Configuration loaded from webda.config.json
* @hidden
*/
_config: Configuration;
/**
* Old route helpers to allow direct URL behaviors
*
* It is not **deprecated** per say but we advise to use [[Service]] instead
*/
protected _routehelpers: any;
/**
* Models that can be retrieved with [[Webda.getModel]]
* @hidden
*/
_models: Map;
/**
* JSON Schema validator instance
*/
protected _ajv: any;
/**
* JSON Schema registry
*/
protected _ajvSchemas: any;
/**
* Current executor
*/
protected _currentExecutor: any;
protected _configFile: string;
protected _initPromise: Promise;
/**
* Loggers registry
* @hidden
*/
_loggers: Logger[];
protected _initTime: number;
/**
* Console logger
* @hidden
*/
_logger: ConsoleLogger;
/**
* CORS Filter registry
*
* Added via [[Webda.registerCorsFilter]]
* See [[CorsFilter]]
*/
protected _requestFilters: RequestFilter[];
/**
* @params {Object} config - The configuration Object, if undefined will load the configuration file
*/
constructor(config?: any);
initBeanRoutes(serviceBean: Service): void;
reinitResolvedRoutes(): void;
/**
* Init Webda
*
* It will resolve Services init method and autolink
*/
init(): Promise;
registerCorsFilter(filter: any): void;
registerRequestFilter(filter: any): void;
/**
* Load the modules,
*
* @protected
* @ignore Useless for documentation
*/
_loadModules(): void;
/**
*
* @param {Object} executor The executor to expose as executor
* @param {String} code to execute
*/
sandbox(executor: any, code: any): any;
/**
* Load the module,
*
* @protected
* @ignore Useless for documentation
*/
_loadModule(info: any, parent: any): void;
/**
* Validate the object with schema
*
* @param object to validate
* @param schema path to use
*/
validate(object: any, schema: any): any;
/**
* Get last errors from AJV schema validator ( called through validate method )
*/
validationLastErrors(): any;
/**
* Load the configuration,
*
* @protected
* @ignore Useless for documentation
* @param {Object|String}
*/
loadConfiguration(config?: any): Configuration;
migrateConfig(config: Configuration): Configuration;
/**
* Return webda current version
*
* @returns package version
* @since 0.4.0
*/
getVersion(): string;
/**
* To define the locales just add a locales: ['en-GB', 'fr-FR'] in your host global configuration
*
* @return The configured locales or "en-GB" if none are defined
*/
getLocales(): string[];
/**
* Add a route dynamicaly
*
* @param {String} url of the route can contains dynamic part like {uuid}
* @param {Object} info the type of executor
*/
addRoute(url: any, info: any): void;
/**
* Remove a route dynamicly
*
* @param {String} url to remove
*/
removeRoute(url: any): void;
/**
* Check for a service name and return the wanted singleton or undefined if none found
*
* @param {String} name The service name to retrieve
*/
getService(name: string): Service;
getTypedService(service: string): T;
/**
* Return a map of defined services
* @returns {{}}
*/
getServices(): Map;
/**
* Return a map of all known services modda
* @param type The type of implementation if null all moddas
* @returns {{}}
*/
getModdas(type?: any): {};
/**
* Return a map of services that extends type
* @param type The type of implementation
* @returns {{}}
*/
getServicesImplementations(type: any): Map;
/**
* Return a map of defined stores
* @returns {{}}
*/
getStores(): Map;
/**
* Return a map of defined models
* @returns {{}}
*/
getModels(): Map;
/**
* Register model
*/
registerModel(name: string, clazz: any): void;
/**
* Check for a model name and return the wanted class or throw exception if none found
*
* @param {String} name The model name to retrieve
*/
getModel(name: any): any;
/**
* Get all method for a specific url
* @param config
* @param method
* @param url
*/
getRouteMethodsFromUrl(url: any): string[];
/**
* Get the route from a method / url
*/
private getRouteFromUrl;
/**
* Get the executor corresponding to a request
* It can be usefull in unit test so you can test the all stack
*
* @protected
* @param {String} vhost The host for the request
* @param {String} method The http method
* @param {String} url The url path
* @param {String} protocol http or https
* @param {String} port Port can be usefull for auto redirection
* @param {Object} headers The headers of the request
*/
getExecutorWithContext(ctx: Context): Executor;
/**
* Get the executor corresponding to a request
* It can be usefull in unit test so you can test the all stack
*
* @protected
* @param {String} vhost The host for the request
* @param {String} method The http method
* @param {String} url The url path
* @param {String} protocol http or https
* @param {String} port Port can be usefull for auto redirection
* @param {Object} headers The headers of the request
*/
protected getExecutor(ctx: Context, vhost: string, method: string, url: string, protocol: string, port?: number, headers?: {}): Executor;
/**
* This should return a "turning" secret with cache and a service to modify it every x mins
* WARNING The security is lower without this "turning" secret, you can still set the global.secret parameter
*
* Dont rely on this method, it will probably disapear to avoid secret leak
*
* @deprecated
* @returns {String} Current secret
*/
getSecret(): string;
/**
* Return a salt to use when doing digest
*
* @returns {String} Current salt
*/
getSalt(): string;
/**
* @hidden
*/
protected getServiceWithRoute(ctx: Context, route: any): Executor;
/**
* @hidden
*/
protected initURITemplates(config: Configuration): void;
/**
* Flush the headers to the response, no more header modification is possible after that
* @abstract
*/
flushHeaders(context: Context): void;
/**
* Flush the entire response to the client
*/
flush(context: Context): void;
/**
* Return if Webda is in debug mode
*/
isDebug(): boolean;
/**
* @hidden
*/
protected extendParams(local: any, wider: any): any;
/**
* Return the global parameters of a domain
*/
getGlobalParams(): any;
reinit(updates: Map): Promise;
protected getServiceParams(service: string): any;
/**
* @hidden
*
*/
protected createServices(excludes?: string[]): void;
/**
* Return all methods that are setters (startsWith("set"))
* @param obj service get setter from
*/
protected _getSetters(obj: any): any[];
/**
* Auto connect services with setters
*/
protected autoConnectServices(): void;
protected jsonFilter(key: string, value: any): any;
protected initStatics(): void;
protected remapRoutes(): void;
/**
* Not usefull anymore
* @deprecated
* @param config
*/
protected initModdas(config: any): void;
protected initModels(config: any): void;
protected comparePath(a: any, b: any): number;
/**
* Create a new context for a request
*
* @class Service
* @param httpContext THe HTTP request context
* @param stream - The request output stream if any
* @return A new context object to pass along
*/
newContext(httpContext: HttpContext, stream?: any, noInit?: boolean): Promise;
/**
* Convert an object to JSON using the Webda json filter
*
* @class Service
* @param {Object} object - The object to export
* @return {String} The export of the strip object ( removed all attribute with _ )
*/
toPublicJSON(object: any): string;
/**
* Emit the event with data and wait for Promise to finish if listener returned a Promise
*/
emitSync(event: any, ...data: any[]): Promise;
/**
* Logs
* @param level
* @param args
*/
log(level: any, ...args: any[]): void;
/**
* Retrieve a global parameter
*/
parameter(name: string): any;
/**
* Verify if an origin is allowed to do request on the API
*
* @param context Context of the request
*/
protected checkCSRF(ctx: Context): Promise;
}
export { Webda, _extend, Configuration };