UNPKG

@dgks/core

Version:

Core implementation for @dgks packages

72 lines (71 loc) 2.44 kB
import { OpenApiServiceResponse, ResponseContainer } from './interfaces'; /** * Response wrapping data.go.kr common formats * * @template T */ export declare class Response<T> { protected readonly rawResponse: Record<string, any>; protected readonly parsedResponse: ResponseContainer<T>; constructor(rawResponse: Record<string, any>); /** * Items of requested service * @type {T[]} */ get items(): T[]; /** * Requested number of rows * @type {number} */ get numOfRows(): number; /** * Current page * @type {number} */ get page(): number; /** * Total count * @type {number} */ get totalCount(): number; /** * Parses raw json response to match response container interface * * @throws {ServiceKeyNotRegistered} Service key is not registed in 3rd party service * @throws {ResponseParseError} Failed to parse response to what we want * @param {Record<string, any>} obj - response to parse * @returns {ResponseContainer<T>} */ protected parseRawResponse(obj: Record<string, any>): ResponseContainer<T>; /** * Parses header object and checks result code * * @throws {ResponseParseError} Failed to parse given header * @throws {ResponseError} Given header's response code is not what we expected * @param {Record<string, any>} obj - header object to parse * @returns {ResponseContainer<T>['header']} */ protected parseHeader(obj: Record<string, any>): ResponseContainer<T>['header']; /** * Parses body object and transforms it * * @throws {ResponseParseError} Failed to parse given body * @param {Record<string, any>} obj - header object to parse * @returns {ResponseContainer<T>['body']} */ protected parseBody(obj: Record<string, any>): ResponseContainer<T>['body']; /** * Replaces empty string to undefined * * @param {ResponseContainer<T>['body']} body - Body to transform * @returns {ResponseContainer<T>['body']} */ protected transformItems(body: ResponseContainer<T>['body']): ResponseContainer<T>['body']; /** * Checks if object is typeof OpenApiServiceResponse * * @param {Record<string, any>} obj - Object to check * @returns {boolean} */ protected isOpenApiServiceResponse(obj: Record<string, any>): obj is OpenApiServiceResponse; }