export default abstract class Response { /** * Indicates custom headers. */ protected headers: Record = {}; constructor( public code: number, public data: Record = {}, public meta: Record = {}, ) {} /** * Merge the given meta into the response meta. */ public withMeta(meta: string | Record, value?: any): Response { const mergeValues = typeof meta === 'string' ? { [meta]: value } : meta; this.meta = { ...mergeValues, ...this.meta, }; return this; } /** * Get content for response. */ public content(): Record { return { code: this.code, data: this.data, meta: this.meta, }; } /** * Get response status code. */ public getStatusCode(): number { return this.code; } /** * Get the response headers. */ public getHeaders(): Record { return this.headers; } /** * Append header value to response. */ public withHeader(key: string, value: any): this { this.headers[key] = value; return this; } }