hive-bedrock-api 3.0.0-alpha.24 → 3.0.0-alpha.26
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/lib/helpers/fetchEndpoint.d.ts +3 -0
- package/lib/helpers/fetchEndpoint.js +88 -0
- package/lib/helpers/isGame.d.ts +2 -0
- package/lib/helpers/isGame.js +7 -0
- package/lib/helpers/toPoint.d.ts +1 -0
- package/lib/helpers/toPoint.js +10 -0
- package/lib/index.d.ts +9 -0
- package/lib/index.js +40 -0
- package/lib/methods/getAllTimeLeaderboard.d.ts +4 -0
- package/lib/methods/getAllTimeLeaderboard.js +85 -0
- package/lib/methods/getAllTimeStatistics.d.ts +10 -0
- package/lib/methods/getAllTimeStatistics.js +126 -0
- package/lib/methods/getGlobalStatistics.d.ts +3 -0
- package/lib/methods/getGlobalStatistics.js +56 -0
- package/lib/methods/getMaps.d.ts +3 -0
- package/lib/methods/getMaps.js +81 -0
- package/lib/methods/getMetadata.d.ts +3 -0
- package/lib/methods/getMetadata.js +81 -0
- package/lib/methods/getMonthlyLeaderboard.d.ts +11 -0
- package/lib/methods/getMonthlyLeaderboard.js +88 -0
- package/lib/methods/getMonthlyStatistics.d.ts +10 -0
- package/lib/methods/getMonthlyStatistics.js +132 -0
- package/lib/methods/getPlayerInfomation.d.ts +3 -0
- package/lib/methods/getPlayerInfomation.js +72 -0
- package/lib/methods/getSeasonLeaderboard.d.ts +10 -0
- package/lib/methods/getSeasonLeaderboard.js +87 -0
- package/lib/methods/getSeasonStatistics.d.ts +10 -0
- package/lib/methods/getSeasonStatistics.js +87 -0
- package/lib/processors/bed.d.ts +19 -0
- package/lib/processors/bed.js +35 -0
- package/lib/processors/bridge.d.ts +24 -0
- package/lib/processors/bridge.js +40 -0
- package/lib/processors/build.d.ts +19 -0
- package/lib/processors/build.js +35 -0
- package/lib/processors/ctf.d.ts +19 -0
- package/lib/processors/ctf.js +35 -0
- package/lib/processors/dr.d.ts +19 -0
- package/lib/processors/dr.js +35 -0
- package/lib/processors/drop.d.ts +17 -0
- package/lib/processors/drop.js +34 -0
- package/lib/processors/game.d.ts +1 -1
- package/lib/processors/game.js +2 -2
- package/lib/processors/grav.d.ts +17 -0
- package/lib/processors/grav.js +34 -0
- package/lib/processors/ground.d.ts +19 -0
- package/lib/processors/ground.js +35 -0
- package/lib/processors/helpers/processBuildRatings.d.ts +8 -0
- package/lib/processors/helpers/processBuildRatings.js +23 -0
- package/lib/processors/helpers/processGameAndXP.d.ts +6 -0
- package/lib/processors/helpers/processGameAndXP.js +10 -0
- package/lib/processors/helpers/processHiderKillsAndDeaths.d.ts +5 -0
- package/lib/processors/helpers/processHiderKillsAndDeaths.js +13 -0
- package/lib/processors/helpers/processKillsAndDeaths.d.ts +5 -0
- package/lib/processors/helpers/processKillsAndDeaths.js +13 -0
- package/lib/processors/helpers/processMurdersAndDeaths.d.ts +5 -0
- package/lib/processors/helpers/processMurdersAndDeaths.js +13 -0
- package/lib/processors/helpers/processPlayedAndVictories.d.ts +6 -0
- package/lib/processors/helpers/processPlayedAndVictories.js +12 -0
- package/lib/processors/hide.d.ts +19 -0
- package/lib/processors/hide.js +35 -0
- package/lib/processors/index.d.ts +12 -0
- package/lib/processors/index.js +73 -0
- package/lib/processors/murder.d.ts +19 -0
- package/lib/processors/murder.js +35 -0
- package/lib/processors/parkour.d.ts +5 -0
- package/lib/processors/parkour.js +99 -0
- package/lib/processors/party.d.ts +17 -0
- package/lib/processors/party.js +34 -0
- package/lib/processors/sg.d.ts +19 -0
- package/lib/processors/sg.js +35 -0
- package/lib/processors/sky.d.ts +19 -0
- package/lib/processors/sky.js +35 -0
- package/lib/processors/wars.d.ts +19 -0
- package/lib/processors/wars.js +35 -0
- package/lib/types/output.d.ts +62 -0
- package/lib/types/output.js +3 -0
- package/lib/types/types.d.ts +24 -0
- package/lib/types/types.js +2 -0
- package/package.json +2 -2
|
@@ -0,0 +1,88 @@
|
|
|
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 = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["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.default = fetchEndpoint;
|
|
40
|
+
var hive_bedrock_data_1 = require("hive-bedrock-data");
|
|
41
|
+
function fetchEndpoint(endpoint, init) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
43
|
+
var time_start, request, time_end, duration, response, err_1;
|
|
44
|
+
return __generator(this, function (_a) {
|
|
45
|
+
switch (_a.label) {
|
|
46
|
+
case 0:
|
|
47
|
+
_a.trys.push([0, 3, , 4]);
|
|
48
|
+
time_start = performance.now();
|
|
49
|
+
return [4 /*yield*/, fetch(hive_bedrock_data_1.API_BASE_ENDPOINT + endpoint, init)];
|
|
50
|
+
case 1:
|
|
51
|
+
request = _a.sent();
|
|
52
|
+
time_end = performance.now();
|
|
53
|
+
duration = Math.round(time_end - time_start);
|
|
54
|
+
if (!request.ok)
|
|
55
|
+
return [2 /*return*/, {
|
|
56
|
+
status: request.status,
|
|
57
|
+
data: null,
|
|
58
|
+
error: {
|
|
59
|
+
code: request.status,
|
|
60
|
+
message: request.statusText,
|
|
61
|
+
},
|
|
62
|
+
duration: duration,
|
|
63
|
+
}];
|
|
64
|
+
return [4 /*yield*/, request.json()];
|
|
65
|
+
case 2:
|
|
66
|
+
response = _a.sent();
|
|
67
|
+
return [2 /*return*/, {
|
|
68
|
+
status: request.status,
|
|
69
|
+
headers: request.headers,
|
|
70
|
+
data: response,
|
|
71
|
+
error: null,
|
|
72
|
+
duration: duration,
|
|
73
|
+
}];
|
|
74
|
+
case 3:
|
|
75
|
+
err_1 = _a.sent();
|
|
76
|
+
return [2 /*return*/, {
|
|
77
|
+
status: 500,
|
|
78
|
+
data: null,
|
|
79
|
+
error: {
|
|
80
|
+
code: 500,
|
|
81
|
+
message: "Failed to fetch endpoint data.",
|
|
82
|
+
},
|
|
83
|
+
}];
|
|
84
|
+
case 4: return [2 /*return*/];
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function toPoint(num: number, point: number): number;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = toPoint;
|
|
4
|
+
function toPoint(num, point) {
|
|
5
|
+
if (isNaN(num))
|
|
6
|
+
return 0;
|
|
7
|
+
if (num === Infinity)
|
|
8
|
+
return 0;
|
|
9
|
+
return Math.round(num * (10 ^ point)) / (10 ^ point);
|
|
10
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -48,8 +48,13 @@ export default class HiveAPI {
|
|
|
48
48
|
month?: number;
|
|
49
49
|
year?: number;
|
|
50
50
|
}): Promise<MethodResponse<ProcessedGame<Timeframe.Monthly, false>[G]>>;
|
|
51
|
+
getStatistics<G extends Game>(identifier: string, timeframe: Timeframe.Seasonal, options: {
|
|
52
|
+
game: G;
|
|
53
|
+
season: number;
|
|
54
|
+
}): Promise<MethodResponse<ProcessedMonthlyGamesResponse>>;
|
|
51
55
|
private _getStatisticsAllTime;
|
|
52
56
|
private _getStatisticsMonthly;
|
|
57
|
+
private _getStatisticsSeasonal;
|
|
53
58
|
getAvailableMonthlyLeaderboards<G extends Game>(game: G): Promise<MethodResponse<AvailableLeaderboardResponse>>;
|
|
54
59
|
/**
|
|
55
60
|
* `/game/season/player/{game}/{player}/{season}` Gets seasonal statistics for a player
|
|
@@ -71,8 +76,12 @@ export default class HiveAPI {
|
|
|
71
76
|
month?: number;
|
|
72
77
|
year?: number;
|
|
73
78
|
}): Promise<MethodResponse<ProcessedGame<Timeframe.Monthly, true>[G][] | null>>;
|
|
79
|
+
getLeaderboard<G extends Game>(timeframe: Timeframe.Seasonal, game: G, options: {
|
|
80
|
+
season: number;
|
|
81
|
+
}): Promise<MethodResponse<ProcessedGame<Timeframe.Seasonal, true>[G][] | null>>;
|
|
74
82
|
private _getLeaderboardAllTime;
|
|
75
83
|
private _getLeaderboardMonthly;
|
|
84
|
+
private _getLeaderboardSeasonal;
|
|
76
85
|
/**
|
|
77
86
|
* `/game/season/{game}/{season}` Gets seasonal statistics for a game
|
|
78
87
|
* @param game The game to get the statistics for
|
package/lib/index.js
CHANGED
|
@@ -170,6 +170,11 @@ var HiveAPI = /** @class */ (function () {
|
|
|
170
170
|
return [2 /*return*/, this._getStatisticsAllTime(identifier, options.game)];
|
|
171
171
|
return [2 /*return*/, this._getStatisticsAllTime(identifier)];
|
|
172
172
|
}
|
|
173
|
+
else if (timeframe === hive_bedrock_data_1.Timeframe.Seasonal) {
|
|
174
|
+
if (!(options === null || options === void 0 ? void 0 : options.game))
|
|
175
|
+
throw new Error("Game must be specified for seasonal statistics");
|
|
176
|
+
return [2 /*return*/, this._getStatisticsSeasonal(identifier, options === null || options === void 0 ? void 0 : options.game, (options === null || options === void 0 ? void 0 : options.season) || 1)];
|
|
177
|
+
}
|
|
173
178
|
if (options === null || options === void 0 ? void 0 : options.game)
|
|
174
179
|
return [2 /*return*/, this._getStatisticsMonthly(identifier, options.game, options.month, options.year)];
|
|
175
180
|
return [2 /*return*/, this._getStatisticsMonthly(identifier, undefined, options === null || options === void 0 ? void 0 : options.month, options === null || options === void 0 ? void 0 : options.year)];
|
|
@@ -235,6 +240,21 @@ var HiveAPI = /** @class */ (function () {
|
|
|
235
240
|
});
|
|
236
241
|
});
|
|
237
242
|
};
|
|
243
|
+
HiveAPI.prototype._getStatisticsSeasonal = function (identifier, game, season) {
|
|
244
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
245
|
+
var _a, response, error, meta;
|
|
246
|
+
return __generator(this, function (_b) {
|
|
247
|
+
switch (_b.label) {
|
|
248
|
+
case 0: return [4 /*yield*/, this._fetchAPI("/game/season/player/".concat(game, "/").concat(identifier, "/").concat(season !== null && season !== void 0 ? season : 1))];
|
|
249
|
+
case 1:
|
|
250
|
+
_a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
|
|
251
|
+
if (error)
|
|
252
|
+
return [2 /*return*/, { data: null, error: error, meta: meta }];
|
|
253
|
+
return [2 /*return*/, { data: (0, game_1.default)(game, hive_bedrock_data_1.Timeframe.Seasonal, false, response), error: null, meta: meta }];
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
};
|
|
238
258
|
HiveAPI.prototype.getAvailableMonthlyLeaderboards = function (game) {
|
|
239
259
|
return __awaiter(this, void 0, void 0, function () {
|
|
240
260
|
var _a, response, error, meta;
|
|
@@ -279,6 +299,8 @@ var HiveAPI = /** @class */ (function () {
|
|
|
279
299
|
return __generator(this, function (_a) {
|
|
280
300
|
if (timeframe === hive_bedrock_data_1.Timeframe.Monthly)
|
|
281
301
|
return [2 /*return*/, this._getLeaderboardMonthly(game, (options === null || options === void 0 ? void 0 : options.month) || new Date().getMonth() + 1, (options === null || options === void 0 ? void 0 : options.year) || new Date().getFullYear())];
|
|
302
|
+
if (timeframe === hive_bedrock_data_1.Timeframe.Seasonal)
|
|
303
|
+
return [2 /*return*/, this._getLeaderboardSeasonal(game, (options === null || options === void 0 ? void 0 : options.season) || 1)];
|
|
282
304
|
return [2 /*return*/, this._getLeaderboardAllTime(game)];
|
|
283
305
|
});
|
|
284
306
|
});
|
|
@@ -317,6 +339,24 @@ var HiveAPI = /** @class */ (function () {
|
|
|
317
339
|
});
|
|
318
340
|
});
|
|
319
341
|
};
|
|
342
|
+
// /game/season/{game}/season
|
|
343
|
+
HiveAPI.prototype._getLeaderboardSeasonal = function (game_2) {
|
|
344
|
+
return __awaiter(this, arguments, void 0, function (game, season) {
|
|
345
|
+
var _a, response, error, meta, data;
|
|
346
|
+
if (season === void 0) { season = 1; }
|
|
347
|
+
return __generator(this, function (_b) {
|
|
348
|
+
switch (_b.label) {
|
|
349
|
+
case 0: return [4 /*yield*/, this._fetchAPI("/game/season/".concat(game, "/").concat(season))];
|
|
350
|
+
case 1:
|
|
351
|
+
_a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
|
|
352
|
+
if (error)
|
|
353
|
+
return [2 /*return*/, { data: null, error: error, meta: meta }];
|
|
354
|
+
data = response.map(function (res) { return (0, game_1.default)(game, hive_bedrock_data_1.Timeframe.Seasonal, true, res); });
|
|
355
|
+
return [2 /*return*/, { data: data, error: null, meta: meta }];
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
});
|
|
359
|
+
};
|
|
320
360
|
/**
|
|
321
361
|
* `/game/season/{game}/{season}` Gets seasonal statistics for a game
|
|
322
362
|
* @param game The game to get the statistics for
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Game } from "hive-bedrock-data";
|
|
2
|
+
import { APIResponse, Options } from "../types/types";
|
|
3
|
+
import { AllTimeProcessedLeaderboard } from "../types/output";
|
|
4
|
+
export default function getAllTimeLeaderboard<G extends Game>(game_id: G, options?: Partial<Options>): Promise<APIResponse<AllTimeProcessedLeaderboard<G>>>;
|
|
@@ -0,0 +1,85 @@
|
|
|
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 = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
24
|
+
return g.next = verb(0), g["throw"] = verb(1), g["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
|
+
exports.default = getAllTimeLeaderboard;
|
|
54
|
+
var fetchEndpoint_1 = __importDefault(require("../helpers/fetchEndpoint"));
|
|
55
|
+
var isGame_1 = __importDefault(require("../helpers/isGame"));
|
|
56
|
+
var processors_1 = require("../processors");
|
|
57
|
+
function getAllTimeLeaderboard(game_id, options) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
59
|
+
var response, response_data, processed_data;
|
|
60
|
+
return __generator(this, function (_a) {
|
|
61
|
+
switch (_a.label) {
|
|
62
|
+
case 0:
|
|
63
|
+
if (!(0, isGame_1.default)(game_id))
|
|
64
|
+
return [2 /*return*/, {
|
|
65
|
+
status: 404,
|
|
66
|
+
error: {
|
|
67
|
+
code: 404,
|
|
68
|
+
message: "Game not found.",
|
|
69
|
+
},
|
|
70
|
+
data: null,
|
|
71
|
+
}];
|
|
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
|
+
processed_data = Array.from(response_data).map(function (statistics) {
|
|
79
|
+
return processors_1.LeaderboardProcessors[game_id](statistics);
|
|
80
|
+
});
|
|
81
|
+
return [2 /*return*/, __assign(__assign({}, response), { data: processed_data, error: null })];
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Game } from "hive-bedrock-data";
|
|
2
|
+
import { APIResponse, Options } from "../types/types";
|
|
3
|
+
import { AllTimeProcessedStatistics } from "../types/output";
|
|
4
|
+
import { Processed_Player_Statistics } from "../processors/player";
|
|
5
|
+
type AllGameStatisticsPlayer = AllTimeProcessedStatistics & {
|
|
6
|
+
player: Processed_Player_Statistics;
|
|
7
|
+
};
|
|
8
|
+
export default function getAllTimeStatistics(identifier: string, options?: Partial<Options>): Promise<APIResponse<AllGameStatisticsPlayer>>;
|
|
9
|
+
export default function getAllTimeStatistics<G extends Game>(identifier: string, game_id: G, options?: Partial<Options>): Promise<APIResponse<AllTimeProcessedStatistics[G]>>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,126 @@
|
|
|
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 = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
24
|
+
return g.next = verb(0), g["throw"] = verb(1), g["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 __read = (this && this.__read) || function (o, n) {
|
|
50
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
51
|
+
if (!m) return o;
|
|
52
|
+
var i = m.call(o), r, ar = [], e;
|
|
53
|
+
try {
|
|
54
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
55
|
+
}
|
|
56
|
+
catch (error) { e = { error: error }; }
|
|
57
|
+
finally {
|
|
58
|
+
try {
|
|
59
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
60
|
+
}
|
|
61
|
+
finally { if (e) throw e.error; }
|
|
62
|
+
}
|
|
63
|
+
return ar;
|
|
64
|
+
};
|
|
65
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
66
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
67
|
+
};
|
|
68
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
69
|
+
exports.default = getAllTimeStatistics;
|
|
70
|
+
var isGame_1 = __importDefault(require("../helpers/isGame"));
|
|
71
|
+
var fetchEndpoint_1 = __importDefault(require("../helpers/fetchEndpoint"));
|
|
72
|
+
var processors_1 = require("../processors");
|
|
73
|
+
function getAllTimeStatistics(identifier, game_or_options, options) {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
75
|
+
var game_id, method_options, response, response_data_1, processed_data_1, response_data, processed_data;
|
|
76
|
+
return __generator(this, function (_a) {
|
|
77
|
+
switch (_a.label) {
|
|
78
|
+
case 0:
|
|
79
|
+
game_id = "all";
|
|
80
|
+
method_options = game_or_options;
|
|
81
|
+
if (typeof game_or_options === "string") {
|
|
82
|
+
game_id = game_or_options;
|
|
83
|
+
method_options = options;
|
|
84
|
+
}
|
|
85
|
+
if (!(0, isGame_1.default)(game_id) && game_id !== "all")
|
|
86
|
+
return [2 /*return*/, {
|
|
87
|
+
status: 404,
|
|
88
|
+
error: {
|
|
89
|
+
code: 404,
|
|
90
|
+
message: "Game not found.",
|
|
91
|
+
},
|
|
92
|
+
data: null,
|
|
93
|
+
}];
|
|
94
|
+
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)];
|
|
95
|
+
case 1:
|
|
96
|
+
response = _a.sent();
|
|
97
|
+
if (response.error)
|
|
98
|
+
return [2 /*return*/, response];
|
|
99
|
+
if (game_id === "all") {
|
|
100
|
+
response_data_1 = Object.entries(response.data);
|
|
101
|
+
processed_data_1 = Object.fromEntries(response_data_1.map(function (_a) {
|
|
102
|
+
var _b = __read(_a, 2), id = _b[0], statistics = _b[1];
|
|
103
|
+
if (id === "main")
|
|
104
|
+
return ["player", (0, processors_1.PlayerProcessor)(statistics)];
|
|
105
|
+
if (!statistics ||
|
|
106
|
+
!(0, isGame_1.default)(id) ||
|
|
107
|
+
Array.isArray(statistics))
|
|
108
|
+
return [id, null];
|
|
109
|
+
return [
|
|
110
|
+
id,
|
|
111
|
+
typeof processors_1.AllTimeProcessors[id] === "function"
|
|
112
|
+
? processors_1.AllTimeProcessors[id](statistics)
|
|
113
|
+
: null,
|
|
114
|
+
];
|
|
115
|
+
}));
|
|
116
|
+
return [2 /*return*/, __assign(__assign({}, response), { data: processed_data_1 })];
|
|
117
|
+
}
|
|
118
|
+
response_data = response.data;
|
|
119
|
+
if (Array.isArray(response_data))
|
|
120
|
+
return [2 /*return*/, __assign(__assign({}, response), { status: 404, data: null, error: { code: 404, message: "Not Found" } })];
|
|
121
|
+
processed_data = processors_1.AllTimeProcessors[game_id](response_data);
|
|
122
|
+
return [2 /*return*/, __assign(__assign({}, response), { data: processed_data, error: null })];
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
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 = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.default = getGlobalStatistics;
|
|
43
|
+
var fetchEndpoint_1 = __importDefault(require("../helpers/fetchEndpoint"));
|
|
44
|
+
function getGlobalStatistics(options) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
46
|
+
var response;
|
|
47
|
+
return __generator(this, function (_a) {
|
|
48
|
+
switch (_a.label) {
|
|
49
|
+
case 0: return [4 /*yield*/, (0, fetchEndpoint_1.default)("/global/statistics", options === null || options === void 0 ? void 0 : options.init)];
|
|
50
|
+
case 1:
|
|
51
|
+
response = _a.sent();
|
|
52
|
+
return [2 /*return*/, response];
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
@@ -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 = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
24
|
+
return g.next = verb(0), g["throw"] = verb(1), g["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
|
+
exports.default = getMaps;
|
|
54
|
+
var fetchEndpoint_1 = __importDefault(require("../helpers/fetchEndpoint"));
|
|
55
|
+
var isGame_1 = __importDefault(require("../helpers/isGame"));
|
|
56
|
+
function getMaps(game_id, options) {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
58
|
+
var response, data;
|
|
59
|
+
return __generator(this, function (_a) {
|
|
60
|
+
switch (_a.label) {
|
|
61
|
+
case 0:
|
|
62
|
+
if (!(0, isGame_1.default)(game_id))
|
|
63
|
+
return [2 /*return*/, {
|
|
64
|
+
status: 404,
|
|
65
|
+
error: {
|
|
66
|
+
code: 404,
|
|
67
|
+
message: "Game not found.",
|
|
68
|
+
},
|
|
69
|
+
data: null,
|
|
70
|
+
}];
|
|
71
|
+
return [4 /*yield*/, (0, fetchEndpoint_1.default)("/game/map/".concat(game_id), options === null || options === void 0 ? void 0 : options.init)];
|
|
72
|
+
case 1:
|
|
73
|
+
response = _a.sent();
|
|
74
|
+
if (response.error)
|
|
75
|
+
return [2 /*return*/, response];
|
|
76
|
+
data = response.data;
|
|
77
|
+
return [2 /*return*/, __assign(__assign({}, response), { data: data })];
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
}
|