hive-bedrock-api 1.0.10 → 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
@@ -0,0 +1,67 @@
1
+ import { Game, Leaderboards, Statistics, Timeframe } from "hive-bedrock-data";
2
+ type Processor = (stats: any) => void;
3
+ export type GameProcessors = {
4
+ [key in Game]: Processor[];
5
+ };
6
+ interface AllTimeAdditions {
7
+ level: number;
8
+ }
9
+ interface PvPAdditions {
10
+ kdr: number;
11
+ }
12
+ interface CommonStatistics {
13
+ id: Game;
14
+ played: number;
15
+ victories: number;
16
+ losses: number;
17
+ win_percentage: number;
18
+ }
19
+ type BaseStatistics<G extends Game, T extends Timeframe> = Statistics<G, T> & CommonStatistics & (T extends Timeframe.AllTime ? AllTimeAdditions : unknown);
20
+ export type StatisticsResponse<G extends Game, T extends Timeframe> = AllStatistics<T>[G];
21
+ export interface AllStatistics<T extends Timeframe> {
22
+ [Game.BlockDrop]: BaseStatistics<Game.BlockDrop, T>;
23
+ [Game.BlockParty]: BaseStatistics<Game.BlockParty, T>;
24
+ [Game.CaptureTheFlag]: BaseStatistics<Game.CaptureTheFlag, T> & PvPAdditions;
25
+ [Game.DeathRun]: BaseStatistics<Game.DeathRun, T>;
26
+ [Game.Gravity]: BaseStatistics<Game.Gravity, T>;
27
+ [Game.GroundWars]: BaseStatistics<Game.GroundWars, T> & PvPAdditions;
28
+ [Game.HideAndSeek]: BaseStatistics<Game.HideAndSeek, T>;
29
+ [Game.JustBuild]: BaseStatistics<Game.JustBuild, T> & {
30
+ total_ratings: number;
31
+ };
32
+ [Game.MurderMystery]: BaseStatistics<Game.MurderMystery, T>;
33
+ [Game.Skywars]: BaseStatistics<Game.Skywars, T> & PvPAdditions;
34
+ [Game.SurvivalGames]: BaseStatistics<Game.SurvivalGames, T> & PvPAdditions;
35
+ [Game.TheBridge]: BaseStatistics<Game.TheBridge, T> & PvPAdditions;
36
+ [Game.TreasureWars]: BaseStatistics<Game.TreasureWars, T> & PvPAdditions;
37
+ }
38
+ interface CommonLeaderboard {
39
+ id: Game;
40
+ played: number;
41
+ victories: number;
42
+ losses: number;
43
+ win_percentage: number;
44
+ }
45
+ type BaseLeaderboard<G extends Game, T extends Timeframe> = Leaderboards<G, T> & CommonLeaderboard & (T extends Timeframe.AllTime ? AllTimeAdditions : unknown);
46
+ export type LeaderboardResponse<G extends Game, T extends Timeframe> = AllLeaderboards<T>[G];
47
+ export interface AllLeaderboards<T extends Timeframe> {
48
+ [Game.BlockDrop]: BaseLeaderboard<Game.BlockDrop, T>[];
49
+ [Game.BlockParty]: BaseLeaderboard<Game.BlockParty, T>[];
50
+ [Game.CaptureTheFlag]: BaseLeaderboard<Game.CaptureTheFlag, T>[];
51
+ [Game.DeathRun]: BaseLeaderboard<Game.DeathRun, T>[];
52
+ [Game.Gravity]: BaseLeaderboard<Game.Gravity, T>[];
53
+ [Game.GroundWars]: BaseLeaderboard<Game.GroundWars, T>[];
54
+ [Game.HideAndSeek]: BaseLeaderboard<Game.HideAndSeek, T>[];
55
+ [Game.JustBuild]: (BaseLeaderboard<Game.JustBuild, T> & {
56
+ total_ratings: number;
57
+ })[];
58
+ [Game.MurderMystery]: BaseLeaderboard<Game.MurderMystery, T>[];
59
+ [Game.Skywars]: BaseLeaderboard<Game.Skywars, T>[];
60
+ [Game.SurvivalGames]: BaseLeaderboard<Game.SurvivalGames, T>[];
61
+ [Game.TheBridge]: BaseLeaderboard<Game.TheBridge, T>[];
62
+ [Game.TreasureWars]: BaseLeaderboard<Game.TreasureWars, T>[];
63
+ }
64
+ export type AllGameStatistics<T extends Timeframe> = {
65
+ [key in Game]: BaseStatistics<key, T> | null;
66
+ };
67
+ export {};
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var GAME_INFO_1 = require("./GAME_INFO");
3
+ var hive_bedrock_data_1 = require("hive-bedrock-data");
@@ -0,0 +1,21 @@
1
+ interface APIResponse_Base {
2
+ duration?: number;
3
+ status: number;
4
+ }
5
+ interface APIResponse_Error {
6
+ code: number;
7
+ message: string;
8
+ }
9
+ export interface APIResponse_Success<T> extends APIResponse_Base {
10
+ error: null;
11
+ data: T;
12
+ }
13
+ export interface APIResponse_Failure extends APIResponse_Base {
14
+ error: APIResponse_Error;
15
+ data: null;
16
+ }
17
+ export type APIResponse<T> = APIResponse_Success<T> | APIResponse_Failure;
18
+ export interface Options {
19
+ init: RequestInit;
20
+ }
21
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hive-bedrock-api",
3
- "version": "1.0.10",
3
+ "version": "2.0.0",
4
4
  "description": "An API wrapper for the Hive Minecraft Bedrock Edition server.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -10,19 +10,18 @@
10
10
  },
11
11
  "license": "MIT",
12
12
  "author": "Cubeedge Studios",
13
- "dependencies": {},
13
+ "dependencies": {
14
+ "hive-bedrock-data": "^1.1.7"
15
+ },
14
16
  "scripts": {
15
- "build": "tsc",
16
- "test": "jest"
17
+ "prepack": "yarn build",
18
+ "prepare": "npm run build",
19
+ "build": "tsc"
17
20
  },
18
21
  "files": [
19
22
  "lib/**/*"
20
23
  ],
21
24
  "devDependencies": {
22
- "@types/jest": "^29.5.2",
23
- "jest": "^29.5.0",
24
- "jest-extended": "^4.0.0",
25
- "ts-jest": "^29.1.0",
26
25
  "ts-node": "^10.9.1",
27
26
  "typescript": "^5.1.3"
28
27
  }
@@ -1,30 +0,0 @@
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
- grav: (game: SingleGameFormat | null) => SingleGameFormat | null;
25
- bridge: (game: SingleGameFormat | null) => SingleGameFormat | null;
26
- };
27
- export declare function gameFormatArray(gameType: GAME, games: SingleGameFormat[]): (SingleGameFormat | null)[];
28
- export default function gameFormat(games: GameFormat, returnAsSingle: true): SingleGameFormat | null;
29
- export default function gameFormat(games: GameFormat): GameFormat | null;
30
- export {};
@@ -1,164 +0,0 @@
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
- return player;
40
- },
41
- default: function (gameType, game) {
42
- var _a, _b, _c, _d;
43
- if (!game)
44
- return null;
45
- if ("index" in game && game.index == 2147483646)
46
- return null;
47
- if (!("index" in game)) {
48
- if ("xp" in game) {
49
- game.level = (0, calculateLevel_1.default)(game.xp, gameType);
50
- }
51
- else
52
- return null;
53
- }
54
- if ("played" in game && "victories" in game) {
55
- game.losses = ((_a = game.played) !== null && _a !== void 0 ? _a : 0) - ((_b = game.victories) !== null && _b !== void 0 ? _b : 0);
56
- game.win_percentage = game.victories / game.played;
57
- if (isNaN(game.win_percentage))
58
- game.win_percentage = 0;
59
- }
60
- if ("kills" in game && "deaths" in game)
61
- game.kdr = parseFloat((((_c = game.kills) !== null && _c !== void 0 ? _c : 0) / ((_d = game.deaths) !== null && _d !== void 0 ? _d : 0)).toFixed(2));
62
- return __assign({ id: gameType }, game);
63
- }
64
- },
65
- _a[GAME_INFO_1.GAME.BlockDrop] = function (game) {
66
- return game;
67
- },
68
- _a[GAME_INFO_1.GAME.BlockParty] = function (game) {
69
- return game;
70
- },
71
- _a[GAME_INFO_1.GAME.CaptureTheFlag] = function (game) {
72
- return game;
73
- },
74
- _a[GAME_INFO_1.GAME.DeathRun] = function (game) {
75
- return game;
76
- },
77
- _a[GAME_INFO_1.GAME.GroundWars] = function (game) {
78
- return game;
79
- },
80
- _a[GAME_INFO_1.GAME.HideAndSeek] = function (game) {
81
- if (!game)
82
- return null;
83
- if ("hider_kills" in game && "deaths" in game)
84
- game.kdr = parseFloat((game.hider_kills / game.deaths).toFixed(2));
85
- return game;
86
- },
87
- _a[GAME_INFO_1.GAME.JustBuild] = function (game) {
88
- return game;
89
- },
90
- _a[GAME_INFO_1.GAME.MurderMystery] = function (game) {
91
- if (!game)
92
- return null;
93
- if ("murders" in game && "deaths" in game)
94
- game.kdr = parseFloat((game.murders / game.deaths).toFixed(2));
95
- return game;
96
- },
97
- _a[GAME_INFO_1.GAME.Skywars] = function (game) {
98
- return game;
99
- },
100
- _a[GAME_INFO_1.GAME.SurvivalGames] = function (game) {
101
- return game;
102
- },
103
- _a[GAME_INFO_1.GAME.TreasureWars] = function (game) {
104
- return game;
105
- },
106
- _a[GAME_INFO_1.GAME.Gravity] = function (game) {
107
- return game;
108
- },
109
- _a[GAME_INFO_1.GAME.TheBridge] = function (game) {
110
- var _a, _b;
111
- if (!game)
112
- return null;
113
- if ("m_solo_deaths" in game) {
114
- game.deaths = game.m_solo_deaths;
115
- delete game.m_solo_deaths;
116
- }
117
- if ("m_solo_goals" in game) {
118
- game.goals = game.m_solo_goals;
119
- delete game.m_solo_goals;
120
- }
121
- if ("m_solo_kills" in game) {
122
- game.kills = game.m_solo_kills;
123
- delete game.m_solo_kills;
124
- }
125
- if ("m_solo_played" in game) {
126
- game.played = game.m_solo_played;
127
- delete game.m_solo_played;
128
- }
129
- if ("m_solo_victories" in game) {
130
- game.victories = game.m_solo_victories;
131
- delete game.m_solo_victories;
132
- }
133
- if ("played" in game && "victories" in game) {
134
- game.losses = (_b = (_a = game.played) !== null && _a !== void 0 ? _a : 0 - game.victories) !== null && _b !== void 0 ? _b : 0;
135
- game.win_percentage = game.victories / game.played;
136
- if (isNaN(game.win_percentage))
137
- game.win_percentage = 0;
138
- }
139
- return game;
140
- },
141
- _a);
142
- function gameFormatArray(gameType, games) {
143
- return games.map(function (game) {
144
- var _a;
145
- return gameFormat((_a = {},
146
- _a[gameType] = game,
147
- _a), true);
148
- });
149
- }
150
- exports.gameFormatArray = gameFormatArray;
151
- function gameFormat(games, returnAsSingle) {
152
- var formatted = Object.fromEntries(Object.entries(games).map(function (_a) {
153
- var _b = __read(_a, 2), key = _b[0], data = _b[1];
154
- if (!data)
155
- return [key, null];
156
- var defaultFormat = exports.formats.default(key, data);
157
- if (!defaultFormat)
158
- return [key, null];
159
- var gameFormat = exports.formats[key](defaultFormat);
160
- return [key, gameFormat];
161
- }));
162
- return returnAsSingle ? Object.values(formatted)[0] : formatted;
163
- }
164
- exports.default = gameFormat;
@@ -1,2 +0,0 @@
1
- import { GAME } from "../types/GAME_INFO";
2
- export default function calculateLevel(xp: number, game: GAME): number;
@@ -1,45 +0,0 @@
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
- }
@@ -1,25 +0,0 @@
1
- import { API_BASE_GAME_ALL, API_BASE_GAME_MONTHLY, API_GAME_STATS, API_GLOBAL_STATISTICS, API_MAP, API_METADATA, API_REQUEST_ALL, API_REQUEST_LB } from "../types/API";
2
- import { GAME_LB_ALLTIME_ENDPOINT, GAME_LB_MONTHLY_ENDPOINT, GAME_LB_SPECIFIC_MONTHLY_ENDPOINT, GAME_MAPS_ENDPOINT, GAME_METADATA_ENDPOINT, GLOBAL_STATISTICS_ENDPOINT, PLAYER_ALLTIME_ENDPOINT, PLAYER_LB_SPECIFIC_MONTHLY_ENDPOINT, PLAYER_MONTHLY_ENDPOINT } from "../types/ENDPOINTS";
3
- import { USER_MAIN } from "../types/GAMES";
4
- import { GAME } from "../types/GAME_INFO";
5
- import { MethodResponse } from "../types/METHODS";
6
- export interface FetchOptions {
7
- headers: {
8
- [key: string]: string;
9
- };
10
- }
11
- export declare const API_ROOT = "https://api.playhive.com/v0";
12
- export default function fetchData(endpoint: PLAYER_ALLTIME_ENDPOINT<"all", string>, options?: FetchOptions): Promise<MethodResponse<API_REQUEST_ALL>>;
13
- export default function fetchData(endpoint: PLAYER_ALLTIME_ENDPOINT<"main", string>, options?: FetchOptions): Promise<MethodResponse<{
14
- main: USER_MAIN;
15
- }>>;
16
- export default function fetchData<G extends GAME>(endpoint: PLAYER_ALLTIME_ENDPOINT<G, string>, options?: FetchOptions): Promise<MethodResponse<API_GAME_STATS<API_BASE_GAME_ALL>[G]>>;
17
- export default function fetchData(endpoint: PLAYER_MONTHLY_ENDPOINT<"all", string>, options?: FetchOptions): Promise<MethodResponse<API_GAME_STATS<API_BASE_GAME_MONTHLY>>>;
18
- export default function fetchData<G extends GAME>(endpoint: PLAYER_MONTHLY_ENDPOINT<G, string>, options?: FetchOptions): Promise<MethodResponse<API_GAME_STATS<API_BASE_GAME_MONTHLY>[G]>>;
19
- export default function fetchData<G extends GAME>(endpoint: GAME_LB_ALLTIME_ENDPOINT<G>, options?: FetchOptions): Promise<MethodResponse<API_REQUEST_LB<G>>>;
20
- export default function fetchData<G extends GAME>(endpoint: GAME_LB_MONTHLY_ENDPOINT<G>, options?: FetchOptions): Promise<MethodResponse<API_REQUEST_LB<G>>>;
21
- export default function fetchData<G extends GAME>(endpoint: PLAYER_LB_SPECIFIC_MONTHLY_ENDPOINT<G, string, number, number, number, number>, options?: FetchOptions): Promise<MethodResponse<API_REQUEST_LB<G>>>;
22
- export default function fetchData<G extends GAME>(endpoint: GAME_LB_SPECIFIC_MONTHLY_ENDPOINT<G, number, number, number, number>, options?: FetchOptions): Promise<MethodResponse<API_REQUEST_LB<G>>>;
23
- export default function fetchData(endpoint: GLOBAL_STATISTICS_ENDPOINT, options?: FetchOptions): Promise<MethodResponse<API_GLOBAL_STATISTICS>>;
24
- export default function fetchData<G extends GAME>(endpoint: GAME_MAPS_ENDPOINT<G>, options?: FetchOptions): Promise<MethodResponse<API_MAP[]>>;
25
- export default function fetchData<G extends GAME>(endpoint: GAME_METADATA_ENDPOINT<G>, options?: FetchOptions): Promise<MethodResponse<API_METADATA>>;
@@ -1,13 +0,0 @@
1
- import { Options } from "../types/API";
2
- import { BASE_GAME_ALL, GAME_STATS, GAME_STATS_ALL, REQUEST_ALL, USER_MAIN } from "../types/GAMES";
3
- import { GAME } from "../types/GAME_INFO";
4
- import { MethodResponse } from "../types/METHODS";
5
- export default function getAllTimeStats(playerIdentifier: string, options?: Options): Promise<MethodResponse<Omit<REQUEST_ALL, "main">> & {
6
- player: USER_MAIN;
7
- }>;
8
- export default function getAllTimeStats<G extends GAME>(playerIdentifier: string, game: G, options?: Options): Promise<MethodResponse<GAME_STATS<BASE_GAME_ALL>[G]>>;
9
- export default function getAllTimeStats<G extends GAME>(playerIdentifier: string, game: G[], options?: Options): Promise<MethodResponse<{
10
- [M in G]: GAME_STATS_ALL<M>;
11
- }> & {
12
- player: USER_MAIN;
13
- }>;
@@ -1,186 +0,0 @@
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 __read = (this && this.__read) || function (o, n) {
73
- var m = typeof Symbol === "function" && o[Symbol.iterator];
74
- if (!m) return o;
75
- var i = m.call(o), r, ar = [], e;
76
- try {
77
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
78
- }
79
- catch (error) { e = { error: error }; }
80
- finally {
81
- try {
82
- if (r && !r.done && (m = i["return"])) m.call(i);
83
- }
84
- finally { if (e) throw e.error; }
85
- }
86
- return ar;
87
- };
88
- var __importDefault = (this && this.__importDefault) || function (mod) {
89
- return (mod && mod.__esModule) ? mod : { "default": mod };
90
- };
91
- Object.defineProperty(exports, "__esModule", { value: true });
92
- var gameFormat_1 = __importStar(require("../format/gameFormat"));
93
- var GAME_INFO_1 = require("../types/GAME_INFO");
94
- var fetchData_1 = __importDefault(require("./fetchData"));
95
- function getAllTimeStats(playerIdentifier, game, options) {
96
- return __awaiter(this, void 0, void 0, function () {
97
- var _a, data, error, gameData, filteredGamesEntries, filteredGames, err_1, _b, data, error, gameData, err_2, _c, data, error, gameData, FILTER_GAMES_1, filteredGamesEntries, filteredGames, err_3;
98
- var _d;
99
- return __generator(this, function (_e) {
100
- switch (_e.label) {
101
- case 0:
102
- if (typeof game === "object" && !(game instanceof Array)) {
103
- options = game;
104
- game = undefined;
105
- }
106
- if (!!game) return [3 /*break*/, 4];
107
- _e.label = 1;
108
- case 1:
109
- _e.trys.push([1, 3, , 4]);
110
- return [4 /*yield*/, (0, fetchData_1.default)("/game/all/all/".concat(playerIdentifier), options === null || options === void 0 ? void 0 : options.fetch)];
111
- case 2:
112
- _a = _e.sent(), data = _a.data, error = _a.error;
113
- if (error || !data)
114
- return [2 /*return*/, {
115
- data: null,
116
- error: __assign({ message: "Failed to fetch data." }, error),
117
- }];
118
- gameData = (0, gameFormat_1.default)(data);
119
- filteredGamesEntries = Object.entries(gameData).filter(function (_a) {
120
- var _b = __read(_a, 1), key = _b[0];
121
- return Object.values(GAME_INFO_1.GAME).includes(key);
122
- });
123
- filteredGames = Object.fromEntries(filteredGamesEntries);
124
- return [2 /*return*/, {
125
- data: filteredGames,
126
- error: null,
127
- player: gameFormat_1.formats.main(data.main),
128
- }];
129
- case 3:
130
- err_1 = _e.sent();
131
- console.error(err_1);
132
- return [2 /*return*/, { data: null, error: { message: "Failed to fetch data." } }];
133
- case 4:
134
- if (!(typeof game === "string")) return [3 /*break*/, 8];
135
- _e.label = 5;
136
- case 5:
137
- _e.trys.push([5, 7, , 8]);
138
- return [4 /*yield*/, (0, fetchData_1.default)("/game/all/".concat(game, "/").concat(playerIdentifier), options === null || options === void 0 ? void 0 : options.fetch)];
139
- case 6:
140
- _b = _e.sent(), data = _b.data, error = _b.error;
141
- if (error || !data)
142
- return [2 /*return*/, {
143
- data: null,
144
- error: __assign({ message: "Failed to fetch data." }, error),
145
- }];
146
- gameData = (0, gameFormat_1.default)((_d = {}, _d[game] = data, _d));
147
- return [2 /*return*/, { data: gameData[game], error: null }];
148
- case 7:
149
- err_2 = _e.sent();
150
- console.error(err_2);
151
- return [2 /*return*/, { data: null, error: { message: "Failed to fetch data." } }];
152
- case 8:
153
- if (!Array.isArray(game)) return [3 /*break*/, 12];
154
- _e.label = 9;
155
- case 9:
156
- _e.trys.push([9, 11, , 12]);
157
- return [4 /*yield*/, (0, fetchData_1.default)("/game/all/all/".concat(playerIdentifier), options === null || options === void 0 ? void 0 : options.fetch)];
158
- case 10:
159
- _c = _e.sent(), data = _c.data, error = _c.error;
160
- if (error || !data)
161
- return [2 /*return*/, {
162
- data: null,
163
- error: __assign({ message: "Failed to fetch data." }, error),
164
- }];
165
- gameData = (0, gameFormat_1.default)(data);
166
- FILTER_GAMES_1 = game;
167
- filteredGamesEntries = Object.entries(gameData).filter(function (_a) {
168
- var _b = __read(_a, 1), key = _b[0];
169
- return FILTER_GAMES_1.includes(key);
170
- });
171
- filteredGames = Object.fromEntries(filteredGamesEntries);
172
- return [2 /*return*/, {
173
- data: filteredGames,
174
- error: null,
175
- player: gameFormat_1.formats.main(data.main),
176
- }];
177
- case 11:
178
- err_3 = _e.sent();
179
- console.error(err_3);
180
- return [2 /*return*/, { data: null, error: { message: "Failed to fetch data." } }];
181
- case 12: return [2 /*return*/, { data: null, error: { message: "Failed to detect game type." } }];
182
- }
183
- });
184
- });
185
- }
186
- exports.default = getAllTimeStats;
@@ -1,4 +0,0 @@
1
- import { API_METADATA, Options } from "../types/API";
2
- import { GAME } from "../types/GAME_INFO";
3
- import { MethodResponse } from "../types/METHODS";
4
- export default function getGameMetadata(game: GAME, options?: Options): Promise<MethodResponse<API_METADATA>>;
@@ -1,15 +0,0 @@
1
- import { Options } from "../types/API";
2
- import { BASE_GAME_MONTHLY, GAME_STATS, GAME_STATS_ALL, REQUEST_MONTHLY } from "../types/GAMES";
3
- import { GAME } from "../types/GAME_INFO";
4
- import { MethodResponse } from "../types/METHODS";
5
- interface OptionsType extends Options {
6
- year?: number;
7
- month?: number;
8
- date?: Date;
9
- }
10
- export default function getMonthlyStats(playerIdentifier: string, options?: Options): Promise<MethodResponse<Omit<REQUEST_MONTHLY, "main">>>;
11
- export default function getMonthlyStats<G extends GAME>(playerIdentifier: string, game: G, options?: OptionsType): Promise<MethodResponse<GAME_STATS<BASE_GAME_MONTHLY>[G]>>;
12
- export default function getMonthlyStats<G extends GAME>(playerIdentifier: string, game: G[], options?: Options): Promise<MethodResponse<{
13
- [M in G]: GAME_STATS_ALL<M>;
14
- }>>;
15
- export {};