Skip to content

Commit e331fb9

Browse files
committed
Rebuild.
1 parent 5a1c3d9 commit e331fb9

12 files changed

+126
-21
lines changed

lib/net/jsonClientSupport.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ export default abstract class JsonClientSupport<API extends UrlHelper, T> {
4040
*
4141
* @param url the URL to request.
4242
* @param signUrl the URL to sign (might be different to `url` if a proxy is used)
43+
* @param delay an optional number of milliseconds to sleep before initiating the request
4344
* @returns a function that accepts a callback argument
4445
*/
45-
protected requestor<V>(url: string, signUrl?: string): (cb: LoaderDataCallbackFn<V>) => void;
46+
protected requestor<V>(url: string, signUrl?: string, delay?: number): (cb: LoaderDataCallbackFn<V>) => void;
4647
}
4748
//# sourceMappingURL=jsonClientSupport.d.ts.map

lib/net/jsonClientSupport.d.ts.map

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change

lib/net/jsonClientSupport.js

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/net/jsonClientSupport.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/solarnetwork-api-core.es.cjs

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// https://github.com/SolarNetwork/sn-api-core-js Version 3.1.2. Copyright 2025 SolarNetwork Foundation.
1+
// https://github.com/SolarNetwork/sn-api-core-js Version 3.1.3-dev.0. Copyright 2025 SolarNetwork Foundation.
22
'use strict';
33

44
/**
@@ -11747,11 +11747,12 @@ class JsonClientSupport {
1174711747
*
1174811748
* @param url the URL to request.
1174911749
* @param signUrl the URL to sign (might be different to `url` if a proxy is used)
11750+
* @param delay an optional number of milliseconds to sleep before initiating the request
1175011751
* @returns a function that accepts a callback argument
1175111752
*/
11752-
requestor(url, signUrl) {
11753+
requestor(url, signUrl, delay) {
1175311754
const auth = this.authBuilder;
11754-
return (cb) => {
11755+
const fn = (cb) => {
1175511756
const headers = {
1175611757
Accept: "application/json",
1175711758
};
@@ -11788,6 +11789,14 @@ class JsonClientSupport {
1178811789
}, errorHandler);
1178911790
}, errorHandler);
1179011791
};
11792+
if (delay && delay > 0) {
11793+
return (cb) => {
11794+
setTimeout(() => {
11795+
fn.call(this, cb);
11796+
}, delay);
11797+
};
11798+
}
11799+
return fn;
1179111800
}
1179211801
}
1179311802

@@ -12890,6 +12899,7 @@ class ControlToggler {
1289012899
}
1289112900

1289212901
const DEFAULT_PAGE_SIZE = 1000;
12902+
const DEFAULT_JITTER = 150;
1289312903
/**
1289412904
* An enumeration of loader state values.
1289512905
*/
@@ -12945,6 +12955,11 @@ class DatumLoader extends JsonClientSupport {
1294512955
* results, followed by parallel requests for the remaining pages.
1294612956
*/
1294712957
#concurrency;
12958+
/**
12959+
* When > 0 then add a random amount of milliseconds up to this amount before initiating
12960+
* parallel requests (thus #concurrency must also be configured).
12961+
*/
12962+
#jitter;
1294812963
/**
1294912964
* A queue to use for parallel mode, when `concurrency` configured > 0.
1295012965
*/
@@ -12971,17 +12986,27 @@ class DatumLoader extends JsonClientSupport {
1297112986
this.#readingsMode = false;
1297212987
this.#proxyUrl = null;
1297312988
this.#concurrency = 0;
12989+
this.#jitter = DEFAULT_JITTER;
1297412990
this.#state = DatumLoaderState.Ready;
1297512991
}
1297612992
concurrency(value) {
1297712993
if (value === undefined) {
1297812994
return this.#concurrency;
1297912995
}
12980-
if (!isNaN(value) && Number(value) > 0) {
12996+
if (!isNaN(value) && Number(value) >= 0) {
1298112997
this.#concurrency = Number(value);
1298212998
}
1298312999
return this;
1298413000
}
13001+
jitter(value) {
13002+
if (value === undefined) {
13003+
return this.#jitter;
13004+
}
13005+
if (!isNaN(value) && Number(value) >= 0) {
13006+
this.#jitter = Number(value);
13007+
}
13008+
return this;
13009+
}
1298513010
callback(value) {
1298613011
if (value === undefined) {
1298713012
return this.#callback;
@@ -13138,7 +13163,11 @@ class DatumLoader extends JsonClientSupport {
1313813163
const reqUrl = this.#proxyUrl
1313913164
? url.replace(/^[^:]+:\/\/[^/]+/, this.#proxyUrl)
1314013165
: url;
13141-
const query = this.requestor(reqUrl, url);
13166+
// add delay for parallel mode if jitter configured
13167+
const delay = q && this.#jitter > 0
13168+
? Math.floor(Math.random() * this.#jitter) + 1
13169+
: 0;
13170+
const query = this.requestor(reqUrl, url, delay);
1314213171
const handler = (error, data) => {
1314313172
if (error) {
1314413173
if (!q) {

lib/solarnetwork-api-core.es.cjs.map

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

lib/solarnetwork-api-core.es.js

Lines changed: 34 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/solarnetwork-api-core.es.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/tool/datumLoader.d.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,23 @@ export default class DatumLoader extends JsonClientSupport<SolarQueryApi, Datum[
6666
* @returns this object
6767
*/
6868
concurrency(value: number): this;
69+
/**
70+
* Get the concurrency jitter value to use for parallel requests.
71+
*
72+
* @returns the current concurrency jitter value (milliseconds); defaults to `150`
73+
*/
74+
jitter(): number;
75+
/**
76+
* Set the concurrency jitter amount to use for parallel requests.
77+
*
78+
* When parallel mode is enabled by setting `concurrency()` to a positive value, a random amount
79+
* of "pause" time can be added before parallel requests are made by configuring this
80+
* to a positive value. This can be helpful to avoid API rate limiting errors.
81+
*
82+
* @param value the concurrency jitter amount to use, in milliseconds, or `0` to disable
83+
* @returns this object
84+
*/
85+
jitter(value: number): this;
6986
/**
7087
* Get the optional callback function.
7188
*

lib/tool/datumLoader.d.ts.map

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change

0 commit comments

Comments
 (0)