import { IMetaData } from "./metadata"; /** * Options for how to handle response parsing. */ export interface ResponseOptions { keepUnprocessedResponse: boolean; } /** * Types of message that can be in a response. */ export declare enum MessageType { /** * Message is an error. */ Error = 0, /** * Message is a warning. */ Warning = 1, /** * Message is informational. */ Information = 2, /** * The message type is unknown. */ Unknown = 3 } /** * Abstract structure for a message */ export interface IMessage { /** * Type of the message */ type: MessageType; /** * Actual message */ message: string; /** * Any other data related to a message */ data?: any; } /** * Abstract structure of a response shared by all responses. */ export interface IResponse { /** * The unprocessed response from the server. */ raw: any; /** * The status code returned by the API. Usually 1 for success, 0 for failure. */ status: number; /** * List of messages related to the response. */ messages: IMessage[]; /** * Additional data returned about the request. Paging, filtering, and maybe other custom properties. */ meta: IMetaData; /** * Data returned from the server for the request. This is the primary data returned. */ data: any; /** * Options about how to handle the response processing. */ options: ResponseOptions; } export declare const DefaultMetaData: IMetaData; /** * Base class for all response. Must be sub-classed by a real implementation. */ export declare abstract class Response implements IResponse { /** * The unprocessed response from the server. */ raw: any; /** * The status code returned by the API. Usually 1 for success, 0 for failure. */ status: number; /** * List of messages related to the response. */ messages: IMessage[]; /** * Additional data returned about the request. Paging, filtering, and maybe other custom properties. */ meta: IMetaData; /** * Data returned from the server for the request. This is the primary data returned. */ data: any; /** * Options about how to handle the response processing. */ options: ResponseOptions; /** * Build a new response object from the response. Note, this class should not be called * directly. * @param response Complete data passed from the server. Probably it's been parsed using JSON.parse(). * @param options for how to handle the processing of the response data. */ constructor(response: any, options?: ResponseOptions); /** * Checks if the API was successful. * * @return true if successful, false if failure. */ get success(): boolean; /** * Checks if the api failed. * * @return true if the API reports failure, false otherwise. */ get failed(): boolean; /** * Get the list of messages based on the requested type. * * @param type Type of the message to look up. * @return List of messages that match the filter. */ private _getMessages; /** * Get the list of error messages. * * @return List of errors. */ get errors(): IMessage[]; /** * Get the list of warning messages. * * @return List of warnings. */ get warnings(): IMessage[]; /** * Get the list of informational messages. * * @return List of informational messages. */ get infoMessages(): IMessage[]; /** * Checks if there are any messages of a given type. * @param type Type of the message to check for. * @return true if there are messages of the requested type. false otherwise. */ private _hasMessages; /** * Checks if there are any error messages in the response. * * @return true if there are error messages, false otherwise. */ get hasErrors(): boolean; /** * Checks if there are any warnings in the response. * * @return true if there are warnings, false otherwise. */ get hasWarnings(): boolean; /** * Checks if there are any informational messages in the response. * * @return true if there are informational messages, false otherwise. */ get hasInfoMessages(): boolean; /** * Check if the response was paginated by the backend. * * @return true if the backend returned a page of the total records. */ get isPaged(): boolean; /** * Check if the response was filtered by the backend. * * @return true if the backend filtered the records. */ get isFiltered(): boolean; }