UNPKG

routeros-api

Version:

Mikrotik Routerboard RouterOS API for NodeJS

179 lines (178 loc) 5.62 kB
import * as Types from "./Types"; import { RouterOSAPI } from "./RouterOSAPI"; export declare abstract class RouterOSAPICrud { protected rosApi: RouterOSAPI; protected pathVal: string; protected proplistVal: string; protected queryVal: string[]; protected snakeCase: boolean; private needsObjectTranslation; private placeAfter; /** * Creates a CRUD set of operations and handle * the raw query to input on the raw API * * @param rosApi the raw api * @param path the menu path we are in * @param snakeCase if should return routerboard properties in snake_case, defaults to camelCase */ constructor(rosApi: RouterOSAPI, path: string, snakeCase: boolean); /** * Get the current menu */ getCurrentMenu(): string; /** * Adds an item on the menu * * @param data the params that will be used to add the item */ add(data: object): Types.SocPromise; /** * Alias of add * * @param data the params that will be used to add the item */ create(data: object): Types.SocPromise; /** * Disable one or more entries * * @param ids the id(s) or number(s) to disable */ disable(ids?: Types.Id): Types.SocPromise; /** * Delete one or more entries * * @param ids the id(s) or number(s) to delete */ delete(ids?: any): Types.SocPromise; /** * Enable one or more entries * * @param ids the id(s) or number(s) to enable */ enable(ids?: Types.Id): Types.SocPromise; /** * Run a custom command over the api, for example "export" * * @param command the command to run * @param data optional data that goes with the command */ exec(command: string, data?: object): Types.SocPromise; /** * Move a queried rule above another. * * @param to where to move the queried rule */ moveAbove(to?: string): Types.SocPromise; /** * Update an entry or set of entries of the menu * * @param data the new data to update the item * @param ids optional id(s) of the rules */ update(data: object, ids?: Types.Id): Types.SocPromise; /** * Unset a property or set of properties of one or more entries * * @param properties one or more properties to unset * @param ids the id(s) of the entries to unset the property(ies) */ unset(properties: string | string[], ids?: Types.Id): Types.SocPromise; /** * Removes an entry or set of entries of the menu * * @param ids optional id(s) to be removed from the menu */ remove(ids?: any): Types.SocPromise; /** * Alias of update * * @param data the new data to update the item * @param ids optional id(s) of the rules */ set(data: object, ids?: Types.Id): Types.SocPromise; /** * Alias of update * * @param data the new data to update the item * @param ids optional id(s) of the rules */ edit(data: object, ids?: Types.Id): Types.SocPromise; /** * Moves a rule ABOVE the destination * * @param from the rule you want to move * @param to the destination where you want to move */ protected moveEntry(from: Types.Id, to?: string | number): Types.SocPromise; /** * Creates the full array of sentences that will be * compatible with the raw API to be sent to the * routerboard using all the functions triggered * up until now * * @param append action to add in front of the menu */ protected fullQuery(append?: string): string[]; /** * Make the query array to write on the API, * adding a question mark if it needs to print * filtered content * * @param searchParameters The key-value pair to add to the search */ protected makeQuery(searchParameters: object, addQuestionMark?: boolean, addToLocalQuery?: boolean): string[]; /** * Write the query using the raw API * * @param query the raw array of sentences to write on the socket */ protected write(query: string[]): Types.SocPromise; /** * Translates .id, place-before and number without using internal * mikrotik id (something like *4A). * * This should check if one of those parameters are an object * and use that object to search the real id of the item. * * @param queries query array */ protected translateQueryIntoId(queries: string[]): Promise<any>; /** * If the place-after feature was used, the rule below * will be moved above here. * * @param results */ protected prepareToPlaceAfter(results: any): Promise<any>; /** * Transform mikrotik properties to either camelCase or snake_case * and casts values of true or false to boolean and * integer strings to number * * @param results the result set of an operation */ protected treatMikrotikProperties(results: object[]): object[]; /** * Stringify a json formated object to be used later * for a translation * * @param items object items to stringfy */ private stringfySearchQuery; /** * Clean data print of provided ids, used only when * creating, editting or unsetting properties * * @param data * @param ids */ private recoverDataFromChangedItems; /** * If trying do any action without providing any id, just * a query. Find all their ids and return them * * @param ids */ private queryForIdsIfNeeded; }