hive-bedrock-api 1.0.9 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/README.md +37 -41
  2. package/lib/helpers/fetchEndpoint.d.ts +3 -0
  3. package/lib/{methods/fetchData.js → helpers/fetchEndpoint.js} +18 -14
  4. package/lib/helpers/isGame.d.ts +2 -0
  5. package/lib/helpers/isGame.js +7 -0
  6. package/lib/helpers/toPoint.d.ts +1 -0
  7. package/lib/helpers/toPoint.js +6 -0
  8. package/lib/index.d.ts +9 -9
  9. package/lib/index.js +13 -31
  10. package/lib/methods/getAllTimeLeaderboard.d.ts +4 -5
  11. package/lib/methods/getAllTimeLeaderboard.js +25 -19
  12. package/lib/methods/getAllTimeStatistics.d.ts +9 -0
  13. package/lib/methods/getAllTimeStatistics.js +180 -0
  14. package/lib/methods/getGlobalStatistics.d.ts +3 -3
  15. package/lib/methods/getGlobalStatistics.js +7 -30
  16. package/lib/methods/getMaps.d.ts +3 -4
  17. package/lib/methods/getMaps.js +17 -38
  18. package/lib/methods/getMetadata.d.ts +3 -0
  19. package/lib/methods/{getPlayerInfo.js → getMetadata.js} +20 -18
  20. package/lib/methods/getMonthlyLeaderboard.d.ts +9 -11
  21. package/lib/methods/getMonthlyLeaderboard.js +28 -56
  22. package/lib/methods/getMonthlyStatistics.d.ts +10 -0
  23. package/lib/methods/getMonthlyStatistics.js +154 -0
  24. package/lib/methods/getPlayerInfomation.d.ts +3 -0
  25. package/lib/methods/{getGameMetadata.js → getPlayerInfomation.js} +15 -21
  26. package/lib/processors/index.d.ts +7 -0
  27. package/lib/processors/index.js +116 -0
  28. package/lib/types/output.d.ts +67 -0
  29. package/lib/types/{GAMES.js → output.js} +1 -1
  30. package/lib/types/types.d.ts +21 -0
  31. package/package.json +7 -8
  32. package/lib/format/gameFormat.d.ts +0 -30
  33. package/lib/format/gameFormat.js +0 -164
  34. package/lib/methods/calculateLevel.d.ts +0 -2
  35. package/lib/methods/calculateLevel.js +0 -45
  36. package/lib/methods/fetchData.d.ts +0 -25
  37. package/lib/methods/getAllTimeStats.d.ts +0 -13
  38. package/lib/methods/getAllTimeStats.js +0 -186
  39. package/lib/methods/getGameMetadata.d.ts +0 -4
  40. package/lib/methods/getMonthlyStats.d.ts +0 -15
  41. package/lib/methods/getMonthlyStats.js +0 -192
  42. package/lib/methods/getPlayerInfo.d.ts +0 -4
  43. package/lib/types/API.d.ts +0 -224
  44. package/lib/types/API.js +0 -37
  45. package/lib/types/ENDPOINTS.d.ts +0 -11
  46. package/lib/types/GAMES.d.ts +0 -85
  47. package/lib/types/GAME_INFO.d.ts +0 -26
  48. package/lib/types/GAME_INFO.js +0 -113
  49. package/lib/types/METHODS.d.ts +0 -8
  50. package/lib/types/METHODS.js +0 -2
  51. /package/lib/types/{ENDPOINTS.js → types.js} +0 -0
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Hive Bedrock API
2
2
 
3
- An API wrapper for the Hive Minecraft Bedrock Edition server. Which allows you to get stats for leaderboards, players, cosmetics and total unique player counts.
3
+ An API wrapper for the Hive Minecraft Bedrock Edition server. Which allows you to get stats for leaderboards, players, cosmetics, unique player counts, maps and metadata.
4
4
 
5
5
  ## Getting started
6
6
 
@@ -16,78 +16,65 @@ See [API.md](docs/API.md) for detailed documentation.
16
16
  ### Fetch Player Infomation
17
17
 
18
18
  ```ts
19
- import { getPlayerInfo } from "hive-bedrock-api";
19
+ import { getPlayerInformation } from "hive-bedrock-api";
20
20
 
21
21
  // Returns player, cosmetics, server statistics and profile infomation
22
- const { data, error } = await getPlayerInfo("ucdfiddes");
22
+ const { data, error } = await getPlayerInformation("player");
23
23
  ```
24
24
 
25
25
  ### Fetch All-Time Player Statistics
26
26
 
27
27
  ```ts
28
- import { getAllTimeStats, GAME } from "hive-bedrock-api";
28
+ import { getAllTimeStatistics, Game } from "hive-bedrock-api";
29
29
 
30
30
  // Returns all games
31
- const { data, player, error } = await getAllTimeStats("ucdfiddes");
32
-
33
- // Returns multiple specific games
34
- const { data, player, error } = await getAllTimeStats("ucdfiddes", [GAME.Deathrun, GAME.TheBridge]);
31
+ const { data, error } = await getAllTimeStats("player");
35
32
 
36
33
  // Returns a single game
37
- const { data, error } = await getAllTimeStats("ucdfiddes", GAME.HideAndSeek);
34
+ const { data, error } = await getAllTimeStats("player", Game.HideAndSeek);
38
35
  ```
39
36
 
40
37
  ### Fetch Monthly Player Statistics
41
38
 
42
39
  ```ts
43
- import { getMonthlyStats, GAME } from "hive-bedrock-api";
40
+ import { getMonthlyStatistics, Game } from "hive-bedrock-api";
44
41
 
45
42
  // Returns all games
46
- const { data, error } = await getMonthlyStats("ucdfiddes");
47
-
48
- // Returns multiple specific games
49
- const { data, error } = await getMonthlyStats("ucdfiddes", [GAME.Deathrun, GAME.TheBridge]);
43
+ const { data, error } = await getMonthlyStats("player");
50
44
 
51
45
  // Returns a single game
52
- const { data, error } = await getMonthlyStats("ucdfiddes", GAME.BlockDrop);
46
+ const { data, error } = await getMonthlyStats("player", Game.BlockDrop);
53
47
 
54
48
  // Returns a single game in a previous month (can return muliple games)
55
- const { data, error } = await getMonthlyStats("ucdfiddes", GAME.BlockDrop, {
56
- year: 2023,
57
- month: 1, // January
58
- });
59
-
60
- // Same as before, but with a Date object
61
- const previousMonth = new Date();
62
- previousMonth.setMonth(0); // January
63
- const { data, error } = await getMonthlyStats("ucdfiddes", GAME.BlockDrop, {
64
- date: previousMonth,
49
+ const { data, error } = await getMonthlyStats("player", Game.BlockDrop, {
50
+ year: 2023,
51
+ month: 1, // January
65
52
  });
66
53
  ```
67
54
 
68
55
  ### Fetch All-Time Leaderboard
69
56
 
70
57
  ```ts
71
- import { getAllTimeLeaderboard, GAME } from "hive-bedrock-api";
58
+ import { getAllTimeLeaderboard, Game } from "hive-bedrock-api";
72
59
 
73
60
  // Returns a single game
74
- const { data, error } = await getAllTimeLeaderboard(GAME.TreasureWars);
61
+ const { data, error } = await getAllTimeLeaderboard(Game.TreasureWars);
75
62
  ```
76
63
 
77
64
  ### Fetch Monthly Leaderboard
78
65
 
79
66
  ```ts
80
- import { getMonthlyLeaderboard, GAME } from "hive-bedrock-api";
67
+ import { getMonthlyLeaderboard, Game } from "hive-bedrock-api";
81
68
 
82
69
  // Returns a single game
83
- const { data, error } = await getMonthlyLeaderboard(GAME.TreasureWars);
70
+ const { data, error } = await getMonthlyLeaderboard(Game.TreasureWars);
84
71
 
85
72
  // Returns a single game from a previous month
86
- const { data, error } = await getMonthlyLeaderboard(GAME.BlockParty, {
87
- year: 2023,
88
- month: 11, // November
89
- amount: 50,
90
- skip: 20, // Sum of skip and amount must be <=100
73
+ const { data, error } = await getMonthlyLeaderboard(Game.BlockParty, {
74
+ year: 2023,
75
+ month: 11, // November
76
+ amount: 50,
77
+ skip: 20, // Sum of skip and amount must be <=100
91
78
  });
92
79
  ```
93
80
 
@@ -103,20 +90,29 @@ const { data, error } = await getGlobalStatistics();
103
90
  ### Fetch Maps
104
91
 
105
92
  ```ts
106
- import { getMaps, GAME } from "hive-bedrock-api";
93
+ import { getMaps, Game } from "hive-bedrock-api";
94
+
95
+ // Returns data for a specific game's currently active maps
96
+ const { data, error } = await getMaps(Game.TreasureWars);
97
+ ```
98
+
99
+ ### Fetch Metadata
100
+
101
+ ```ts
102
+ import { getMetadata, Game } from "hive-bedrock-api";
107
103
 
108
104
  // Returns data for a specific game's currently active maps
109
- const { data, error } = await getMaps(GAME.TreasureWars);
105
+ const { data, error } = await getMetadata(Game.TreasureWars);
110
106
  ```
111
107
 
112
108
  ## API Response Changes
113
109
 
114
110
  Different API responses are edited by the wrapper to provide more data:
115
111
 
116
- - Game responses have a new value "id" showing the parent game
117
- - "first_played" values are converted into a Date object
118
- - A new value for "losses" is provided
119
- - A new value for "kdr" is provided
120
- - "xp" is converted and a "level" is provided
112
+ - Game responses have a new value "id" showing the parent game
113
+ - A new value for "losses" is provided
114
+ - A new value for "kdr" is provided
115
+ - "xp" is converted and a "level" is provided
116
+ - "total_ratings" for just build is provided
121
117
 
122
118
  See [API.md](docs/API.md#game-statistics-types) for specific fields and their corresponding types per game.
@@ -0,0 +1,3 @@
1
+ import { APIResponse } from "../types/types";
2
+ import { Routes } from "hive-bedrock-data";
3
+ export default function fetchEndpoint<T extends string>(endpoint: T, init?: RequestInit): Promise<APIResponse<Routes<T>>>;
@@ -36,48 +36,52 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  }
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.API_ROOT = void 0;
40
- exports.API_ROOT = "https://api.playhive.com/v0";
41
- function fetchData(endpoint, options) {
39
+ var hive_bedrock_data_1 = require("hive-bedrock-data");
40
+ function fetchEndpoint(endpoint, init) {
42
41
  return __awaiter(this, void 0, void 0, function () {
43
- var request, response, err_1;
42
+ var time_start, request, time_end, duration, response, err_1;
44
43
  return __generator(this, function (_a) {
45
44
  switch (_a.label) {
46
45
  case 0:
47
46
  _a.trys.push([0, 3, , 4]);
48
- return [4 /*yield*/, fetch(exports.API_ROOT + endpoint, {
49
- headers: (options === null || options === void 0 ? void 0 : options.headers)
50
- ? new Headers(options === null || options === void 0 ? void 0 : options.headers)
51
- : undefined,
52
- })];
47
+ time_start = performance.now();
48
+ return [4 /*yield*/, fetch(hive_bedrock_data_1.API_BASE_ENDPOINT + endpoint, init)];
53
49
  case 1:
54
50
  request = _a.sent();
51
+ time_end = performance.now();
52
+ duration = Math.round(time_end - time_start);
55
53
  if (!request.ok)
56
54
  return [2 /*return*/, {
55
+ status: request.status,
57
56
  data: null,
58
57
  error: {
58
+ code: request.status,
59
59
  message: request.statusText,
60
- status: request.status,
61
- endpoint: exports.API_ROOT + endpoint,
62
60
  },
61
+ duration: duration,
63
62
  }];
64
63
  return [4 /*yield*/, request.json()];
65
64
  case 2:
66
65
  response = _a.sent();
67
66
  return [2 /*return*/, {
67
+ status: request.status,
68
68
  data: response,
69
69
  error: null,
70
+ duration: duration,
70
71
  }];
71
72
  case 3:
72
73
  err_1 = _a.sent();
73
- console.error(err_1);
74
74
  return [2 /*return*/, {
75
+ status: 500,
75
76
  data: null,
76
- error: { message: "Failed to fetch data." },
77
+ error: {
78
+ code: 500,
79
+ message: "Failed to fetch endpoint data.",
80
+ },
77
81
  }];
78
82
  case 4: return [2 /*return*/];
79
83
  }
80
84
  });
81
85
  });
82
86
  }
83
- exports.default = fetchData;
87
+ exports.default = fetchEndpoint;
@@ -0,0 +1,2 @@
1
+ import { Game } from "hive-bedrock-data";
2
+ export default function isGame(game_id: Game): boolean;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var hive_bedrock_data_1 = require("hive-bedrock-data");
4
+ function isGame(game_id) {
5
+ return Object.values(hive_bedrock_data_1.Game).includes(game_id);
6
+ }
7
+ exports.default = isGame;
@@ -0,0 +1 @@
1
+ export default function toPoint(num: number, point: number): number;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function toPoint(num, point) {
4
+ return Math.round(num * (10 ^ point)) / (10 ^ point);
5
+ }
6
+ exports.default = toPoint;
package/lib/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
- import getMonthlyStats from "./methods/getMonthlyStats";
2
- import getMonthlyLeaderboard from "./methods/getMonthlyLeaderboard";
3
- import getAllTimeStats from "./methods/getAllTimeStats";
4
1
  import getAllTimeLeaderboard from "./methods/getAllTimeLeaderboard";
2
+ import getAllTimeStatistics from "./methods/getAllTimeStatistics";
5
3
  import getGlobalStatistics from "./methods/getGlobalStatistics";
6
- import getPlayerInfo from "./methods/getPlayerInfo";
7
4
  import getMaps from "./methods/getMaps";
8
- import getGameMetadata from "./methods/getGameMetadata";
9
- import { AVATAR, RANK, MAP_SEASON, MAP_VARIANT } from "./types/API";
10
- export { getAllTimeStats, getAllTimeLeaderboard, getMonthlyStats, getMonthlyLeaderboard, getGlobalStatistics, getPlayerInfo, getMaps, getGameMetadata, AVATAR, RANK, MAP_SEASON, MAP_VARIANT, };
11
- export * from "./types/GAME_INFO";
12
- export * from "./types/GAMES";
5
+ import getMetdata from "./methods/getMetadata";
6
+ import getMonthlyLeaderboard from "./methods/getMonthlyLeaderboard";
7
+ import getMonthlyStatistics from "./methods/getMonthlyStatistics";
8
+ import getPlayerInfomation from "./methods/getPlayerInfomation";
9
+ import type { AllStatistics, AllLeaderboards } from "./types/output";
10
+ export { getAllTimeLeaderboard, getMonthlyLeaderboard, getAllTimeStatistics, getMonthlyStatistics, getGlobalStatistics, getMaps, getMetdata, getPlayerInfomation, };
11
+ export type { AllStatistics, AllLeaderboards };
12
+ export { Game } from "hive-bedrock-data";
package/lib/index.js CHANGED
@@ -1,42 +1,24 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
17
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
4
  };
19
5
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.MAP_VARIANT = exports.MAP_SEASON = exports.RANK = exports.getGameMetadata = exports.getMaps = exports.getPlayerInfo = exports.getGlobalStatistics = exports.getMonthlyLeaderboard = exports.getMonthlyStats = exports.getAllTimeLeaderboard = exports.getAllTimeStats = void 0;
21
- var getMonthlyStats_1 = __importDefault(require("./methods/getMonthlyStats"));
22
- exports.getMonthlyStats = getMonthlyStats_1.default;
23
- var getMonthlyLeaderboard_1 = __importDefault(require("./methods/getMonthlyLeaderboard"));
24
- exports.getMonthlyLeaderboard = getMonthlyLeaderboard_1.default;
25
- var getAllTimeStats_1 = __importDefault(require("./methods/getAllTimeStats"));
26
- exports.getAllTimeStats = getAllTimeStats_1.default;
6
+ exports.Game = exports.getPlayerInfomation = exports.getMetdata = exports.getMaps = exports.getGlobalStatistics = exports.getMonthlyStatistics = exports.getAllTimeStatistics = exports.getMonthlyLeaderboard = exports.getAllTimeLeaderboard = void 0;
27
7
  var getAllTimeLeaderboard_1 = __importDefault(require("./methods/getAllTimeLeaderboard"));
28
8
  exports.getAllTimeLeaderboard = getAllTimeLeaderboard_1.default;
9
+ var getAllTimeStatistics_1 = __importDefault(require("./methods/getAllTimeStatistics"));
10
+ exports.getAllTimeStatistics = getAllTimeStatistics_1.default;
29
11
  var getGlobalStatistics_1 = __importDefault(require("./methods/getGlobalStatistics"));
30
12
  exports.getGlobalStatistics = getGlobalStatistics_1.default;
31
- var getPlayerInfo_1 = __importDefault(require("./methods/getPlayerInfo"));
32
- exports.getPlayerInfo = getPlayerInfo_1.default;
33
13
  var getMaps_1 = __importDefault(require("./methods/getMaps"));
34
14
  exports.getMaps = getMaps_1.default;
35
- var getGameMetadata_1 = __importDefault(require("./methods/getGameMetadata"));
36
- exports.getGameMetadata = getGameMetadata_1.default;
37
- var API_1 = require("./types/API");
38
- Object.defineProperty(exports, "RANK", { enumerable: true, get: function () { return API_1.RANK; } });
39
- Object.defineProperty(exports, "MAP_SEASON", { enumerable: true, get: function () { return API_1.MAP_SEASON; } });
40
- Object.defineProperty(exports, "MAP_VARIANT", { enumerable: true, get: function () { return API_1.MAP_VARIANT; } });
41
- __exportStar(require("./types/GAME_INFO"), exports);
42
- __exportStar(require("./types/GAMES"), exports);
15
+ var getMetadata_1 = __importDefault(require("./methods/getMetadata"));
16
+ exports.getMetdata = getMetadata_1.default;
17
+ var getMonthlyLeaderboard_1 = __importDefault(require("./methods/getMonthlyLeaderboard"));
18
+ exports.getMonthlyLeaderboard = getMonthlyLeaderboard_1.default;
19
+ var getMonthlyStatistics_1 = __importDefault(require("./methods/getMonthlyStatistics"));
20
+ exports.getMonthlyStatistics = getMonthlyStatistics_1.default;
21
+ var getPlayerInfomation_1 = __importDefault(require("./methods/getPlayerInfomation"));
22
+ exports.getPlayerInfomation = getPlayerInfomation_1.default;
23
+ var hive_bedrock_data_1 = require("hive-bedrock-data");
24
+ Object.defineProperty(exports, "Game", { enumerable: true, get: function () { return hive_bedrock_data_1.Game; } });
@@ -1,5 +1,4 @@
1
- import { Options } from "../types/API";
2
- import { LB_STATS } from "../types/GAMES";
3
- import { GAME } from "../types/GAME_INFO";
4
- import { MethodResponse } from "../types/METHODS";
5
- export default function getAllTimeLeaderboard<G extends GAME>(game: G, options?: Options): Promise<MethodResponse<LB_STATS<G>[]>>;
1
+ import { Game, Timeframe } from "hive-bedrock-data";
2
+ import { APIResponse, Options } from "../types/types";
3
+ import { LeaderboardResponse } from "../types/output";
4
+ export default function getAllTimeLeaderboard<G extends Game>(game_id: G, options?: Options): Promise<APIResponse<LeaderboardResponse<G, Timeframe.AllTime>>>;
@@ -50,30 +50,36 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
50
50
  return (mod && mod.__esModule) ? mod : { "default": mod };
51
51
  };
52
52
  Object.defineProperty(exports, "__esModule", { value: true });
53
- var gameFormat_1 = require("../format/gameFormat");
54
- var fetchData_1 = __importDefault(require("./fetchData"));
55
- function getAllTimeLeaderboard(game, options) {
53
+ var hive_bedrock_data_1 = require("hive-bedrock-data");
54
+ var fetchEndpoint_1 = __importDefault(require("../helpers/fetchEndpoint"));
55
+ var isGame_1 = __importDefault(require("../helpers/isGame"));
56
+ var processors_1 = __importDefault(require("../processors"));
57
+ function getAllTimeLeaderboard(game_id, options) {
56
58
  return __awaiter(this, void 0, void 0, function () {
57
- var _a, data, error, gameData, err_1;
58
- return __generator(this, function (_b) {
59
- switch (_b.label) {
59
+ var response, response_data, processors;
60
+ return __generator(this, function (_a) {
61
+ switch (_a.label) {
60
62
  case 0:
61
- _b.trys.push([0, 2, , 3]);
62
- return [4 /*yield*/, (0, fetchData_1.default)("/game/all/".concat(game), options === null || options === void 0 ? void 0 : options.fetch)];
63
- case 1:
64
- _a = _b.sent(), data = _a.data, error = _a.error;
65
- if (error || !data)
63
+ if (!(0, isGame_1.default)(game_id))
66
64
  return [2 /*return*/, {
65
+ status: 404,
66
+ error: {
67
+ code: 404,
68
+ message: "Game not found.",
69
+ },
67
70
  data: null,
68
- error: __assign({ message: "Failed to fetch data." }, error),
69
71
  }];
70
- gameData = (0, gameFormat_1.gameFormatArray)(game, data);
71
- return [2 /*return*/, { data: gameData, error: null }];
72
- case 2:
73
- err_1 = _b.sent();
74
- console.error(err_1);
75
- return [2 /*return*/, { data: null, error: { message: "Failed to fetch data." } }];
76
- case 3: return [2 /*return*/];
72
+ return [4 /*yield*/, (0, fetchEndpoint_1.default)("/game/all/".concat(game_id), options === null || options === void 0 ? void 0 : options.init)];
73
+ case 1:
74
+ response = _a.sent();
75
+ if (response.error)
76
+ return [2 /*return*/, response];
77
+ response_data = response.data;
78
+ processors = (0, processors_1.default)(game_id, hive_bedrock_data_1.Timeframe.AllTime);
79
+ response_data.forEach(function (statistics) {
80
+ return processors.forEach(function (processor) { return processor(statistics); });
81
+ });
82
+ return [2 /*return*/, __assign(__assign({}, response), { data: response_data, error: null })];
77
83
  }
78
84
  });
79
85
  });
@@ -0,0 +1,9 @@
1
+ import { Game, PlayerMetadata, Timeframe } from "hive-bedrock-data";
2
+ import { APIResponse, Options } from "../types/types";
3
+ import { AllGameStatistics, StatisticsResponse } from "../types/output";
4
+ type AllGameStatisticsPlayer = AllGameStatistics<Timeframe.AllTime> & {
5
+ player: PlayerMetadata;
6
+ };
7
+ export default function getAllTimeStatistics(identifier: string, options?: Options): Promise<APIResponse<AllGameStatisticsPlayer>>;
8
+ export default function getAllTimeStatistics<G extends Game>(identifier: string, game_id: G, options?: Options): Promise<APIResponse<StatisticsResponse<G, Timeframe.AllTime>>>;
9
+ export {};
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
26
+ }) : function(o, v) {
27
+ o["default"] = v;
28
+ });
29
+ var __importStar = (this && this.__importStar) || function (mod) {
30
+ if (mod && mod.__esModule) return mod;
31
+ var result = {};
32
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
+ __setModuleDefault(result, mod);
34
+ return result;
35
+ };
36
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
37
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
38
+ return new (P || (P = Promise))(function (resolve, reject) {
39
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
40
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
41
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
42
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
43
+ });
44
+ };
45
+ var __generator = (this && this.__generator) || function (thisArg, body) {
46
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
47
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
48
+ function verb(n) { return function (v) { return step([n, v]); }; }
49
+ function step(op) {
50
+ if (f) throw new TypeError("Generator is already executing.");
51
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
52
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
53
+ if (y = 0, t) op = [op[0] & 2, t.value];
54
+ switch (op[0]) {
55
+ case 0: case 1: t = op; break;
56
+ case 4: _.label++; return { value: op[1], done: false };
57
+ case 5: _.label++; y = op[1]; op = [0]; continue;
58
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
59
+ default:
60
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
61
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
62
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
63
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
64
+ if (t[2]) _.ops.pop();
65
+ _.trys.pop(); continue;
66
+ }
67
+ op = body.call(thisArg, _);
68
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
69
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
70
+ }
71
+ };
72
+ var __values = (this && this.__values) || function(o) {
73
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
74
+ if (m) return m.call(o);
75
+ if (o && typeof o.length === "number") return {
76
+ next: function () {
77
+ if (o && i >= o.length) o = void 0;
78
+ return { value: o && o[i++], done: !o };
79
+ }
80
+ };
81
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
82
+ };
83
+ var __read = (this && this.__read) || function (o, n) {
84
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
85
+ if (!m) return o;
86
+ var i = m.call(o), r, ar = [], e;
87
+ try {
88
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
89
+ }
90
+ catch (error) { e = { error: error }; }
91
+ finally {
92
+ try {
93
+ if (r && !r.done && (m = i["return"])) m.call(i);
94
+ }
95
+ finally { if (e) throw e.error; }
96
+ }
97
+ return ar;
98
+ };
99
+ var __importDefault = (this && this.__importDefault) || function (mod) {
100
+ return (mod && mod.__esModule) ? mod : { "default": mod };
101
+ };
102
+ Object.defineProperty(exports, "__esModule", { value: true });
103
+ var hive_bedrock_data_1 = require("hive-bedrock-data");
104
+ var isGame_1 = __importDefault(require("../helpers/isGame"));
105
+ var fetchEndpoint_1 = __importDefault(require("../helpers/fetchEndpoint"));
106
+ var processors_1 = __importStar(require("../processors"));
107
+ function getAllTimeStatistics(identifier, game_or_options, options) {
108
+ return __awaiter(this, void 0, void 0, function () {
109
+ var game_id, method_options, response, games, output, _loop_1, games_1, games_1_1, _a, g, stats, player_1, processors_2, response_data, processors;
110
+ var e_1, _b;
111
+ var _c;
112
+ return __generator(this, function (_d) {
113
+ switch (_d.label) {
114
+ case 0:
115
+ game_id = "all";
116
+ method_options = game_or_options;
117
+ if (typeof game_or_options === "string") {
118
+ game_id = game_or_options;
119
+ method_options = options;
120
+ }
121
+ if (!(0, isGame_1.default)(game_id) && game_id !== "all")
122
+ return [2 /*return*/, {
123
+ status: 404,
124
+ error: {
125
+ code: 404,
126
+ message: "Game not found.",
127
+ },
128
+ data: null,
129
+ }];
130
+ return [4 /*yield*/, (0, fetchEndpoint_1.default)("/game/all/".concat(game_id, "/").concat(identifier), method_options === null || method_options === void 0 ? void 0 : method_options.init)];
131
+ case 1:
132
+ response = _d.sent();
133
+ if (response.error)
134
+ return [2 /*return*/, response];
135
+ if (game_id === "all") {
136
+ games = Object.entries(response.data);
137
+ output = {};
138
+ _loop_1 = function (g, stats) {
139
+ if ((0, isGame_1.default)(g)) {
140
+ if (Array.isArray(stats)) {
141
+ output[g] = null;
142
+ return "continue";
143
+ }
144
+ var processors_3 = (0, processors_1.default)(g, hive_bedrock_data_1.Timeframe.AllTime);
145
+ processors_3.forEach(function (processor) { return processor(stats); });
146
+ output[g] = stats;
147
+ }
148
+ };
149
+ try {
150
+ for (games_1 = __values(games), games_1_1 = games_1.next(); !games_1_1.done; games_1_1 = games_1.next()) {
151
+ _a = __read(games_1_1.value, 2), g = _a[0], stats = _a[1];
152
+ _loop_1(g, stats);
153
+ }
154
+ }
155
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
156
+ finally {
157
+ try {
158
+ if (games_1_1 && !games_1_1.done && (_b = games_1.return)) _b.call(games_1);
159
+ }
160
+ finally { if (e_1) throw e_1.error; }
161
+ }
162
+ player_1 = (_c = games.find(function (_a) {
163
+ var _b = __read(_a, 1), g = _b[0];
164
+ return g === "main";
165
+ })) === null || _c === void 0 ? void 0 : _c[1];
166
+ processors_2 = (0, processors_1.getPlayerProcessors)();
167
+ processors_2.forEach(function (processor) { return processor(player_1); });
168
+ return [2 /*return*/, __assign(__assign({}, response), { data: __assign(__assign({}, output), { player: player_1 }) })];
169
+ }
170
+ response_data = response.data;
171
+ if (Array.isArray(response_data))
172
+ return [2 /*return*/, __assign(__assign({}, response), { status: 404, data: null, error: { code: 404, message: "Not Found" } })];
173
+ processors = (0, processors_1.default)(game_id, hive_bedrock_data_1.Timeframe.AllTime);
174
+ processors.forEach(function (processor) { return processor(response_data); });
175
+ return [2 /*return*/, __assign(__assign({}, response), { data: response_data, error: null })];
176
+ }
177
+ });
178
+ });
179
+ }
180
+ exports.default = getAllTimeStatistics;
@@ -1,3 +1,3 @@
1
- import { API_GLOBAL_STATISTICS, Options } from "../types/API";
2
- import { MethodResponse } from "../types/METHODS";
3
- export default function getGlobalStatistics(options?: Options): Promise<MethodResponse<API_GLOBAL_STATISTICS>>;
1
+ import { GlobalStatisticsMetadata } from "hive-bedrock-data";
2
+ import { APIResponse, Options } from "../types/types";
3
+ export default function getGlobalStatistics(options?: Options): Promise<APIResponse<GlobalStatisticsMetadata>>;
@@ -1,15 +1,4 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -50,28 +39,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
50
39
  return (mod && mod.__esModule) ? mod : { "default": mod };
51
40
  };
52
41
  Object.defineProperty(exports, "__esModule", { value: true });
53
- var fetchData_1 = __importDefault(require("./fetchData"));
42
+ var fetchEndpoint_1 = __importDefault(require("../helpers/fetchEndpoint"));
54
43
  function getGlobalStatistics(options) {
55
44
  return __awaiter(this, void 0, void 0, function () {
56
- var _a, data, error, err_1;
57
- return __generator(this, function (_b) {
58
- switch (_b.label) {
59
- case 0:
60
- _b.trys.push([0, 2, , 3]);
61
- return [4 /*yield*/, (0, fetchData_1.default)("/global/statistics", options === null || options === void 0 ? void 0 : options.fetch)];
45
+ var response;
46
+ return __generator(this, function (_a) {
47
+ switch (_a.label) {
48
+ case 0: return [4 /*yield*/, (0, fetchEndpoint_1.default)("/global/statistics", options === null || options === void 0 ? void 0 : options.init)];
62
49
  case 1:
63
- _a = _b.sent(), data = _a.data, error = _a.error;
64
- if (error || !data)
65
- return [2 /*return*/, {
66
- data: null,
67
- error: __assign({ message: "Failed to fetch data." }, error),
68
- }];
69
- return [2 /*return*/, { data: data, error: null }];
70
- case 2:
71
- err_1 = _b.sent();
72
- console.error(err_1);
73
- return [2 /*return*/, { data: null, error: { message: "Failed to fetch data." } }];
74
- case 3: return [2 /*return*/];
50
+ response = _a.sent();
51
+ return [2 /*return*/, response];
75
52
  }
76
53
  });
77
54
  });