hive-bedrock-api 3.0.0-alpha.30 → 3.0.0-alpha.32
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/index.d.ts +6 -1
- package/lib/index.js +31 -11
- package/lib/processors/game.d.ts +1 -27
- package/lib/processors/game.js +3 -11
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -12,6 +12,12 @@ interface Options {
|
|
|
12
12
|
apiBaseEndpoint?: string;
|
|
13
13
|
requestInit?: RequestInit;
|
|
14
14
|
}
|
|
15
|
+
export * from "./processors/game";
|
|
16
|
+
export * from "./processors/global_statistics";
|
|
17
|
+
export * from "./processors/map";
|
|
18
|
+
export * from "./processors/meta";
|
|
19
|
+
export * from "./processors/player";
|
|
20
|
+
export * from "./processors/player_search";
|
|
15
21
|
export default class HiveAPI {
|
|
16
22
|
options: Options;
|
|
17
23
|
constructor(options?: Options);
|
|
@@ -107,4 +113,3 @@ export default class HiveAPI {
|
|
|
107
113
|
*/
|
|
108
114
|
getGameMetadata(game: Game): Promise<MethodResponse<ProcessedGameMetadata>>;
|
|
109
115
|
}
|
|
110
|
-
export {};
|
package/lib/index.js
CHANGED
|
@@ -10,6 +10,20 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
};
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
25
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
26
|
+
};
|
|
13
27
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
28
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
29
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -69,7 +83,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
69
83
|
var hive_bedrock_data_1 = require("hive-bedrock-data");
|
|
70
84
|
var player_1 = __importDefault(require("./processors/player"));
|
|
71
85
|
var player_search_1 = __importDefault(require("./processors/player_search"));
|
|
72
|
-
var game_1 =
|
|
86
|
+
var game_1 = require("./processors/game");
|
|
87
|
+
__exportStar(require("./processors/game"), exports);
|
|
88
|
+
__exportStar(require("./processors/global_statistics"), exports);
|
|
89
|
+
__exportStar(require("./processors/map"), exports);
|
|
90
|
+
__exportStar(require("./processors/meta"), exports);
|
|
91
|
+
__exportStar(require("./processors/player"), exports);
|
|
92
|
+
__exportStar(require("./processors/player_search"), exports);
|
|
73
93
|
var HiveAPI = /** @class */ (function () {
|
|
74
94
|
function HiveAPI(options) {
|
|
75
95
|
if (options === void 0) { options = {}; }
|
|
@@ -192,11 +212,11 @@ var HiveAPI = /** @class */ (function () {
|
|
|
192
212
|
if (error)
|
|
193
213
|
return [2 /*return*/, { data: null, error: error, meta: meta }];
|
|
194
214
|
if (game)
|
|
195
|
-
return [2 /*return*/, { data: (0, game_1.
|
|
215
|
+
return [2 /*return*/, { data: (0, game_1.processGame)(game, hive_bedrock_data_1.Timeframe.AllTime, false, response), error: null, meta: meta }];
|
|
196
216
|
data = Object.fromEntries(Object.entries(response).map(function (_a) {
|
|
197
217
|
var _b;
|
|
198
218
|
var _c = __read(_a, 2), id = _c[0], res = _c[1];
|
|
199
|
-
return [id, id === "main" ? null : (_b = (0, game_1.
|
|
219
|
+
return [id, id === "main" ? null : (_b = (0, game_1.processGame)(id, hive_bedrock_data_1.Timeframe.AllTime, false, res)) !== null && _b !== void 0 ? _b : null];
|
|
200
220
|
}));
|
|
201
221
|
delete data.main;
|
|
202
222
|
return [2 /*return*/, {
|
|
@@ -222,11 +242,11 @@ var HiveAPI = /** @class */ (function () {
|
|
|
222
242
|
if (error)
|
|
223
243
|
return [2 /*return*/, { data: null, error: error, meta: meta }];
|
|
224
244
|
if (game)
|
|
225
|
-
return [2 /*return*/, { data: (0, game_1.
|
|
245
|
+
return [2 /*return*/, { data: (0, game_1.processGame)(game, hive_bedrock_data_1.Timeframe.Monthly, false, response), error: null, meta: meta }];
|
|
226
246
|
data = Object.fromEntries(Object.entries(response).map(function (_a) {
|
|
227
247
|
var _b;
|
|
228
248
|
var _c = __read(_a, 2), id = _c[0], res = _c[1];
|
|
229
|
-
return [id, id === "main" ? null : (_b = (0, game_1.
|
|
249
|
+
return [id, id === "main" ? null : (_b = (0, game_1.processGame)(id, hive_bedrock_data_1.Timeframe.Monthly, false, res)) !== null && _b !== void 0 ? _b : null];
|
|
230
250
|
}));
|
|
231
251
|
delete data.main;
|
|
232
252
|
return [2 /*return*/, {
|
|
@@ -250,7 +270,7 @@ var HiveAPI = /** @class */ (function () {
|
|
|
250
270
|
_a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
|
|
251
271
|
if (error)
|
|
252
272
|
return [2 /*return*/, { data: null, error: error, meta: meta }];
|
|
253
|
-
return [2 /*return*/, { data: (0, game_1.
|
|
273
|
+
return [2 /*return*/, { data: (0, game_1.processGame)(game, hive_bedrock_data_1.Timeframe.Seasonal, false, response), error: null, meta: meta }];
|
|
254
274
|
}
|
|
255
275
|
});
|
|
256
276
|
});
|
|
@@ -288,7 +308,7 @@ var HiveAPI = /** @class */ (function () {
|
|
|
288
308
|
_a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
|
|
289
309
|
if (error)
|
|
290
310
|
return [2 /*return*/, { data: null, error: error, meta: meta }];
|
|
291
|
-
data = (0, game_1.
|
|
311
|
+
data = (0, game_1.processGame)(game, hive_bedrock_data_1.Timeframe.Monthly, true, response);
|
|
292
312
|
return [2 /*return*/, { data: data, error: null, meta: meta }];
|
|
293
313
|
}
|
|
294
314
|
});
|
|
@@ -316,7 +336,7 @@ var HiveAPI = /** @class */ (function () {
|
|
|
316
336
|
_a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
|
|
317
337
|
if (error)
|
|
318
338
|
return [2 /*return*/, { data: null, error: error, meta: meta }];
|
|
319
|
-
data = response.map(function (res) { return (0, game_1.
|
|
339
|
+
data = response.map(function (res) { return (0, game_1.processGame)(game, hive_bedrock_data_1.Timeframe.AllTime, true, res); });
|
|
320
340
|
return [2 /*return*/, { data: data, error: null, meta: meta }];
|
|
321
341
|
}
|
|
322
342
|
});
|
|
@@ -333,7 +353,7 @@ var HiveAPI = /** @class */ (function () {
|
|
|
333
353
|
_a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
|
|
334
354
|
if (error)
|
|
335
355
|
return [2 /*return*/, { data: null, error: error, meta: meta }];
|
|
336
|
-
data = response.map(function (res) { return (0, game_1.
|
|
356
|
+
data = response.map(function (res) { return (0, game_1.processGame)(game, hive_bedrock_data_1.Timeframe.Monthly, true, res); });
|
|
337
357
|
return [2 /*return*/, { data: data, error: null, meta: meta }];
|
|
338
358
|
}
|
|
339
359
|
});
|
|
@@ -351,7 +371,7 @@ var HiveAPI = /** @class */ (function () {
|
|
|
351
371
|
_a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
|
|
352
372
|
if (error)
|
|
353
373
|
return [2 /*return*/, { data: null, error: error, meta: meta }];
|
|
354
|
-
data = response.map(function (res) { return (0, game_1.
|
|
374
|
+
data = response.map(function (res) { return (0, game_1.processGame)(game, hive_bedrock_data_1.Timeframe.Seasonal, true, res); });
|
|
355
375
|
return [2 /*return*/, { data: data, error: null, meta: meta }];
|
|
356
376
|
}
|
|
357
377
|
});
|
|
@@ -374,7 +394,7 @@ var HiveAPI = /** @class */ (function () {
|
|
|
374
394
|
_a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
|
|
375
395
|
if (error)
|
|
376
396
|
return [2 /*return*/, { data: null, error: error, meta: meta }];
|
|
377
|
-
data = response.map(function (res) { return (0, game_1.
|
|
397
|
+
data = response.map(function (res) { return (0, game_1.processGame)(game, hive_bedrock_data_1.Timeframe.Monthly, true, res); });
|
|
378
398
|
return [2 /*return*/, { data: data, error: null, meta: meta }];
|
|
379
399
|
}
|
|
380
400
|
});
|
package/lib/processors/game.d.ts
CHANGED
|
@@ -269,33 +269,7 @@ export interface ProcessedGame<T extends Timeframe, L extends boolean> {
|
|
|
269
269
|
[Game.TreasureWars]: ProcessedGameWARS & AdditionalStatistics<T, L>;
|
|
270
270
|
[Game.ParkourWorlds]: L extends true ? never : T extends Timeframe.AllTime ? ProcessedGamePARKOUR : never;
|
|
271
271
|
}
|
|
272
|
-
export
|
|
273
|
-
export declare const processors: {
|
|
274
|
-
bed: (response: any) => ProcessedGameBED;
|
|
275
|
-
drop: (response: any) => ProcessedGameDROP;
|
|
276
|
-
party: (response: any) => ProcessedGamePARTY;
|
|
277
|
-
ctf: (response: any) => ProcessedGameCTF;
|
|
278
|
-
dr: (response: any) => ProcessedGameDR;
|
|
279
|
-
grav: (response: any) => ProcessedGameGRAV;
|
|
280
|
-
ground: (response: any) => ProcessedGameGROUND;
|
|
281
|
-
build: (response: any) => ProcessedGameBUILD;
|
|
282
|
-
hide: (response: any) => ProcessedGameHIDE;
|
|
283
|
-
murder: (response: any) => ProcessedGameMURDER;
|
|
284
|
-
sky: (response: any) => ProcessedGameSKY;
|
|
285
|
-
"sky-kits": (response: any) => ProcessedGameSKYKITS;
|
|
286
|
-
"sky-classic": (response: any) => ProcessedGameSKYCLASSIC;
|
|
287
|
-
sg: (response: any) => ProcessedGameSG;
|
|
288
|
-
bridge: (response: any) => ProcessedGameBRIDGE;
|
|
289
|
-
wars: (response: any) => ProcessedGameWARS;
|
|
290
|
-
parkour: (response: any) => ProcessedGamePARKOUR | null;
|
|
291
|
-
};
|
|
292
|
-
export declare function validateNumber(value: number, def?: number): number;
|
|
293
|
-
export declare function calculateKDR(kills: number, deaths: number): number;
|
|
294
|
-
export declare function calculateWinPercentage(victories: number, played: number): number;
|
|
295
|
-
export declare function calculateLosses(played: number, victories: number): number;
|
|
296
|
-
export declare function calculateTotal(values: number[]): number;
|
|
297
|
-
export declare function calculateKPG(kills: number, games: number): number;
|
|
298
|
-
export declare function roundTo(value: number, places?: number): number;
|
|
272
|
+
export declare function processGame<G extends Game, T extends Timeframe, L extends boolean>(game: G, timeframe: T, isLeaderboard: L, response: any): ProcessedGame<T, L>[G] | null;
|
|
299
273
|
export interface ProcessedAllGamesResponse {
|
|
300
274
|
player: ProcessedPlayerResponse;
|
|
301
275
|
statistics: {
|
package/lib/processors/game.js
CHANGED
|
@@ -17,15 +17,7 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
17
17
|
};
|
|
18
18
|
var _a;
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.
|
|
21
|
-
exports.default = processGame;
|
|
22
|
-
exports.validateNumber = validateNumber;
|
|
23
|
-
exports.calculateKDR = calculateKDR;
|
|
24
|
-
exports.calculateWinPercentage = calculateWinPercentage;
|
|
25
|
-
exports.calculateLosses = calculateLosses;
|
|
26
|
-
exports.calculateTotal = calculateTotal;
|
|
27
|
-
exports.calculateKPG = calculateKPG;
|
|
28
|
-
exports.roundTo = roundTo;
|
|
20
|
+
exports.processGame = processGame;
|
|
29
21
|
var hive_bedrock_data_1 = require("hive-bedrock-data");
|
|
30
22
|
function processGame(game, timeframe, isLeaderboard, response) {
|
|
31
23
|
var _a;
|
|
@@ -35,7 +27,7 @@ function processGame(game, timeframe, isLeaderboard, response) {
|
|
|
35
27
|
return null;
|
|
36
28
|
if (Array.isArray(response))
|
|
37
29
|
return null;
|
|
38
|
-
var data =
|
|
30
|
+
var data = processors[game](response);
|
|
39
31
|
if (!data)
|
|
40
32
|
return null;
|
|
41
33
|
if ("played" in data && data.played === 0 && "xp" in data && data.xp === 0)
|
|
@@ -52,7 +44,7 @@ function processGame(game, timeframe, isLeaderboard, response) {
|
|
|
52
44
|
data.UUID = response.UUID;
|
|
53
45
|
return data;
|
|
54
46
|
}
|
|
55
|
-
|
|
47
|
+
var processors = (_a = {},
|
|
56
48
|
_a[hive_bedrock_data_1.Game.BedWars] = function (response) {
|
|
57
49
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
58
50
|
return ({
|