startgg-helper 2.4.0 → 2.4.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 +1 -1
- package/src/query.js +8 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "startgg-helper",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.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
|
@@ -87,7 +87,7 @@ export class Query {
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
/**
|
|
90
|
-
* @param {GraphQLClient} client A client object ; not provided by this package, either use startgg-helper-node (or-browser) or refer to README.md
|
|
90
|
+
* @param {GraphQLClient} client A client object ; not provided by this package, either use startgg-helper-node (or -browser) or refer to README.md
|
|
91
91
|
* @param {{[varName: string]: value}} params GraphQL variables
|
|
92
92
|
* @param {TimedQuerySemaphore} limiter A request limiter object; see TimedQuerySemaphore
|
|
93
93
|
* @param {boolean} silentErrors No effect, exists only for legacy purposes
|
|
@@ -116,7 +116,7 @@ export class Query {
|
|
|
116
116
|
* @param {{[varName: string]: value}} params GraphQL variables ; does not include the page index variable.
|
|
117
117
|
* @param {string} connectionPathInQuery JSON path to the paginated collection that must be aggregated in the query (JSON path : property names separated by dots, see deep_get())
|
|
118
118
|
* @param {TimedQuerySemaphore} limiter A request limiter object; see TimedQuerySemaphore
|
|
119
|
-
* @param {{pageParamName?: string, perPageParamName?: string, perPage?: number, delay?: number, maxElements?: number, includeWholeQuery?: number, callback: PageCallback?}} config
|
|
119
|
+
* @param {{pageParamName?: string, perPageParamName?: string, perPage?: number, startingPage: number, initialData: any, delay?: number, maxElements?: number, includeWholeQuery?: number, callback: PageCallback?}} config
|
|
120
120
|
* @param config.pageParamName name of the variable representing the page index. This variable must exist in your query, and be used as an argument in a paginated collection field
|
|
121
121
|
* @param config.delay number of miliseconds to wait for between each query. No delay if absent.
|
|
122
122
|
* @param config.maxElements if present, queries will stop once this many elements have been fetched
|
|
@@ -127,15 +127,14 @@ export class Query {
|
|
|
127
127
|
* @returns See config.includeWholeQuery
|
|
128
128
|
*/
|
|
129
129
|
async executePaginated(client, params, connectionPathInQuery, limiter = null, config = {}, silentErrors = false, maxTries = null){
|
|
130
|
-
let result = [];
|
|
131
|
-
//delay = null, perPage = undefined, pageParamName = "page", perPageParamName = "perPage", silentErrors = false, maxTries = null
|
|
130
|
+
let result = config.initialData ?? [];
|
|
132
131
|
const pageParamName = config.pageParamName ?? "page";
|
|
133
132
|
const perPageParamName = config.perPageParamName ?? "perPage";
|
|
134
133
|
const perPage = config.perPage ?? params[perPageParamName];
|
|
135
134
|
const delay = config.delay;
|
|
136
135
|
const maxElements = config.maxElements ?? undefined; //eliminating null
|
|
137
136
|
|
|
138
|
-
let currentPage = 1;
|
|
137
|
+
let currentPage = config.startingPage ?? 1;
|
|
139
138
|
|
|
140
139
|
params = Object.assign({}, params);
|
|
141
140
|
params[pageParamName] = currentPage;
|
|
@@ -167,7 +166,7 @@ export class Query {
|
|
|
167
166
|
let totalPages = connection.pageInfo.totalPages;
|
|
168
167
|
if (currentPage >= totalPages) {
|
|
169
168
|
if (config.callback){
|
|
170
|
-
let cbRes = config.callback(localResult,
|
|
169
|
+
let cbRes = config.callback(localResult, result, currentPage)
|
|
171
170
|
|
|
172
171
|
if (cbRes instanceof PageResult){
|
|
173
172
|
if (cbRes.result){ //If the user gives us a result we take it ofc
|
|
@@ -188,7 +187,7 @@ export class Query {
|
|
|
188
187
|
}
|
|
189
188
|
|
|
190
189
|
if (config.callback){
|
|
191
|
-
let cbRes = config.callback(localResult, currentPage);
|
|
190
|
+
let cbRes = config.callback(localResult, result, currentPage);
|
|
192
191
|
|
|
193
192
|
if (cbRes instanceof PageResult){
|
|
194
193
|
if (cbRes.result){ //If the user gives us a result we take it ofc
|
|
@@ -199,21 +198,19 @@ export class Query {
|
|
|
199
198
|
if (cbRes.stop){
|
|
200
199
|
break;
|
|
201
200
|
}
|
|
202
|
-
currentPage++;
|
|
203
201
|
} else if (!cbRes) { //"normal case" : basic callback that doesn't touch the flow of the pexecution, we concat and increment normally
|
|
204
202
|
result = result.concat(localResult)
|
|
205
|
-
currentPage++;
|
|
206
203
|
} else if (cbRes === true){ //callback is asking us to stop by returning true
|
|
207
204
|
break;
|
|
208
205
|
} else { //callback returns a non-boolean value : it's the local result (and we increment normally)
|
|
209
206
|
result = result.concat(cbRes);
|
|
210
|
-
currentPage++;
|
|
211
207
|
}
|
|
212
208
|
|
|
213
209
|
} else {
|
|
214
210
|
result = result.concat(localResult);
|
|
215
|
-
currentPage++;
|
|
216
211
|
}
|
|
212
|
+
|
|
213
|
+
currentPage++;
|
|
217
214
|
|
|
218
215
|
params[pageParamName] = currentPage;
|
|
219
216
|
|