startgg-helper 2.2.1 → 2.3.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "startgg-helper",
3
- "version": "2.2.1",
3
+ "version": "2.3.1",
4
4
  "description": "A set of functions and classes useful to communicate with the start.gg API, using any client (YOU NEED TO PROVIDE A CLIENT YOURSELF, SEE README)",
5
5
  "main": "main.js",
6
6
  "module": "main.js",
package/src/query.js CHANGED
@@ -93,7 +93,7 @@ export class Query {
93
93
  * @param {{[varName: string]: value}} params
94
94
  * @param {string} connectionPathInQuery JSON path to the paginated collection that must aggregated in the query (JSON path : property names separated by dots)
95
95
  * @param {TimedQuerySemaphore} limiter
96
- * @param {{pageParamName?: string, perPageParamName?: string, perPage?: number, delay?: number, maxElements?: number, includeWholeQuery?: number}} config
96
+ * @param {{pageParamName?: string, perPageParamName?: string, perPage?: number, delay?: number, maxElements?: number, includeWholeQuery?: number, callback: (localResult: T[], page: number, totalPages: number) => T[]?}} config
97
97
  * @param {boolean} silentErrors
98
98
  * @param {number} maxTries
99
99
  * @returns
@@ -132,9 +132,15 @@ export class Query {
132
132
  if (!isConnection(connection)) throw "The given path does not point to a connection type";
133
133
 
134
134
  let localResult = connection.nodes;
135
+
135
136
  if (connection.pageInfo && connection.pageInfo.totalPages){
136
137
  let totalPages = connection.pageInfo.totalPages;
137
138
  if (!totalPages || currentPage >= totalPages) {
139
+ if (config.callback){
140
+ let cbRes = config.callback(localResult, currentPage);
141
+ if (cbRes) break;
142
+ localResult = cbRes;
143
+ }
138
144
  result = result.concat(localResult);
139
145
  break;
140
146
  }
@@ -142,6 +148,12 @@ export class Query {
142
148
  if (localResult.length < 1) break;
143
149
  }
144
150
 
151
+ if (config.callback){
152
+ let cbRes = config.callback(localResult, currentPage);
153
+ if (!cbRes) break;
154
+ localResult = cbRes;
155
+ }
156
+
145
157
  result = result.concat(localResult);
146
158
  currentPage++;
147
159
  params[pageParamName] = currentPage;
@@ -17,8 +17,9 @@ const placements = [
17
17
  */
18
18
  export function extractSlug(string){
19
19
  if (string.includes("start.gg/")){
20
- return string.split("start.gg/")[1];
21
- }
20
+ string = string.split("start.gg/")[1];
21
+ };
22
+ string = string.split("/").slice(0, 4).join("/");
22
23
  return string;
23
24
  }
24
25