hive-bedrock-api 2.0.3 → 2.0.5
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/methods/getAllTimeLeaderboard.js +1 -3
- package/lib/methods/getAllTimeStatistics.js +11 -2
- package/lib/methods/getMonthlyLeaderboard.js +1 -3
- package/lib/methods/getMonthlyStatistics.js +3 -4
- package/lib/processors/index.js +33 -10
- package/lib/types/output.d.ts +4 -0
- package/package.json +2 -4
|
@@ -76,9 +76,7 @@ function getAllTimeLeaderboard(game_id, options) {
|
|
|
76
76
|
return [2 /*return*/, response];
|
|
77
77
|
response_data = response.data;
|
|
78
78
|
processors = (0, processors_1.default)(game_id, hive_bedrock_data_1.Timeframe.AllTime);
|
|
79
|
-
response_data.forEach(function (statistics) {
|
|
80
|
-
return processors.forEach(function (processor) { return processor(statistics); });
|
|
81
|
-
});
|
|
79
|
+
response_data.forEach(function (statistics) { return processors.forEach(function (processor) { return processor(statistics); }); });
|
|
82
80
|
return [2 /*return*/, __assign(__assign({}, response), { data: response_data, error: null })];
|
|
83
81
|
}
|
|
84
82
|
});
|
|
@@ -143,7 +143,7 @@ function getAllTimeStatistics(identifier, game_or_options, options) {
|
|
|
143
143
|
}
|
|
144
144
|
var processors_3 = (0, processors_1.default)(g, hive_bedrock_data_1.Timeframe.AllTime);
|
|
145
145
|
processors_3.forEach(function (processor) { return processor(stats); });
|
|
146
|
-
output[g] = stats;
|
|
146
|
+
output[g] = Object.keys(stats).length > 0 ? stats : null;
|
|
147
147
|
}
|
|
148
148
|
};
|
|
149
149
|
try {
|
|
@@ -163,6 +163,15 @@ function getAllTimeStatistics(identifier, game_or_options, options) {
|
|
|
163
163
|
var _b = __read(_a, 1), g = _b[0];
|
|
164
164
|
return g === "main";
|
|
165
165
|
})) === null || _c === void 0 ? void 0 : _c[1];
|
|
166
|
+
if (!player_1)
|
|
167
|
+
return [2 /*return*/, {
|
|
168
|
+
status: 500,
|
|
169
|
+
error: {
|
|
170
|
+
code: 500,
|
|
171
|
+
message: "Player statistics not returned",
|
|
172
|
+
},
|
|
173
|
+
data: null,
|
|
174
|
+
}];
|
|
166
175
|
processors_2 = (0, processors_1.getPlayerProcessors)();
|
|
167
176
|
processors_2.forEach(function (processor) { return processor(player_1); });
|
|
168
177
|
return [2 /*return*/, __assign(__assign({}, response), { data: __assign(__assign({}, output), { player: player_1 }) })];
|
|
@@ -172,7 +181,7 @@ function getAllTimeStatistics(identifier, game_or_options, options) {
|
|
|
172
181
|
return [2 /*return*/, __assign(__assign({}, response), { status: 404, data: null, error: { code: 404, message: "Not Found" } })];
|
|
173
182
|
processors = (0, processors_1.default)(game_id, hive_bedrock_data_1.Timeframe.AllTime);
|
|
174
183
|
processors.forEach(function (processor) { return processor(response_data); });
|
|
175
|
-
return [2 /*return*/, __assign(__assign({}, response), { data: response_data, error: null })];
|
|
184
|
+
return [2 /*return*/, __assign(__assign({}, response), { data: Object.keys(response_data).length > 0 ? response_data : null, error: null })];
|
|
176
185
|
}
|
|
177
186
|
});
|
|
178
187
|
});
|
|
@@ -79,9 +79,7 @@ function getMonthlyLeaderboard(game_id, options) {
|
|
|
79
79
|
return [2 /*return*/, response];
|
|
80
80
|
response_data = Object.values(response.data);
|
|
81
81
|
processors = (0, processors_1.default)(game_id, hive_bedrock_data_1.Timeframe.Monthly);
|
|
82
|
-
response_data.forEach(function (statistics) {
|
|
83
|
-
return processors.forEach(function (processor) { return processor(statistics); });
|
|
84
|
-
});
|
|
82
|
+
response_data.forEach(function (statistics) { return processors.forEach(function (processor) { return processor(statistics); }); });
|
|
85
83
|
return [2 /*return*/, __assign(__assign({}, response), { data: response_data, error: null })];
|
|
86
84
|
}
|
|
87
85
|
});
|
|
@@ -116,14 +116,13 @@ function getMonthlyStatistics(identifier, game_or_options, options) {
|
|
|
116
116
|
output = {};
|
|
117
117
|
_loop_1 = function (g, stats) {
|
|
118
118
|
if ((0, isGame_1.default)(g)) {
|
|
119
|
-
if (Array.isArray(stats) ||
|
|
120
|
-
typeof stats.played === "undefined") {
|
|
119
|
+
if (Array.isArray(stats) || typeof stats["played"] === "undefined") {
|
|
121
120
|
output[g] = null;
|
|
122
121
|
return "continue";
|
|
123
122
|
}
|
|
124
123
|
var processors_2 = (0, processors_1.default)(g, hive_bedrock_data_1.Timeframe.Monthly);
|
|
125
124
|
processors_2.forEach(function (processor) { return processor(stats); });
|
|
126
|
-
output[g] = stats;
|
|
125
|
+
output[g] = Object.keys(stats).length > 0 ? stats : null;
|
|
127
126
|
}
|
|
128
127
|
};
|
|
129
128
|
try {
|
|
@@ -146,7 +145,7 @@ function getMonthlyStatistics(identifier, game_or_options, options) {
|
|
|
146
145
|
return [2 /*return*/, __assign(__assign({}, response), { status: 404, data: null, error: { code: 404, message: "Not Found" } })];
|
|
147
146
|
processors = (0, processors_1.default)(game_id, hive_bedrock_data_1.Timeframe.Monthly);
|
|
148
147
|
processors.forEach(function (processor) { return processor(response_data); });
|
|
149
|
-
return [2 /*return*/, __assign(__assign({}, response), { data: response_data, error: null })];
|
|
148
|
+
return [2 /*return*/, __assign(__assign({}, response), { data: Object.keys(response_data).length > 0 ? response_data : null, error: null })];
|
|
150
149
|
}
|
|
151
150
|
});
|
|
152
151
|
});
|
package/lib/processors/index.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __values = (this && this.__values) || function(o) {
|
|
3
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
4
|
+
if (m) return m.call(o);
|
|
5
|
+
if (o && typeof o.length === "number") return {
|
|
6
|
+
next: function () {
|
|
7
|
+
if (o && i >= o.length) o = void 0;
|
|
8
|
+
return { value: o && o[i++], done: !o };
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
12
|
+
};
|
|
2
13
|
var __read = (this && this.__read) || function (o, n) {
|
|
3
14
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
15
|
if (!m) return o;
|
|
@@ -70,25 +81,37 @@ function getProcessors(game, timeframe) {
|
|
|
70
81
|
return game === hive_bedrock_data_1.Game.JustBuild
|
|
71
82
|
? Object.keys(s)
|
|
72
83
|
.filter(function (key) { return key.startsWith("rating_"); })
|
|
73
|
-
.forEach(function (key) {
|
|
74
|
-
var _a;
|
|
75
|
-
return (s.total_ratings =
|
|
76
|
-
((_a = s.total_ratings) !== null && _a !== void 0 ? _a : 0) + s[key]);
|
|
77
|
-
})
|
|
84
|
+
.forEach(function (key) { var _a; return (s.total_ratings = ((_a = s.total_ratings) !== null && _a !== void 0 ? _a : 0) + s[key]); })
|
|
78
85
|
: null;
|
|
79
86
|
},
|
|
80
87
|
// Append losses
|
|
81
|
-
function (s) {
|
|
82
|
-
return "played" in s && "victories" in s
|
|
83
|
-
? (s.losses = s.played - s.victories)
|
|
84
|
-
: null;
|
|
85
|
-
},
|
|
88
|
+
function (s) { return ("played" in s && "victories" in s ? (s.losses = s.played - s.victories) : null); },
|
|
86
89
|
// Calculate win percentage
|
|
87
90
|
function (s) {
|
|
88
91
|
return "played" in s && "victories" in s
|
|
89
92
|
? (s.win_percentage = s.played > 0 ? s.victories / s.played : 0)
|
|
90
93
|
: null;
|
|
91
94
|
},
|
|
95
|
+
// remove empty parkour world stats
|
|
96
|
+
function (s) {
|
|
97
|
+
var e_1, _a;
|
|
98
|
+
if (game === hive_bedrock_data_1.Game.ParkourWorlds && typeof s.parkours !== "object") {
|
|
99
|
+
try {
|
|
100
|
+
for (var _b = __values(Object.keys(s)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
101
|
+
var key = _c.value;
|
|
102
|
+
delete s[key];
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
106
|
+
finally {
|
|
107
|
+
try {
|
|
108
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
109
|
+
}
|
|
110
|
+
finally { if (e_1) throw e_1.error; }
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return null;
|
|
114
|
+
},
|
|
92
115
|
// Remove NaN
|
|
93
116
|
function (s) {
|
|
94
117
|
return Object.entries(s).forEach(function (_a) {
|
package/lib/types/output.d.ts
CHANGED
|
@@ -35,6 +35,9 @@ export interface AllStatistics<T extends Timeframe> {
|
|
|
35
35
|
[Game.TheBridge]: BaseStatistics<Game.TheBridge, T> & PvPAdditions;
|
|
36
36
|
[Game.TreasureWars]: BaseStatistics<Game.TreasureWars, T> & PvPAdditions;
|
|
37
37
|
[Game.BedWars]: BaseStatistics<Game.BedWars, T> & PvPAdditions;
|
|
38
|
+
[Game.ParkourWorlds]: Statistics<Game.ParkourWorlds, T> & {
|
|
39
|
+
id: Game;
|
|
40
|
+
};
|
|
38
41
|
}
|
|
39
42
|
interface CommonLeaderboard {
|
|
40
43
|
id: Game;
|
|
@@ -62,6 +65,7 @@ export interface AllLeaderboards<T extends Timeframe> {
|
|
|
62
65
|
[Game.TheBridge]: BaseLeaderboard<Game.TheBridge, T>[];
|
|
63
66
|
[Game.TreasureWars]: BaseLeaderboard<Game.TreasureWars, T>[];
|
|
64
67
|
[Game.BedWars]: BaseLeaderboard<Game.BedWars, T>[];
|
|
68
|
+
[Game.ParkourWorlds]: never;
|
|
65
69
|
}
|
|
66
70
|
export type AllGameStatistics<T extends Timeframe> = {
|
|
67
71
|
[key in Game]: BaseStatistics<key, T> | null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hive-bedrock-api",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
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",
|
|
@@ -11,11 +11,9 @@
|
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"author": "Cubeedge Studios",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"hive-bedrock-data": "^1.1.
|
|
14
|
+
"hive-bedrock-data": "^1.1.17"
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|
|
17
|
-
"prepack": "yarn build",
|
|
18
|
-
"prepare": "npm run build",
|
|
19
17
|
"build": "tsc"
|
|
20
18
|
},
|
|
21
19
|
"files": [
|