import { DBConnector, DBConfig, DBTypes, PageOffset, SQLInterface, ResultSet } from "will-sql"; import { ServiceSchema, ServiceBroker, ServiceActionsSchema } from "moleculer"; export declare type GenericObject = { [name: string]: any; }; declare type EnumFieldTypes = keyof typeof DBTypes; export declare type KnAlias = { [key: string]: string | DBConfig; }; export interface DBField { type: DBTypes | EnumFieldTypes; size?: number; precision?: number; key?: boolean; calculated?: boolean; selected?: boolean; nullable?: boolean; created?: boolean; updated?: boolean; defaultValue?: any; options?: GenericObject; } export interface FieldSetting { [name: string]: DBField; } export interface KnModel { /** * table or schema name */ name: string; /** * alias setting point to database connection */ alias: KnAlias; /** * white list of fields setting */ fields?: FieldSetting; /** * black list of fields name */ disableFields?: string[]; /** * prefix field name with model name or not */ prefixNaming?: boolean; } export interface KnSetting { rowsPerPage: number; maxRowsPerPage: number; maxLimit: number; /** * disable response columns attribute */ disableColumnSchema?: boolean; /** * disable response offsets attribute */ disablePageOffset?: boolean; /** * disable compose query paging */ disableQueryPaging?: boolean; } export interface HandlerSetting { name: string; options?: GenericObject; } export interface PageSetting extends PageOffset { /** * order by field/column name */ orderBy?: string; /** * order direction ascending or descending */ orderDir?: string | "ASC" | "DESC"; } export declare const KEY_PAGE_SETTING: string[] = [ "page", "rowsPerPage", "orderBy", "orderDir", "offset", "limit", "totalRows", "totalPages" ]; export interface LoggerInterface { fatal(...args: any[]): void; error(...args: any[]): void; warn(...args: any[]): void; info(...args: any[]): void; debug(...args: any[]): void; trace(...args: any[]): void; } export interface ServiceHandler { handlers?: HandlerSetting[]; init(broker?: any, service?: any): void; clear(context: any): Promise; create(context: any): Promise; execute(context: any): Promise; list(context: any): Promise; find(context: any): Promise; insert(context: any): Promise; retrieve(context: any): Promise; update(context: any): Promise; remove(context: any): Promise; collect(context: any): Promise; executeQuery(sql: string | SQLInterface): Promise; executeUpdate(sql: string | SQLInterface): Promise; destroy(): void; } export interface TrackingInfo { method: string; model: string; tracker?: string; info?: any; } export interface OperationInfo { operate: string; info?: any; } export enum Operation { INSERT = "insert", RETRIEVE = "retrieve", UPDATE = "update", DELETE = "delete", COLLECT = "collect", REMOVE = "remove", CREATE = "create", FIND = "find", CLEAR = "clear", LIST = "list", EXECUTE = "execute", COUNT = "count", GET = "get", ADD = "add", EDIT = "edit", RETRIEVAL = "retrieval", FETCH = "fetch", SEARCH = "search", QUERY = "query", VIEW = "view", ERASE = "erase", IMPORT = "import", EXPORT = "export", DOWNLOAD = "download", LAUNCH = "launch", VALIDATE = "validate", ENTRY = "entry", VERIFY = "verify", INQUIRY = "inquiry", DISPLAY = "display", } export declare abstract class KnAbstract implements ServiceHandler { handlers?: HandlerSetting[]; model?: KnModel; settings: KnSetting; logger: LoggerInterface; constructor(model?: KnModel, settings?: KnSetting); init(broker?: any, service?: any): void; clear(context: any): Promise; create(context: any): Promise; execute(context: any): Promise; list(context: any): Promise; find(context: any): Promise; insert(context: any): Promise; retrieve(context: any): Promise; update(context: any): Promise; remove(context: any): Promise; collect(context: any): Promise; executeQuery(sql: string | SQLInterface): Promise; executeUpdate(sql: string | SQLInterface): Promise; destroy(): void; } export declare class KnBase extends KnAbstract { broker?: ServiceBroker; service?: ServiceSchema; init(broker: ServiceBroker, service: ServiceSchema): void; destroy(): void; getConnector(schema: string | DBConfig): DBConnector; getPageSetting(params: any): PageSetting; calculatePageOffset(pageOffset: PageOffset, totalRows?: number): PageOffset; createQueryPaging(config: DBConfig, pageOffset: PageOffset): string; fatal(...args: any[]): void; error(...args: any[]): void; warn(...args: any[]): void; info(...args: any[]): void; debug(...args: any[]): void; trace(...args: any[]): void; track(context: any, info: TrackingInfo): Promise; trackingInfo(action: string, modelname?: string, tracker?: string): TrackingInfo; clear(context: any): Promise; create(context: any): Promise; execute(context: any): Promise; list(context: any): Promise; find(context: any): Promise; insert(context: any): Promise; retrieve(context: any): Promise; update(context: any): Promise; remove(context: any): Promise; collect(context: any): Promise; protected exposeFunctional(context: any, model: KnModel, operation: OperationInfo): Promise; protected exposeOperation(context: any, model: KnModel, operation: OperationInfo): Promise; protected doClear(context: any, model: KnModel): Promise; protected doCreate(context: any, model: KnModel): Promise; protected doExecute(context: any, model: KnModel): Promise; protected doList(context: any, model: KnModel): Promise; protected doFind(context: any, model: KnModel): Promise; protected doInsert(context: any, model: KnModel): Promise; protected doRetrieve(context: any, model: KnModel): Promise; protected doUpdate(context: any, model: KnModel): Promise; protected doRemove(context: any, model: KnModel): Promise; protected doCollect(context: any, model: KnModel): Promise; protected getPrivateConnector(model: KnModel): DBConnector; protected getCenterConnector(model: KnModel): DBConnector; protected getGlobalConnector(model: KnModel): DBConnector; protected isValidModelConfig(aliasName: string, model?: KnModel): boolean; createSpan(action: string, context?: any, config?: any): any; } export declare class KnHandler extends KnBase { protected isInPageSetting(key: string, model: KnModel): boolean; protected assignParameters(context: any, sql: SQLInterface, action?: string, mode?: string): void; protected hasParams(name: string, params?: any): boolean; protected buildInsertQuery(context: any, model: KnModel, action?: string): SQLInterface; protected buildUpdateQuery(context: any, model: KnModel, action?: string): SQLInterface; protected buildDeleteQuery(context: any, model: KnModel, action?: string): SQLInterface; protected buildFilterQuery(context: any, model: KnModel, knsql: SQLInterface, selector: string, action?: string, subaction?: string, pageSetting?: PageSetting): SQLInterface; protected buildCriteriaQuery(context: any, model: KnModel, knsql: SQLInterface, operator: string, action?: string): boolean; protected buildCountQuery(context: any, model: KnModel, action?: string): SQLInterface; protected isDisableQueryPaging(): boolean; protected buildSelectField(context: any, model: KnModel): string; protected buildSelectQuery(context: any, model: KnModel, config: DBConfig, pageSetting: PageSetting, action?: string): SQLInterface; protected buildOrderQuery(context: any, model: KnModel, knsql: SQLInterface, pageSetting: PageSetting, action?: string, subaction?: string): SQLInterface; protected buildPageSetting(rs: ResultSet, pageSetting: PageSetting): void; protected buildResultSet(rs: ResultSet, pageSetting: PageSetting): void; protected obtainParameters(knsql: SQLInterface, params?: any): void; protected doClearing(context: any, model: KnModel): Promise; protected performClearing(context: any, model: KnModel, db: DBConnector): Promise; protected doCreating(context: any, model: KnModel): Promise; protected performCreating(context: any, model: KnModel, db: DBConnector): Promise; protected doFinding(context: any, model: KnModel, action?: string): Promise; protected performFinding(context: any, model: KnModel, db: DBConnector, action?: string): Promise; protected doUpdating(context: any, model: KnModel): Promise; protected performUpdating(context: any, model: KnModel, db: DBConnector): Promise; protected executeQuerying(sql: string | SQLInterface, context?: any): Promise; protected executeUpdating(sql: string | SQLInterface, context?: any): Promise; protected doClear(context: any, model: KnModel): Promise; protected doCreate(context: any, model: KnModel): Promise; protected doFind(context: any, model: KnModel): Promise; protected doUpdate(context: any, model: KnModel): Promise; executeQuery(sql: string | SQLInterface, context?: any): Promise; executeUpdate(sql: string | SQLInterface, context?: any): Promise; getSQLError(err: any): string; getDBError(err: any, code?: number): DBError; } export declare class KnLogger implements LoggerInterface { fatal(...args: any[]): void; error(...args: any[]): void; warn(...args: any[]): void; info(...args: any[]): void; debug(...args: any[]): void; trace(...args: any[]): void; } export declare class KnSchema implements ServiceSchema { name: string; actions: ServiceActionsSchema; handler?: ServiceHandler; constructor(handler?: ServiceHandler); createActions(): ServiceActionsSchema; private defaultActions; merged(scheme: any): void; created(): void; started(): void; stopped(): void; } export declare class SQLUtils { static createQueryPaging(config: DBConfig, pageOffset: PageOffset): string; static calculatePageOffset(pageOffset: PageOffset, totalRows?: number): PageOffset; static getPageSetting(settings: KnSetting, params: any): PageSetting; } declare class KnService extends KnSchema { } declare const _default: KnService; export = _default;