From 47bd06e1a2b8a65007032a984a018a12a5e89e24 Mon Sep 17 00:00:00 2001 From: NeutronicMC Date: Sat, 20 Jun 2020 00:10:49 -0700 Subject: [PATCH] fix dumb issue --- index.js | 1 + package.json | 4 ++-- src/api/ApiClient.ts | 22 +++++++++++----------- 3 files changed, 14 insertions(+), 13 deletions(-) create mode 100644 index.js diff --git a/index.js b/index.js new file mode 100644 index 0000000..ac50cb7 --- /dev/null +++ b/index.js @@ -0,0 +1 @@ +module.exports = require("./lib/HiveApi"); \ No newline at end of file diff --git a/package.json b/package.json index c3e6bc9..398b3ea 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "hive-tools-wrapper", - "version": "0.1.0", + "version": "0.1.1", "description": "Advanced Hive Bedrock API wrapper with caching.", - "main": "/src/HiveApi.ts", + "main": "index.js", "files": [ "lib/**/*" ], diff --git a/src/api/ApiClient.ts b/src/api/ApiClient.ts index ddf8c71..9698b1c 100644 --- a/src/api/ApiClient.ts +++ b/src/api/ApiClient.ts @@ -1,10 +1,10 @@ import Axios, {AxiosResponse} from "axios"; -export interface params { +export interface Params { [key: string]: any; } -interface cacheData { +interface CacheData { [key: string]: { timestamp: number, data: AxiosResponse @@ -22,7 +22,7 @@ export default class ApiClient { return await Axios.get(this.buildUrl(path, pathParams)); } - public buildUrl(path: string, pathParams: params) { + public buildUrl(path: string, pathParams: Params) { if (!path.match(/^\//)) { path = '/' + path; } @@ -34,7 +34,7 @@ export default class ApiClient { } public static paramToString(param: any): string { - if (param == undefined) { + if (param === undefined) { return ''; } if (param instanceof Date) { @@ -44,7 +44,7 @@ export default class ApiClient { return param.toString(); } - public static buildPath(path: string, pathParams: params): string { + public static buildPath(path: string, pathParams: Params): string { return path.replace(/\{([\w-]+)\}/g, (fullMatch, key) => { let value; if (pathParams.hasOwnProperty(key)) { @@ -57,21 +57,21 @@ export default class ApiClient { }); } - cacheData: cacheData = {}; - public async getData(path: string, params: params, cache: boolean) { - let key = ApiClient.buildPath(path, params); - let now = new Date().getTime(); + cacheData: CacheData = {}; + public async getData(path: string, pathParams: Params, cache: boolean) { + const key = ApiClient.buildPath(path, pathParams); + const now = new Date().getTime(); if (this.cacheData.hasOwnProperty(key) && cache) { if (this.cacheData[key].timestamp + (this.cacheTimeout * 1000) < now) { this.cacheData[key] = { timestamp: now, - data: await this.callApi(path, params) + data: await this.callApi(path, pathParams) } } } else { this.cacheData[key] = { timestamp: now, - data: await this.callApi(path, params) + data: await this.callApi(path, pathParams) } } return this.cacheData[key].data;