hive-bedrock-api 0.1.0-beta.0 → 0.1.0-beta.3

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.
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 and players.
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.
4
4
 
5
5
  ## Getting started
6
6
 
@@ -8,3 +8,92 @@ An API wrapper for the Hive Minecraft Bedrock Edition server. Which allows you t
8
8
  $ npm install hive-bedrock-api
9
9
  $ yarn add hive-bedrock-api
10
10
  ```
11
+
12
+ ## Usage
13
+
14
+ ### Fetch All-Time Player Statistics
15
+
16
+ ```ts
17
+ import { getAllTimeStats, GAME } from "hive-bedrock-api";
18
+
19
+ // Returns all games
20
+ const { data, player, error } = await getAllTimeStats("ucdfiddes");
21
+
22
+ // Returns multiple specific games
23
+ const { data, player, error } = await getAllTimeStats("ucdfiddes", [
24
+ GAME.Deathrun,
25
+ GAME.TheBridge,
26
+ ]);
27
+
28
+ // Returns a single game
29
+ const { data, error } = await getAllTimeStats("ucdfiddes", GAME.HideAndSeek);
30
+ ```
31
+
32
+ ### Fetch Monthly Player Statistics
33
+
34
+ ```ts
35
+ import { getMonthlyStats, GAME } from "hive-bedrock-api";
36
+
37
+ // Returns all games
38
+ const { data, error } = await getMonthlyStats("ucdfiddes");
39
+
40
+ // Returns multiple specific games
41
+ const { data, error } = await getMonthlyStats("ucdfiddes", [
42
+ GAME.Deathrun,
43
+ GAME.TheBridge,
44
+ ]);
45
+
46
+ // Returns a single game
47
+ const { data, error } = await getMonthlyStats("ucdfiddes", GAME.BlockDrop);
48
+
49
+ // Returns a single game in a previous month (can return muliple games)
50
+ const { data, error } = await getMonthlyStats("ucdfiddes", GAME.BlockDrop, {
51
+ year: 2023,
52
+ month: 1, // January
53
+ });
54
+ ```
55
+
56
+ ### Fetch All-Time Leaderboard
57
+
58
+ ```ts
59
+ import { getAllTimeLeaderboard, GAME } from "hive-bedrock-api";
60
+
61
+ // Returns asingle game
62
+ const { data, error } = await getAllTimeLeaderboard(GAME.TreasureWars);
63
+ ```
64
+
65
+ ### Fetch Monthly Leaderboard
66
+
67
+ ```ts
68
+ import { getMonthlyLeaderboard, GAME } from "hive-bedrock-api";
69
+
70
+ // Returns asingle game
71
+ const { data, error } = await getMonthlyLeaderboard(GAME.TreasureWars);
72
+
73
+ // Returns a single game from a previous month
74
+ const { data, error } = await getMonthlyLeaderboard(GAME.BlockParty, {
75
+ year: 2023,
76
+ month: 11, // November
77
+ amount: 50,
78
+ skip: 20, // Sum of skip and amount must be <=100
79
+ });
80
+ ```
81
+
82
+ ### Fetch Global Statistics
83
+
84
+ ```ts
85
+ import { getGlobalStatistics } from "hive-bedrock-api";
86
+
87
+ // Returns unqiue total player counts for different games
88
+ const { data, error } = await getGlobalStatistics();
89
+ ```
90
+
91
+ ## API Response Changes
92
+
93
+ Different API responses are edited by the wrapper to provide more data:
94
+
95
+ - Game responses have a new value "id" showing the parent game
96
+ - "first_played" values are converted into a Date object
97
+ - A new value for "losses" is provided
98
+ - A new value for "kdr" is provided
99
+ - "xp" is converted and a "level" is provided
@@ -0,0 +1,29 @@
1
+ import { GAME } from "../types/GAME_INFO";
2
+ interface SingleGameFormat {
3
+ [key: string]: any;
4
+ }
5
+ interface GameFormat {
6
+ [key: string]: SingleGameFormat | null;
7
+ }
8
+ export declare const formats: {
9
+ main: (player: SingleGameFormat) => SingleGameFormat;
10
+ default: (gameType: GAME, game: SingleGameFormat | null) => {
11
+ id: GAME;
12
+ } | null;
13
+ drop: (game: SingleGameFormat | null) => SingleGameFormat | null;
14
+ party: (game: SingleGameFormat | null) => SingleGameFormat | null;
15
+ ctf: (game: SingleGameFormat | null) => SingleGameFormat | null;
16
+ dr: (game: SingleGameFormat | null) => SingleGameFormat | null;
17
+ ground: (game: SingleGameFormat | null) => SingleGameFormat | null;
18
+ hide: (game: SingleGameFormat | null) => SingleGameFormat | null;
19
+ build: (game: SingleGameFormat | null) => SingleGameFormat | null;
20
+ murder: (game: SingleGameFormat | null) => SingleGameFormat | null;
21
+ sky: (game: SingleGameFormat | null) => SingleGameFormat | null;
22
+ sg: (game: SingleGameFormat | null) => SingleGameFormat | null;
23
+ wars: (game: SingleGameFormat | null) => SingleGameFormat | null;
24
+ bridge: (game: SingleGameFormat | null) => SingleGameFormat | null;
25
+ };
26
+ export declare function gameFormatArray(gameType: GAME, games: SingleGameFormat[]): (SingleGameFormat | null)[];
27
+ export default function gameFormat(games: GameFormat, returnAsSingle: true): SingleGameFormat | null;
28
+ export default function gameFormat(games: GameFormat): GameFormat | null;
29
+ export {};
@@ -0,0 +1,131 @@
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 __read = (this && this.__read) || function (o, n) {
14
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
15
+ if (!m) return o;
16
+ var i = m.call(o), r, ar = [], e;
17
+ try {
18
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
19
+ }
20
+ catch (error) { e = { error: error }; }
21
+ finally {
22
+ try {
23
+ if (r && !r.done && (m = i["return"])) m.call(i);
24
+ }
25
+ finally { if (e) throw e.error; }
26
+ }
27
+ return ar;
28
+ };
29
+ var __importDefault = (this && this.__importDefault) || function (mod) {
30
+ return (mod && mod.__esModule) ? mod : { "default": mod };
31
+ };
32
+ var _a;
33
+ Object.defineProperty(exports, "__esModule", { value: true });
34
+ exports.gameFormatArray = exports.formats = void 0;
35
+ var calculateLevel_1 = __importDefault(require("../methods/calculateLevel"));
36
+ var GAME_INFO_1 = require("../types/GAME_INFO");
37
+ exports.formats = (_a = {
38
+ main: function (player) {
39
+ if ("first_played" in player)
40
+ player.first_played = new Date(player.first_played * 1000);
41
+ return player;
42
+ },
43
+ default: function (gameType, game) {
44
+ if (!game)
45
+ return null;
46
+ if ("index" in game && game.index == 2147483646)
47
+ return null;
48
+ if ("xp" in game) {
49
+ game.level = (0, calculateLevel_1.default)(game.xp, GAME_INFO_1.GAME.CaptureTheFlag);
50
+ }
51
+ else
52
+ return null;
53
+ if ("first_played" in game)
54
+ game.first_played = new Date(game.first_played * 1000);
55
+ if ("played" in game && "victories" in game) {
56
+ game.losses = game.played - game.victories;
57
+ game.win_percentage = parseFloat((game.victories / game.played).toFixed(2));
58
+ }
59
+ if ("kills" in game && "deaths" in game)
60
+ game.kdr = parseFloat((game.kills / game.deaths).toFixed(2));
61
+ return __assign({ id: gameType }, game);
62
+ }
63
+ },
64
+ _a[GAME_INFO_1.GAME.BlockDrop] = function (game) {
65
+ return game;
66
+ },
67
+ _a[GAME_INFO_1.GAME.BlockParty] = function (game) {
68
+ return game;
69
+ },
70
+ _a[GAME_INFO_1.GAME.CaptureTheFlag] = function (game) {
71
+ return game;
72
+ },
73
+ _a[GAME_INFO_1.GAME.DeathRun] = function (game) {
74
+ return game;
75
+ },
76
+ _a[GAME_INFO_1.GAME.GroundWars] = function (game) {
77
+ return game;
78
+ },
79
+ _a[GAME_INFO_1.GAME.HideAndSeek] = function (game) {
80
+ if (!game)
81
+ return null;
82
+ if ("hider_kills" in game && "deaths" in game)
83
+ game.kdr = parseFloat((game.hider_kills / game.deaths).toFixed(2));
84
+ return game;
85
+ },
86
+ _a[GAME_INFO_1.GAME.JustBuild] = function (game) {
87
+ return game;
88
+ },
89
+ _a[GAME_INFO_1.GAME.MurderMystery] = function (game) {
90
+ if (!game)
91
+ return null;
92
+ if ("murders" in game && "deaths" in game)
93
+ game.kdr = parseFloat((game.murders / game.deaths).toFixed(2));
94
+ return game;
95
+ },
96
+ _a[GAME_INFO_1.GAME.Skywars] = function (game) {
97
+ return game;
98
+ },
99
+ _a[GAME_INFO_1.GAME.SurvivalGames] = function (game) {
100
+ return game;
101
+ },
102
+ _a[GAME_INFO_1.GAME.TreasureWars] = function (game) {
103
+ return game;
104
+ },
105
+ _a[GAME_INFO_1.GAME.TheBridge] = function (game) {
106
+ return game;
107
+ },
108
+ _a);
109
+ function gameFormatArray(gameType, games) {
110
+ return games.map(function (game) {
111
+ var _a;
112
+ return gameFormat((_a = {},
113
+ _a[gameType] = game,
114
+ _a), true);
115
+ });
116
+ }
117
+ exports.gameFormatArray = gameFormatArray;
118
+ function gameFormat(games, returnAsSingle) {
119
+ var formatted = Object.fromEntries(Object.entries(games).map(function (_a) {
120
+ var _b = __read(_a, 2), key = _b[0], data = _b[1];
121
+ if (!data)
122
+ return [key, null];
123
+ var defaultFormat = exports.formats.default(key, data);
124
+ if (!defaultFormat)
125
+ return [key, null];
126
+ var gameFormat = exports.formats[key](defaultFormat);
127
+ return [key, gameFormat];
128
+ }));
129
+ return returnAsSingle ? Object.values(formatted)[0] : formatted;
130
+ }
131
+ exports.default = gameFormat;
package/lib/index.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import getMonthlyStats from "./methods/getMonthlyStats";
2
+ import getMonthlyLeaderboard from "./methods/getMonthlyLeaderboard";
3
+ import getAllTimeStats from "./methods/getAllTimeStats";
4
+ import getAllTimeLeaderboard from "./methods/getAllTimeLeaderboard";
5
+ import getGlobalStatistics from "./methods/getGlobalStatistics";
6
+ import { AVATAR, RANK } from "./types/API";
7
+ export { getAllTimeStats, getAllTimeLeaderboard, getMonthlyStats, getMonthlyLeaderboard, getGlobalStatistics, AVATAR, RANK, };
8
+ export * from "./types/GAME_INFO";
9
+ export * from "./types/GAMES";
package/lib/index.js ADDED
@@ -0,0 +1,32 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ 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;
27
+ var getAllTimeLeaderboard_1 = __importDefault(require("./methods/getAllTimeLeaderboard"));
28
+ exports.getAllTimeLeaderboard = getAllTimeLeaderboard_1.default;
29
+ var getGlobalStatistics_1 = __importDefault(require("./methods/getGlobalStatistics"));
30
+ exports.getGlobalStatistics = getGlobalStatistics_1.default;
31
+ __exportStar(require("./types/GAME_INFO"), exports);
32
+ __exportStar(require("./types/GAMES"), exports);
@@ -0,0 +1,2 @@
1
+ import { GAME } from "../types/GAME_INFO";
2
+ export default function calculateLevel(xp: number, game: GAME): number;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var GAME_INFO_1 = require("../types/GAME_INFO");
4
+ function calculateLevel(xp, game) {
5
+ if (game === GAME_INFO_1.GAME.TheBridge) {
6
+ var lastXp = 0;
7
+ var currentXp = 300;
8
+ var increment = 300;
9
+ var additionalIncrement = 300;
10
+ var i = 2;
11
+ while (true) {
12
+ if (xp === currentXp)
13
+ return i;
14
+ else if (xp < currentXp)
15
+ return i + (xp - lastXp) / (currentXp - lastXp) - 1;
16
+ additionalIncrement = Math.floor(additionalIncrement * 1.08);
17
+ increment += additionalIncrement;
18
+ lastXp = currentXp;
19
+ currentXp += increment;
20
+ i++;
21
+ }
22
+ }
23
+ var gameInfo = GAME_INFO_1.GAME_INFO[game];
24
+ var INCREMENT = gameInfo.increment / 2;
25
+ var INCREMENT_CAP = gameInfo.incrementCap;
26
+ var level = (INCREMENT + Math.sqrt(INCREMENT * (INCREMENT + 4 * xp))) /
27
+ (2 * INCREMENT);
28
+ if (!INCREMENT_CAP || level <= INCREMENT_CAP)
29
+ return boundLevel(level, gameInfo.maxLevel);
30
+ level =
31
+ INCREMENT_CAP +
32
+ (xp -
33
+ (INCREMENT * Math.pow(INCREMENT_CAP - 1, 2) +
34
+ (INCREMENT_CAP - 1) * INCREMENT)) /
35
+ ((INCREMENT_CAP - 1) * INCREMENT * 2);
36
+ return boundLevel(level, gameInfo.maxLevel);
37
+ }
38
+ exports.default = calculateLevel;
39
+ function boundLevel(level, maxLevel) {
40
+ if (level < 0)
41
+ return 0;
42
+ if (level > maxLevel)
43
+ return maxLevel;
44
+ return parseFloat(level.toFixed(2));
45
+ }
@@ -0,0 +1,14 @@
1
+ import { API_BASE_GAME_ALL, API_BASE_GAME_MONTHLY, API_GAME_STATS, API_GLOBAL_STATISTICS, API_REQUEST_ALL, API_REQUEST_LB } from "../types/API";
2
+ import { GAME_LB_ALLTIME_ENDPOINT, GAME_LB_MONTHLY_ENDPOINT, GAME_LB_SPECIFIC_MONTHLY_ENDPOINT, GLOBAL_STATISTICS_ENDPOINT, PLAYER_ALLTIME_ENDPOINT, PLAYER_LB_SPECIFIC_MONTHLY_ENDPOINT, PLAYER_MONTHLY_ENDPOINT } from "../types/ENDPOINTS";
3
+ import { GAME } from "../types/GAME_INFO";
4
+ import { MethodResponse } from "../types/METHODS";
5
+ export declare const API_ROOT = "https://api.playhive.com/v0";
6
+ export default function fetchData(endpoint: PLAYER_ALLTIME_ENDPOINT<"all", string>): Promise<MethodResponse<API_REQUEST_ALL>>;
7
+ export default function fetchData<G extends GAME>(endpoint: PLAYER_ALLTIME_ENDPOINT<G, string>): Promise<MethodResponse<API_GAME_STATS<API_BASE_GAME_ALL>[G]>>;
8
+ export default function fetchData(endpoint: PLAYER_MONTHLY_ENDPOINT<"all", string>): Promise<MethodResponse<API_GAME_STATS<API_BASE_GAME_MONTHLY>>>;
9
+ export default function fetchData<G extends GAME>(endpoint: PLAYER_MONTHLY_ENDPOINT<G, string>): Promise<MethodResponse<API_GAME_STATS<API_BASE_GAME_MONTHLY>[G]>>;
10
+ export default function fetchData<G extends GAME>(endpoint: GAME_LB_ALLTIME_ENDPOINT<G>): Promise<MethodResponse<API_REQUEST_LB<G>>>;
11
+ export default function fetchData<G extends GAME>(endpoint: GAME_LB_MONTHLY_ENDPOINT<G>): Promise<MethodResponse<API_REQUEST_LB<G>>>;
12
+ export default function fetchData<G extends GAME>(endpoint: PLAYER_LB_SPECIFIC_MONTHLY_ENDPOINT<G, string, number, number, number, number>): Promise<MethodResponse<API_REQUEST_LB<G>>>;
13
+ export default function fetchData<G extends GAME>(endpoint: GAME_LB_SPECIFIC_MONTHLY_ENDPOINT<G, number, number, number, number>): Promise<MethodResponse<API_REQUEST_LB<G>>>;
14
+ export default function fetchData(endpoint: GLOBAL_STATISTICS_ENDPOINT): Promise<MethodResponse<API_GLOBAL_STATISTICS>>;
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ 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;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
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) {
42
+ return __awaiter(this, void 0, void 0, function () {
43
+ var request, response, err_1;
44
+ return __generator(this, function (_a) {
45
+ switch (_a.label) {
46
+ case 0:
47
+ _a.trys.push([0, 3, , 4]);
48
+ return [4 /*yield*/, fetch(exports.API_ROOT + endpoint)];
49
+ case 1:
50
+ request = _a.sent();
51
+ if (!request.ok)
52
+ return [2 /*return*/, {
53
+ data: null,
54
+ error: {
55
+ message: request.statusText,
56
+ status: request.status,
57
+ endpoint: exports.API_ROOT + endpoint,
58
+ },
59
+ }];
60
+ return [4 /*yield*/, request.json()];
61
+ case 2:
62
+ response = _a.sent();
63
+ return [2 /*return*/, {
64
+ data: response,
65
+ error: null,
66
+ }];
67
+ case 3:
68
+ err_1 = _a.sent();
69
+ console.error(err_1);
70
+ return [2 /*return*/, {
71
+ data: null,
72
+ error: { message: "Failed to fetch data." },
73
+ }];
74
+ case 4: return [2 /*return*/];
75
+ }
76
+ });
77
+ });
78
+ }
79
+ exports.default = fetchData;
@@ -0,0 +1,4 @@
1
+ import { LB_STATS } from "../types/GAMES";
2
+ import { GAME } from "../types/GAME_INFO";
3
+ import { MethodResponse } from "../types/METHODS";
4
+ export default function getAllTimeLeaderboard<G extends GAME>(game: G): Promise<MethodResponse<LB_STATS<G>[]>>;
@@ -0,0 +1,81 @@
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ 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;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __importDefault = (this && this.__importDefault) || function (mod) {
50
+ return (mod && mod.__esModule) ? mod : { "default": mod };
51
+ };
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) {
56
+ 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) {
60
+ case 0:
61
+ _b.trys.push([0, 2, , 3]);
62
+ return [4 /*yield*/, (0, fetchData_1.default)("/game/all/".concat(game))];
63
+ case 1:
64
+ _a = _b.sent(), data = _a.data, error = _a.error;
65
+ if (error || !data)
66
+ return [2 /*return*/, {
67
+ data: null,
68
+ error: __assign({ message: "Failed to fetch data." }, error),
69
+ }];
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*/];
77
+ }
78
+ });
79
+ });
80
+ }
81
+ exports.default = getAllTimeLeaderboard;
@@ -0,0 +1,12 @@
1
+ import { BASE_GAME_ALL, GAME_STATS, GAME_STATS_ALL, REQUEST_ALL, USER_MAIN } from "../types/GAMES";
2
+ import { GAME } from "../types/GAME_INFO";
3
+ import { MethodResponse } from "../types/METHODS";
4
+ export default function getAllTimeStats(playerIndentifier: string): Promise<MethodResponse<Omit<REQUEST_ALL, "main">> & {
5
+ player: USER_MAIN;
6
+ }>;
7
+ export default function getAllTimeStats<G extends GAME>(playerIdentifier: string, game: G): Promise<MethodResponse<GAME_STATS<BASE_GAME_ALL>[G]>>;
8
+ export default function getAllTimeStats<G extends GAME>(playerIdentifier: string, game: G[]): Promise<MethodResponse<{
9
+ [M in G]: GAME_STATS_ALL<M>;
10
+ }> & {
11
+ player: USER_MAIN;
12
+ }>;