UNPKG

@creamapi/cream

Version:

Concise REST API Maker - An extension library for express to create REST APIs faster

78 lines (77 loc) 3.7 kB
import { HeaderBuilder } from '../HttpUtils/Headers/HeaderBuilder'; import { HeadersManager } from '../HttpUtils/Headers/HeadersManager'; import { MessageType } from './Message'; import { Response } from 'express'; import { ResponseCookieManager } from '../HttpUtils/Cookies/ResponseCookiesManager'; import { NoCookiesHeaderNames } from '../HttpUtils/Headers/HeadersDef'; /** * This class is used to prepare the transaction before sending the data to the user.\ * It is accessible from any method that is decorated as {@link ExpressCall} or its derivatives * like {@link Get}, {@link Put}, {@link Post}, {@link Delete}.\ * To access it in the method simply call ExpressModule.prepareTransaction(). */ export declare class TransactionManager { private method; private thisArg; /** * The transaction HTTP Return Code * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Status | HTTP Status Codes} */ private retcode; /** * This object will handle headers */ private headers; /** * @param method The method that will handle the transaction * @param thisArg The method owner (reserved for future usage) */ constructor(method: any, thisArg: any); /** * This method is used by the ExpressCall wrapper to set the cookies in the transaction * manager. * @note This will overwrite any previously set headers. * @param headers the headers manager cotaining new headers * @returns a self reference to the transaction manager for chaining more operations */ setHeaders(headers: HeadersManager | undefined): this; /** * This method allows to retrieve a header builder for the requested header * @note this will create a new header builder if the one searched is undefined * @param headerName the name of the header * @returns the header builder associated with the headerName or undefined if none is found */ getHeaderBuilder(headerName: NoCookiesHeaderNames): HeaderBuilder; /** * This method is used to set the content type of the transaction. * @see {@link MessageType} * @param contentType The content type of the data sent to the user. If contentType is undefined then nothing is changed from the last value * @returns a self reference to the transaction manager for chaining more operations */ ContentType(contentType: MessageType | undefined): TransactionManager; /** * Returns the cookies manager that will set or unset cookies for responses to users */ getResponseCookiesManager(): ResponseCookieManager; /** * This method is used to set the return code of the transaction. * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Status | HTTP Status Codes} * @param retcode is the HTTP status code sent to the user. If retcode is undefined then nothing is changed from the last value * @returns a self reference to the transaction manager for chaining more operations */ ReturnCode(retcode: number | undefined): TransactionManager; /** * @internal * This method is used to reset to a default state the transaction manager. This method is called * everytime before calling the associated method. * @param thisArg the owner of the method * @returns a self reference to the transaction manager */ reset(thisArg: any): TransactionManager; /** * This method will apply all saved information to the transaction * @param res the transaction that will be modified by the content of this transaction manager * @returns the modified transaction */ finalizeTransaction(res: Response): Response; }