gd-sprest 9.7.6 → 9.7.8
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/@types/utils/base.d.ts +0 -3
- package/build/rest.js +1 -1
- package/build/utils/helper.js +0 -1
- package/build/utils/methodInfo.js +0 -3
- package/build/utils/oData.js +0 -4
- package/build/utils/request.js +11 -1
- package/build/utils/xhrRequest.js +15 -0
- package/dist/gd-sprest.d.ts +0 -3
- package/dist/gd-sprest.js +1 -1
- package/dist/gd-sprest.min.js +1 -1
- package/package.json +2 -2
package/@types/utils/base.d.ts
CHANGED
|
@@ -58,9 +58,6 @@ export interface IBase<Type = any, Result = Type, QueryResult = Result> extends
|
|
|
58
58
|
/** Flag to get all items. */
|
|
59
59
|
getAllItemsFl: boolean;
|
|
60
60
|
|
|
61
|
-
/** Time in ms to wait inbetween requests when getting all items. */
|
|
62
|
-
getAllItemsWaitTime: number;
|
|
63
|
-
|
|
64
61
|
/** Flag determining if more items exist. */
|
|
65
62
|
nextFl: boolean;
|
|
66
63
|
|
package/build/rest.js
CHANGED
package/build/utils/helper.js
CHANGED
|
@@ -124,7 +124,6 @@ export const Helper = {
|
|
|
124
124
|
// Set the properties
|
|
125
125
|
obj.base = base.base ? base.base : base;
|
|
126
126
|
obj.getAllItemsFl = methodInfo.getAllItemsFl;
|
|
127
|
-
obj.getAllItemsWaitTime = methodInfo.getAllItemsWaitTime;
|
|
128
127
|
obj.parent = base;
|
|
129
128
|
obj.requestType = methodConfig.requestType;
|
|
130
129
|
// Ensure the return type exists
|
|
@@ -28,8 +28,6 @@ export class MethodInfo {
|
|
|
28
28
|
get body() { return this.methodData; }
|
|
29
29
|
// Flag to determine if we are getting all items
|
|
30
30
|
get getAllItemsFl() { return this.methodInfo.getAllItemsFl; }
|
|
31
|
-
// Time in ms to wait inbetween requests for getting all items
|
|
32
|
-
get getAllItemsWaitTime() { return this.methodInfo.getAllItemsWaitTime; }
|
|
33
31
|
// Flag to determine if this method replaces the endpoint
|
|
34
32
|
get replaceEndpointFl() { return this.methodInfo.replaceEndpointFl ? true : false; }
|
|
35
33
|
// The request method
|
|
@@ -198,7 +196,6 @@ export class MethodInfo {
|
|
|
198
196
|
url = "?" + oData.QueryString;
|
|
199
197
|
// Set the get all items Flag
|
|
200
198
|
this.methodInfo.getAllItemsFl = oData.GetAllItems;
|
|
201
|
-
this.methodInfo.getAllItemsWaitTime = oData.GetAllItemsWaitTime;
|
|
202
199
|
}
|
|
203
200
|
// Else, see if we are not passing the data in the body or query string as a variable
|
|
204
201
|
else if (!this.passDataInBody && !this.passDataInQSAsVar) {
|
package/build/utils/oData.js
CHANGED
|
@@ -12,7 +12,6 @@ export class OData {
|
|
|
12
12
|
this._expand = oData && oData.Expand ? oData.Expand : [];
|
|
13
13
|
this._filter = oData && oData.Filter ? oData.Filter : null;
|
|
14
14
|
this._getAllItems = oData && oData.GetAllItems ? oData.GetAllItems : false;
|
|
15
|
-
this._getAllItemsWaitTime = oData && oData.GetAllItemsWaitTime ? oData.GetAllItemsWaitTime : 0;
|
|
16
15
|
this._orderBy = oData && oData.OrderBy ? oData.OrderBy : [];
|
|
17
16
|
this._search = oData && oData.Search ? oData.Search : null;
|
|
18
17
|
this._select = oData && oData.Select ? oData.Select : [];
|
|
@@ -35,9 +34,6 @@ export class OData {
|
|
|
35
34
|
// Flag to get all items
|
|
36
35
|
get GetAllItems() { return this._getAllItems; }
|
|
37
36
|
set GetAllItems(value) { this._getAllItems = value; }
|
|
38
|
-
// Time in ms to wait between calls to avoid throttling
|
|
39
|
-
get GetAllItemsWaitTime() { return this._getAllItemsWaitTime; }
|
|
40
|
-
set GetAllItemsWaitTime(value) { this._getAllItemsWaitTime = value; }
|
|
41
37
|
// Order By
|
|
42
38
|
get OrderBy() { return this._orderBy; }
|
|
43
39
|
set OrderBy(value) { this._orderBy = value; }
|
package/build/utils/request.js
CHANGED
|
@@ -698,6 +698,14 @@ export const Request = {
|
|
|
698
698
|
targetInfo.accessToken = base.targetInfo.accessToken || (base.xhr.isGraph ? Graph.Token : null);
|
|
699
699
|
targetInfo.endpoint = "";
|
|
700
700
|
targetInfo.url = data["@odata.nextLink"] || data.d.__next;
|
|
701
|
+
// Set the sleep value to prevent throttling
|
|
702
|
+
let sleepInMS = 0;
|
|
703
|
+
if (xhr.rateLimit && xhr.rateLimit.remaining < 50) {
|
|
704
|
+
// Set the rate
|
|
705
|
+
sleepInMS = xhr.rateLimit.reset * 1000;
|
|
706
|
+
// Log
|
|
707
|
+
console.info("[gd-sprest] Throttle approaching... Waiting " + sleepInMS + "ms before sending the next request.", xhr.rateLimit);
|
|
708
|
+
}
|
|
701
709
|
// Wait before we execute the call
|
|
702
710
|
setTimeout(() => {
|
|
703
711
|
// Create a new object
|
|
@@ -713,6 +721,8 @@ export const Request = {
|
|
|
713
721
|
// Update the expanded properties
|
|
714
722
|
Helper.updateExpandedProperties(base);
|
|
715
723
|
}
|
|
724
|
+
// Set the rate limit information
|
|
725
|
+
base.rateLimit = xhr.rateLimit;
|
|
716
726
|
// Append the raw data results
|
|
717
727
|
if ((_b = base["d"]) === null || _b === void 0 ? void 0 : _b.results) {
|
|
718
728
|
base["d"].results = base["d"].results.concat(data.d.results);
|
|
@@ -728,7 +738,7 @@ export const Request = {
|
|
|
728
738
|
resolve();
|
|
729
739
|
}
|
|
730
740
|
});
|
|
731
|
-
},
|
|
741
|
+
}, sleepInMS);
|
|
732
742
|
}
|
|
733
743
|
else {
|
|
734
744
|
// Add a method to get the next set of results
|
|
@@ -33,12 +33,27 @@ export class XHRRequest {
|
|
|
33
33
|
get isGraph() { return this.targetInfo.isGraph; }
|
|
34
34
|
// Flag indicating the request has completed
|
|
35
35
|
get completedFl() { return this.xhr ? this.xhr.readyState == 4 : false; }
|
|
36
|
+
// Gets a response header
|
|
37
|
+
getResponseHeader(key) { return this.xhr ? this.xhr.getResponseHeader(key) : ""; }
|
|
36
38
|
// The response
|
|
37
39
|
get response() { return this.xhr ? this.xhr.response : null; }
|
|
38
40
|
// The xml http request
|
|
39
41
|
get request() { return this.xhr ? this.xhr : null; }
|
|
40
42
|
// The data send in the body of the request
|
|
41
43
|
get requestData() { return this.targetInfo.requestData; }
|
|
44
|
+
// Return the rate limit information
|
|
45
|
+
get rateLimit() {
|
|
46
|
+
// Ensure the rate limit information exists
|
|
47
|
+
if (this.xhr == null || this.getResponseHeader("RateLimit-Limit") == null) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
// Return the rate limit information
|
|
51
|
+
return {
|
|
52
|
+
limit: this.getResponseHeader("RateLimit-Limit"),
|
|
53
|
+
remaining: parseInt(this.getResponseHeader("RateLimit-Remaining")),
|
|
54
|
+
reset: parseInt(this.getResponseHeader("RateLimit-Reset"))
|
|
55
|
+
};
|
|
56
|
+
}
|
|
42
57
|
// The request headers
|
|
43
58
|
get requestHeaders() { return this.headers; }
|
|
44
59
|
// The request information
|
package/dist/gd-sprest.d.ts
CHANGED
|
@@ -7439,9 +7439,6 @@ declare module 'gd-sprest/utils/base' {
|
|
|
7439
7439
|
/** Flag to get all items. */
|
|
7440
7440
|
getAllItemsFl: boolean;
|
|
7441
7441
|
|
|
7442
|
-
/** Time in ms to wait inbetween requests when getting all items. */
|
|
7443
|
-
getAllItemsWaitTime: number;
|
|
7444
|
-
|
|
7445
7442
|
/** Flag determining if more items exist. */
|
|
7446
7443
|
nextFl: boolean;
|
|
7447
7444
|
|