import { HttpRoute, KuzzleRequest } from "kuzzle"; import { JSONObject } from "kuzzle-sdk"; import { DecodedPayload } from "./DecodedPayload"; import { DecoderContent } from "./types/DecoderContent"; /** * Array of measures declaration * * This need to be read only so we can provide strong typing when decoding measures * with the DecodedPayload */ export type NamedMeasures = Array<{ name: string; type: string; }>; /** * Base class to implement a decoder for a device model. * The device model must be passed to the parent constructor. * The abstract "decode" method must be implemented. */ export declare abstract class Decoder { private _http?; /** * Internal logger. */ log: { debug: (message: any) => void; error: (message: any) => void; info: (message: any) => void; silly: (message: any) => void; verbose: (message: any) => void; warn: (message: any) => void; }; /** * Device model name. * * Will be infered from the class name if not defined: * `AbeewayGPSDecoder` => `AbeewayGPS` */ deviceModel: string; /** * Declaration of the measures decoded by this decoder. * The name correspond of the measure name for the device. * Measures types should be registered on the plugin beforehand. * * @example * * this.measures = [ * { type: 'temperature', name: 'temperatureExterior' }, * ]; */ measures: ReadonlyArray; /** * Custom name for the associated API action in the "payload" controller */ action?: string; /** * Custom mappings for the payload collection. * It will be injected in the "payload" property and it should allows to index * the device model unique identifier field. * * @example * * this.payloadsMappings = { * device_properties: { * properties: { * deveui: { type: 'keyword' } * } * } * } */ payloadsMappings?: JSONObject; /** * Define custom HTTP routes * * @param http HttpRoute array */ set http(http: HttpRoute[]); get http(): HttpRoute[]; get measureNames(): string[]; get measureTypes(): string[]; /** * Validate the payload format before processing. * * If the method: * - return true: the payload will be processed (status 200) * - return false: the payload will be skipped (status 200) * - throw an error: the payload will be skipped (status 4** or 5**) * * @param payload Raw payload received in the API action body * @param request Original request * * @return A boolean indicating if the payload is valid */ validate(payload: JSONObject, request: KuzzleRequest): Promise | never; /** * Decode the payload: * - set "reference" * - fetch measures * * @param decodedPayload Decoded payload to store decoded measures * @param payload Raw payload received in the API action body * @param request Original request * * @returns DecodedPayload */ abstract decode(decodedPayload: DecodedPayload, payload: JSONObject, request: KuzzleRequest): Promise>; /** * Checks if the provided properties are present in the payload * * @param payload Raw payload received in the API action body * @param paths Paths of properties (lodash style) * * @throws */ ensureProperties(payload: JSONObject, paths: string[]): void | never; serialize(): DecoderContent; }