bmlt-query-client 1.0.3 → 1.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/dist/app.d.ts +5 -3
- package/dist/app.js +846 -669
- package/dist/app.js.map +1 -1
- package/package.json +12 -13
package/dist/app.js
CHANGED
|
@@ -1,463 +1,411 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
1
|
+
var De = Object.defineProperty;
|
|
2
|
+
var be = (r) => {
|
|
3
3
|
throw TypeError(r);
|
|
4
4
|
};
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
5
|
+
var $e = (r, e, t) => e in r ? De(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
|
|
6
|
+
var R = (r, e, t) => $e(r, typeof e != "symbol" ? e + "" : e, t), me = (r, e, t) => e.has(r) || be("Cannot " + t);
|
|
7
|
+
var n = (r, e, t) => (me(r, e, "read from private field"), t ? t.call(r) : e.get(r)), p = (r, e, t) => e.has(r) ? be("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(r) : e.set(r, t), w = (r, e, t, i) => (me(r, e, "write to private field"), i ? i.call(r, t) : e.set(r, t), t), m = (r, e, t) => (me(r, e, "access private method"), t);
|
|
8
8
|
var H = (r, e, t, i) => ({
|
|
9
|
-
set _(
|
|
10
|
-
|
|
9
|
+
set _(s) {
|
|
10
|
+
w(r, e, s, t);
|
|
11
11
|
},
|
|
12
12
|
get _() {
|
|
13
|
-
return
|
|
13
|
+
return n(r, e, i);
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
|
-
|
|
17
|
-
return r && r.__esModule && Object.prototype.hasOwnProperty.call(r, "default") ? r.default : r;
|
|
18
|
-
}
|
|
19
|
-
var re = {}, ie, he;
|
|
20
|
-
function Pe() {
|
|
21
|
-
if (he) return ie;
|
|
22
|
-
he = 1;
|
|
23
|
-
function r(e, t) {
|
|
24
|
-
typeof t == "boolean" && (t = { forever: t }), this._originalTimeouts = JSON.parse(JSON.stringify(e)), this._timeouts = e, this._options = t || {}, this._maxRetryTime = t && t.maxRetryTime || 1 / 0, this._fn = null, this._errors = [], this._attempts = 1, this._operationTimeout = null, this._operationTimeoutCb = null, this._timeout = null, this._operationStart = null, this._timer = null, this._options.forever && (this._cachedTimeouts = this._timeouts.slice(0));
|
|
25
|
-
}
|
|
26
|
-
return ie = r, r.prototype.reset = function() {
|
|
27
|
-
this._attempts = 1, this._timeouts = this._originalTimeouts.slice(0);
|
|
28
|
-
}, r.prototype.stop = function() {
|
|
29
|
-
this._timeout && clearTimeout(this._timeout), this._timer && clearTimeout(this._timer), this._timeouts = [], this._cachedTimeouts = null;
|
|
30
|
-
}, r.prototype.retry = function(e) {
|
|
31
|
-
if (this._timeout && clearTimeout(this._timeout), !e)
|
|
32
|
-
return !1;
|
|
33
|
-
var t = (/* @__PURE__ */ new Date()).getTime();
|
|
34
|
-
if (e && t - this._operationStart >= this._maxRetryTime)
|
|
35
|
-
return this._errors.push(e), this._errors.unshift(new Error("RetryOperation timeout occurred")), !1;
|
|
36
|
-
this._errors.push(e);
|
|
37
|
-
var i = this._timeouts.shift();
|
|
38
|
-
if (i === void 0)
|
|
39
|
-
if (this._cachedTimeouts)
|
|
40
|
-
this._errors.splice(0, this._errors.length - 1), i = this._cachedTimeouts.slice(-1);
|
|
41
|
-
else
|
|
42
|
-
return !1;
|
|
43
|
-
var n = this;
|
|
44
|
-
return this._timer = setTimeout(function() {
|
|
45
|
-
n._attempts++, n._operationTimeoutCb && (n._timeout = setTimeout(function() {
|
|
46
|
-
n._operationTimeoutCb(n._attempts);
|
|
47
|
-
}, n._operationTimeout), n._options.unref && n._timeout.unref()), n._fn(n._attempts);
|
|
48
|
-
}, i), this._options.unref && this._timer.unref(), !0;
|
|
49
|
-
}, r.prototype.attempt = function(e, t) {
|
|
50
|
-
this._fn = e, t && (t.timeout && (this._operationTimeout = t.timeout), t.cb && (this._operationTimeoutCb = t.cb));
|
|
51
|
-
var i = this;
|
|
52
|
-
this._operationTimeoutCb && (this._timeout = setTimeout(function() {
|
|
53
|
-
i._operationTimeoutCb();
|
|
54
|
-
}, i._operationTimeout)), this._operationStart = (/* @__PURE__ */ new Date()).getTime(), this._fn(this._attempts);
|
|
55
|
-
}, r.prototype.try = function(e) {
|
|
56
|
-
console.log("Using RetryOperation.try() is deprecated"), this.attempt(e);
|
|
57
|
-
}, r.prototype.start = function(e) {
|
|
58
|
-
console.log("Using RetryOperation.start() is deprecated"), this.attempt(e);
|
|
59
|
-
}, r.prototype.start = r.prototype.try, r.prototype.errors = function() {
|
|
60
|
-
return this._errors;
|
|
61
|
-
}, r.prototype.attempts = function() {
|
|
62
|
-
return this._attempts;
|
|
63
|
-
}, r.prototype.mainError = function() {
|
|
64
|
-
if (this._errors.length === 0)
|
|
65
|
-
return null;
|
|
66
|
-
for (var e = {}, t = null, i = 0, n = 0; n < this._errors.length; n++) {
|
|
67
|
-
var a = this._errors[n], s = a.message, o = (e[s] || 0) + 1;
|
|
68
|
-
e[s] = o, o >= i && (t = a, i = o);
|
|
69
|
-
}
|
|
70
|
-
return t;
|
|
71
|
-
}, ie;
|
|
72
|
-
}
|
|
73
|
-
var le;
|
|
74
|
-
function Ge() {
|
|
75
|
-
return le || (le = 1, (function(r) {
|
|
76
|
-
var e = Pe();
|
|
77
|
-
r.operation = function(t) {
|
|
78
|
-
var i = r.timeouts(t);
|
|
79
|
-
return new e(i, {
|
|
80
|
-
forever: t && (t.forever || t.retries === 1 / 0),
|
|
81
|
-
unref: t && t.unref,
|
|
82
|
-
maxRetryTime: t && t.maxRetryTime
|
|
83
|
-
});
|
|
84
|
-
}, r.timeouts = function(t) {
|
|
85
|
-
if (t instanceof Array)
|
|
86
|
-
return [].concat(t);
|
|
87
|
-
var i = {
|
|
88
|
-
retries: 10,
|
|
89
|
-
factor: 2,
|
|
90
|
-
minTimeout: 1 * 1e3,
|
|
91
|
-
maxTimeout: 1 / 0,
|
|
92
|
-
randomize: !1
|
|
93
|
-
};
|
|
94
|
-
for (var n in t)
|
|
95
|
-
i[n] = t[n];
|
|
96
|
-
if (i.minTimeout > i.maxTimeout)
|
|
97
|
-
throw new Error("minTimeout is greater than maxTimeout");
|
|
98
|
-
for (var a = [], s = 0; s < i.retries; s++)
|
|
99
|
-
a.push(this.createTimeout(s, i));
|
|
100
|
-
return t && t.forever && !a.length && a.push(this.createTimeout(s, i)), a.sort(function(o, u) {
|
|
101
|
-
return o - u;
|
|
102
|
-
}), a;
|
|
103
|
-
}, r.createTimeout = function(t, i) {
|
|
104
|
-
var n = i.randomize ? Math.random() + 1 : 1, a = Math.round(n * Math.max(i.minTimeout, 1) * Math.pow(i.factor, t));
|
|
105
|
-
return a = Math.min(a, i.maxTimeout), a;
|
|
106
|
-
}, r.wrap = function(t, i, n) {
|
|
107
|
-
if (i instanceof Array && (n = i, i = null), !n) {
|
|
108
|
-
n = [];
|
|
109
|
-
for (var a in t)
|
|
110
|
-
typeof t[a] == "function" && n.push(a);
|
|
111
|
-
}
|
|
112
|
-
for (var s = 0; s < n.length; s++) {
|
|
113
|
-
var o = n[s], u = t[o];
|
|
114
|
-
t[o] = function(h) {
|
|
115
|
-
var f = r.operation(i), p = Array.prototype.slice.call(arguments, 1), E = p.pop();
|
|
116
|
-
p.push(function(y) {
|
|
117
|
-
f.retry(y) || (y && (arguments[0] = f.mainError()), E.apply(this, arguments));
|
|
118
|
-
}), f.attempt(function() {
|
|
119
|
-
h.apply(t, p);
|
|
120
|
-
});
|
|
121
|
-
}.bind(t, u), t[o].options = i;
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
})(re)), re;
|
|
125
|
-
}
|
|
126
|
-
var ne, fe;
|
|
127
|
-
function Le() {
|
|
128
|
-
return fe || (fe = 1, ne = Ge()), ne;
|
|
129
|
-
}
|
|
130
|
-
var Ue = Le();
|
|
131
|
-
const xe = /* @__PURE__ */ ve(Ue), De = Object.prototype.toString, Fe = (r) => De.call(r) === "[object Error]", ke = /* @__PURE__ */ new Set([
|
|
16
|
+
const Me = Object.prototype.toString, qe = (r) => Me.call(r) === "[object Error]", Ve = /* @__PURE__ */ new Set([
|
|
132
17
|
"network error",
|
|
133
18
|
// Chrome
|
|
134
|
-
"Failed to fetch",
|
|
135
|
-
// Chrome
|
|
136
19
|
"NetworkError when attempting to fetch resource.",
|
|
137
20
|
// Firefox
|
|
138
21
|
"The Internet connection appears to be offline.",
|
|
139
22
|
// Safari 16
|
|
140
|
-
"Load failed",
|
|
141
|
-
// Safari 17+
|
|
142
23
|
"Network request failed",
|
|
143
24
|
// `cross-fetch`
|
|
144
25
|
"fetch failed",
|
|
145
26
|
// Undici (Node.js)
|
|
146
|
-
"terminated"
|
|
27
|
+
"terminated",
|
|
147
28
|
// Undici (Node.js)
|
|
29
|
+
" A network error occurred.",
|
|
30
|
+
// Bun (WebKit)
|
|
31
|
+
"Network connection lost"
|
|
32
|
+
// Cloudflare Workers (fetch)
|
|
148
33
|
]);
|
|
149
|
-
function
|
|
150
|
-
|
|
34
|
+
function Ye(r) {
|
|
35
|
+
if (!(r && qe(r) && r.name === "TypeError" && typeof r.message == "string"))
|
|
36
|
+
return !1;
|
|
37
|
+
const { message: t, stack: i } = r;
|
|
38
|
+
return t === "Load failed" ? i === void 0 || "__sentry_captured__" in r : t.startsWith("error sending request for url") || t === "Failed to fetch" || t.startsWith("Failed to fetch (") && t.endsWith(")") ? !0 : Ve.has(t);
|
|
39
|
+
}
|
|
40
|
+
function ze(r) {
|
|
41
|
+
if (typeof r == "number") {
|
|
42
|
+
if (r < 0)
|
|
43
|
+
throw new TypeError("Expected `retries` to be a non-negative number.");
|
|
44
|
+
if (Number.isNaN(r))
|
|
45
|
+
throw new TypeError("Expected `retries` to be a valid number or Infinity, got NaN.");
|
|
46
|
+
} else if (r !== void 0)
|
|
47
|
+
throw new TypeError("Expected `retries` to be a number or Infinity.");
|
|
151
48
|
}
|
|
152
|
-
|
|
49
|
+
function ne(r, e, { min: t = 0, allowInfinity: i = !1 } = {}) {
|
|
50
|
+
if (e !== void 0) {
|
|
51
|
+
if (typeof e != "number" || Number.isNaN(e))
|
|
52
|
+
throw new TypeError(`Expected \`${r}\` to be a number${i ? " or Infinity" : ""}.`);
|
|
53
|
+
if (!i && !Number.isFinite(e))
|
|
54
|
+
throw new TypeError(`Expected \`${r}\` to be a finite number.`);
|
|
55
|
+
if (e < t)
|
|
56
|
+
throw new TypeError(`Expected \`${r}\` to be ≥ ${t}.`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
class He extends Error {
|
|
153
60
|
constructor(e) {
|
|
154
61
|
super(), e instanceof Error ? (this.originalError = e, { message: e } = e) : (this.originalError = new Error(e), this.originalError.stack = this.stack), this.name = "AbortError", this.message = e;
|
|
155
62
|
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
const i =
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const u = await r(o);
|
|
175
|
-
s(), t(u);
|
|
176
|
-
} catch (u) {
|
|
177
|
-
try {
|
|
178
|
-
if (!(u instanceof Error))
|
|
179
|
-
throw new TypeError(`Non-error was thrown: "${u}". You should only throw errors.`);
|
|
180
|
-
if (u instanceof Me)
|
|
181
|
-
throw u.originalError;
|
|
182
|
-
if (u instanceof TypeError && !$e(u))
|
|
183
|
-
throw u;
|
|
184
|
-
if (de(u, o, e), await e.shouldRetry(u) || (n.stop(), i(u)), await e.onFailedAttempt(u), !n.retry(u))
|
|
185
|
-
throw n.mainError();
|
|
186
|
-
} catch (c) {
|
|
187
|
-
de(c, o, e), s(), i(c);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
});
|
|
63
|
+
}
|
|
64
|
+
function Je(r, e) {
|
|
65
|
+
const t = Math.max(1, r + 1), i = e.randomize ? Math.random() + 1 : 1;
|
|
66
|
+
let s = Math.round(i * e.minTimeout * e.factor ** (t - 1));
|
|
67
|
+
return s = Math.min(s, e.maxTimeout), s;
|
|
68
|
+
}
|
|
69
|
+
function Te(r, e) {
|
|
70
|
+
return Number.isFinite(e) ? e - (performance.now() - r) : e;
|
|
71
|
+
}
|
|
72
|
+
async function je({ error: r, attemptNumber: e, retriesConsumed: t, startTime: i, options: s }) {
|
|
73
|
+
const a = r instanceof Error ? r : new TypeError(`Non-error was thrown: "${r}". You should only throw errors.`);
|
|
74
|
+
if (a instanceof He)
|
|
75
|
+
throw a.originalError;
|
|
76
|
+
const c = Number.isFinite(s.retries) ? Math.max(0, s.retries - t) : s.retries, u = s.maxRetryTime ?? Number.POSITIVE_INFINITY, o = Object.freeze({
|
|
77
|
+
error: a,
|
|
78
|
+
attemptNumber: e,
|
|
79
|
+
retriesLeft: c,
|
|
80
|
+
retriesConsumed: t
|
|
191
81
|
});
|
|
82
|
+
if (await s.onFailedAttempt(o), Te(i, u) <= 0)
|
|
83
|
+
throw a;
|
|
84
|
+
const l = await s.shouldConsumeRetry(o), d = Te(i, u);
|
|
85
|
+
if (d <= 0 || c <= 0)
|
|
86
|
+
throw a;
|
|
87
|
+
if (a instanceof TypeError && !Ye(a)) {
|
|
88
|
+
if (l)
|
|
89
|
+
throw a;
|
|
90
|
+
return s.signal?.throwIfAborted(), !1;
|
|
91
|
+
}
|
|
92
|
+
if (!await s.shouldRetry(o))
|
|
93
|
+
throw a;
|
|
94
|
+
if (!l)
|
|
95
|
+
return s.signal?.throwIfAborted(), !1;
|
|
96
|
+
const f = Je(t, s), g = Math.min(f, d);
|
|
97
|
+
return s.signal?.throwIfAborted(), g > 0 && await new Promise((b, y) => {
|
|
98
|
+
const O = () => {
|
|
99
|
+
clearTimeout(E), s.signal?.removeEventListener("abort", O), y(s.signal.reason);
|
|
100
|
+
}, E = setTimeout(() => {
|
|
101
|
+
s.signal?.removeEventListener("abort", O), b();
|
|
102
|
+
}, g);
|
|
103
|
+
s.unref && E.unref?.(), s.signal?.addEventListener("abort", O, { once: !0 });
|
|
104
|
+
}), s.signal?.throwIfAborted(), !0;
|
|
105
|
+
}
|
|
106
|
+
async function Se(r, e = {}) {
|
|
107
|
+
if (e = { ...e }, ze(e.retries), Object.hasOwn(e, "forever"))
|
|
108
|
+
throw new Error("The `forever` option is no longer supported. For many use-cases, you can set `retries: Infinity` instead.");
|
|
109
|
+
e.retries ?? (e.retries = 10), e.factor ?? (e.factor = 2), e.minTimeout ?? (e.minTimeout = 1e3), e.maxTimeout ?? (e.maxTimeout = Number.POSITIVE_INFINITY), e.maxRetryTime ?? (e.maxRetryTime = Number.POSITIVE_INFINITY), e.randomize ?? (e.randomize = !1), e.onFailedAttempt ?? (e.onFailedAttempt = () => {
|
|
110
|
+
}), e.shouldRetry ?? (e.shouldRetry = () => !0), e.shouldConsumeRetry ?? (e.shouldConsumeRetry = () => !0), ne("factor", e.factor, { min: 0, allowInfinity: !1 }), ne("minTimeout", e.minTimeout, { min: 0, allowInfinity: !1 }), ne("maxTimeout", e.maxTimeout, { min: 0, allowInfinity: !0 }), ne("maxRetryTime", e.maxRetryTime, { min: 0, allowInfinity: !0 }), e.factor > 0 || (e.factor = 1), e.signal?.throwIfAborted();
|
|
111
|
+
let t = 0, i = 0;
|
|
112
|
+
const s = performance.now();
|
|
113
|
+
for (; !Number.isFinite(e.retries) || i <= e.retries; ) {
|
|
114
|
+
t++;
|
|
115
|
+
try {
|
|
116
|
+
e.signal?.throwIfAborted();
|
|
117
|
+
const a = await r(t);
|
|
118
|
+
return e.signal?.throwIfAborted(), a;
|
|
119
|
+
} catch (a) {
|
|
120
|
+
await je({
|
|
121
|
+
error: a,
|
|
122
|
+
attemptNumber: t,
|
|
123
|
+
retriesConsumed: i,
|
|
124
|
+
startTime: s,
|
|
125
|
+
options: e
|
|
126
|
+
}) && i++;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
throw new Error("Retry attempts exhausted without throwing an error.");
|
|
192
130
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
131
|
+
function We(r) {
|
|
132
|
+
return r && r.__esModule && Object.prototype.hasOwnProperty.call(r, "default") ? r.default : r;
|
|
133
|
+
}
|
|
134
|
+
var Ee = { exports: {} }, Re;
|
|
135
|
+
function Be() {
|
|
136
|
+
return Re || (Re = 1, (function(r) {
|
|
196
137
|
var e = Object.prototype.hasOwnProperty, t = "~";
|
|
197
138
|
function i() {
|
|
198
139
|
}
|
|
199
140
|
Object.create && (i.prototype = /* @__PURE__ */ Object.create(null), new i().__proto__ || (t = !1));
|
|
200
|
-
function
|
|
201
|
-
this.fn =
|
|
141
|
+
function s(o, l, d) {
|
|
142
|
+
this.fn = o, this.context = l, this.once = d || !1;
|
|
202
143
|
}
|
|
203
|
-
function a(
|
|
204
|
-
if (typeof
|
|
144
|
+
function a(o, l, d, f, g) {
|
|
145
|
+
if (typeof d != "function")
|
|
205
146
|
throw new TypeError("The listener must be a function");
|
|
206
|
-
var
|
|
207
|
-
return
|
|
147
|
+
var b = new s(d, f || o, g), y = t ? t + l : l;
|
|
148
|
+
return o._events[y] ? o._events[y].fn ? o._events[y] = [o._events[y], b] : o._events[y].push(b) : (o._events[y] = b, o._eventsCount++), o;
|
|
208
149
|
}
|
|
209
|
-
function
|
|
210
|
-
--
|
|
150
|
+
function c(o, l) {
|
|
151
|
+
--o._eventsCount === 0 ? o._events = new i() : delete o._events[l];
|
|
211
152
|
}
|
|
212
|
-
function
|
|
153
|
+
function u() {
|
|
213
154
|
this._events = new i(), this._eventsCount = 0;
|
|
214
155
|
}
|
|
215
|
-
|
|
216
|
-
var
|
|
217
|
-
if (this._eventsCount === 0) return
|
|
218
|
-
for (f in
|
|
219
|
-
e.call(
|
|
220
|
-
return Object.getOwnPropertySymbols ?
|
|
221
|
-
},
|
|
222
|
-
var
|
|
156
|
+
u.prototype.eventNames = function() {
|
|
157
|
+
var l = [], d, f;
|
|
158
|
+
if (this._eventsCount === 0) return l;
|
|
159
|
+
for (f in d = this._events)
|
|
160
|
+
e.call(d, f) && l.push(t ? f.slice(1) : f);
|
|
161
|
+
return Object.getOwnPropertySymbols ? l.concat(Object.getOwnPropertySymbols(d)) : l;
|
|
162
|
+
}, u.prototype.listeners = function(l) {
|
|
163
|
+
var d = t ? t + l : l, f = this._events[d];
|
|
223
164
|
if (!f) return [];
|
|
224
165
|
if (f.fn) return [f.fn];
|
|
225
|
-
for (var
|
|
226
|
-
y[
|
|
166
|
+
for (var g = 0, b = f.length, y = new Array(b); g < b; g++)
|
|
167
|
+
y[g] = f[g].fn;
|
|
227
168
|
return y;
|
|
228
|
-
},
|
|
229
|
-
var
|
|
169
|
+
}, u.prototype.listenerCount = function(l) {
|
|
170
|
+
var d = t ? t + l : l, f = this._events[d];
|
|
230
171
|
return f ? f.fn ? 1 : f.length : 0;
|
|
231
|
-
},
|
|
232
|
-
var
|
|
233
|
-
if (!this._events[
|
|
234
|
-
var
|
|
235
|
-
if (
|
|
236
|
-
switch (
|
|
172
|
+
}, u.prototype.emit = function(l, d, f, g, b, y) {
|
|
173
|
+
var O = t ? t + l : l;
|
|
174
|
+
if (!this._events[O]) return !1;
|
|
175
|
+
var E = this._events[O], V = arguments.length, z, T;
|
|
176
|
+
if (E.fn) {
|
|
177
|
+
switch (E.once && this.removeListener(l, E.fn, void 0, !0), V) {
|
|
237
178
|
case 1:
|
|
238
|
-
return
|
|
179
|
+
return E.fn.call(E.context), !0;
|
|
239
180
|
case 2:
|
|
240
|
-
return
|
|
181
|
+
return E.fn.call(E.context, d), !0;
|
|
241
182
|
case 3:
|
|
242
|
-
return
|
|
183
|
+
return E.fn.call(E.context, d, f), !0;
|
|
243
184
|
case 4:
|
|
244
|
-
return
|
|
185
|
+
return E.fn.call(E.context, d, f, g), !0;
|
|
245
186
|
case 5:
|
|
246
|
-
return
|
|
187
|
+
return E.fn.call(E.context, d, f, g, b), !0;
|
|
247
188
|
case 6:
|
|
248
|
-
return
|
|
189
|
+
return E.fn.call(E.context, d, f, g, b, y), !0;
|
|
249
190
|
}
|
|
250
|
-
for (
|
|
251
|
-
|
|
252
|
-
|
|
191
|
+
for (T = 1, z = new Array(V - 1); T < V; T++)
|
|
192
|
+
z[T - 1] = arguments[T];
|
|
193
|
+
E.fn.apply(E.context, z);
|
|
253
194
|
} else {
|
|
254
|
-
var
|
|
255
|
-
for (
|
|
256
|
-
switch (
|
|
195
|
+
var Ue = E.length, te;
|
|
196
|
+
for (T = 0; T < Ue; T++)
|
|
197
|
+
switch (E[T].once && this.removeListener(l, E[T].fn, void 0, !0), V) {
|
|
257
198
|
case 1:
|
|
258
|
-
|
|
199
|
+
E[T].fn.call(E[T].context);
|
|
259
200
|
break;
|
|
260
201
|
case 2:
|
|
261
|
-
|
|
202
|
+
E[T].fn.call(E[T].context, d);
|
|
262
203
|
break;
|
|
263
204
|
case 3:
|
|
264
|
-
|
|
205
|
+
E[T].fn.call(E[T].context, d, f);
|
|
265
206
|
break;
|
|
266
207
|
case 4:
|
|
267
|
-
|
|
208
|
+
E[T].fn.call(E[T].context, d, f, g);
|
|
268
209
|
break;
|
|
269
210
|
default:
|
|
270
|
-
if (!
|
|
271
|
-
|
|
272
|
-
|
|
211
|
+
if (!z) for (te = 1, z = new Array(V - 1); te < V; te++)
|
|
212
|
+
z[te - 1] = arguments[te];
|
|
213
|
+
E[T].fn.apply(E[T].context, z);
|
|
273
214
|
}
|
|
274
215
|
}
|
|
275
216
|
return !0;
|
|
276
|
-
},
|
|
277
|
-
return a(this,
|
|
278
|
-
},
|
|
279
|
-
return a(this,
|
|
280
|
-
},
|
|
281
|
-
var
|
|
282
|
-
if (!this._events[
|
|
283
|
-
if (!
|
|
284
|
-
return
|
|
285
|
-
var y = this._events[
|
|
217
|
+
}, u.prototype.on = function(l, d, f) {
|
|
218
|
+
return a(this, l, d, f, !1);
|
|
219
|
+
}, u.prototype.once = function(l, d, f) {
|
|
220
|
+
return a(this, l, d, f, !0);
|
|
221
|
+
}, u.prototype.removeListener = function(l, d, f, g) {
|
|
222
|
+
var b = t ? t + l : l;
|
|
223
|
+
if (!this._events[b]) return this;
|
|
224
|
+
if (!d)
|
|
225
|
+
return c(this, b), this;
|
|
226
|
+
var y = this._events[b];
|
|
286
227
|
if (y.fn)
|
|
287
|
-
y.fn ===
|
|
228
|
+
y.fn === d && (!g || y.once) && (!f || y.context === f) && c(this, b);
|
|
288
229
|
else {
|
|
289
|
-
for (var
|
|
290
|
-
(y[
|
|
291
|
-
|
|
230
|
+
for (var O = 0, E = [], V = y.length; O < V; O++)
|
|
231
|
+
(y[O].fn !== d || g && !y[O].once || f && y[O].context !== f) && E.push(y[O]);
|
|
232
|
+
E.length ? this._events[b] = E.length === 1 ? E[0] : E : c(this, b);
|
|
292
233
|
}
|
|
293
234
|
return this;
|
|
294
|
-
},
|
|
295
|
-
var
|
|
296
|
-
return
|
|
297
|
-
},
|
|
298
|
-
})(
|
|
235
|
+
}, u.prototype.removeAllListeners = function(l) {
|
|
236
|
+
var d;
|
|
237
|
+
return l ? (d = t ? t + l : l, this._events[d] && c(this, d)) : (this._events = new i(), this._eventsCount = 0), this;
|
|
238
|
+
}, u.prototype.off = u.prototype.removeListener, u.prototype.addListener = u.prototype.on, u.prefixed = t, u.EventEmitter = u, r.exports = u;
|
|
239
|
+
})(Ee)), Ee.exports;
|
|
299
240
|
}
|
|
300
|
-
var
|
|
301
|
-
const
|
|
302
|
-
class
|
|
303
|
-
constructor(
|
|
304
|
-
super(
|
|
241
|
+
var Qe = Be();
|
|
242
|
+
const Ke = /* @__PURE__ */ We(Qe);
|
|
243
|
+
class pe extends Error {
|
|
244
|
+
constructor(t, i) {
|
|
245
|
+
super(t, i);
|
|
246
|
+
R(this, "name", "TimeoutError");
|
|
247
|
+
Error.captureStackTrace?.(this, pe);
|
|
305
248
|
}
|
|
306
249
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
super(), this.name = "AbortError", this.message = e;
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
const pe = (r) => globalThis.DOMException === void 0 ? new He(r) : new DOMException(r), ge = (r) => {
|
|
313
|
-
const e = r.reason === void 0 ? pe("This operation was aborted.") : r.reason;
|
|
314
|
-
return e instanceof Error ? e : pe(e);
|
|
315
|
-
};
|
|
316
|
-
function Je(r, e) {
|
|
250
|
+
const _e = (r) => r.reason ?? new DOMException("This operation was aborted.", "AbortError");
|
|
251
|
+
function Ze(r, e) {
|
|
317
252
|
const {
|
|
318
253
|
milliseconds: t,
|
|
319
254
|
fallback: i,
|
|
320
|
-
message:
|
|
321
|
-
customTimers: a = { setTimeout, clearTimeout }
|
|
255
|
+
message: s,
|
|
256
|
+
customTimers: a = { setTimeout, clearTimeout },
|
|
257
|
+
signal: c
|
|
322
258
|
} = e;
|
|
323
|
-
let
|
|
324
|
-
const
|
|
259
|
+
let u, o;
|
|
260
|
+
const d = new Promise((f, g) => {
|
|
325
261
|
if (typeof t != "number" || Math.sign(t) !== 1)
|
|
326
262
|
throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);
|
|
327
|
-
if (
|
|
328
|
-
|
|
329
|
-
E.aborted && f(ge(E)), o = () => {
|
|
330
|
-
f(ge(E));
|
|
331
|
-
}, E.addEventListener("abort", o, { once: !0 });
|
|
332
|
-
}
|
|
333
|
-
if (t === Number.POSITIVE_INFINITY) {
|
|
334
|
-
r.then(h, f);
|
|
263
|
+
if (c?.aborted) {
|
|
264
|
+
g(_e(c));
|
|
335
265
|
return;
|
|
336
266
|
}
|
|
337
|
-
|
|
338
|
-
|
|
267
|
+
if (c && (o = () => {
|
|
268
|
+
g(_e(c));
|
|
269
|
+
}, c.addEventListener("abort", o, { once: !0 })), r.then(f, g), t === Number.POSITIVE_INFINITY)
|
|
270
|
+
return;
|
|
271
|
+
const b = new pe();
|
|
272
|
+
u = a.setTimeout.call(void 0, () => {
|
|
339
273
|
if (i) {
|
|
340
274
|
try {
|
|
341
|
-
|
|
342
|
-
} catch (
|
|
343
|
-
|
|
275
|
+
f(i());
|
|
276
|
+
} catch (y) {
|
|
277
|
+
g(y);
|
|
344
278
|
}
|
|
345
279
|
return;
|
|
346
280
|
}
|
|
347
|
-
typeof r.cancel == "function" && r.cancel(),
|
|
348
|
-
}, t)
|
|
349
|
-
try {
|
|
350
|
-
h(await r);
|
|
351
|
-
} catch (E) {
|
|
352
|
-
f(E);
|
|
353
|
-
}
|
|
354
|
-
})();
|
|
281
|
+
typeof r.cancel == "function" && r.cancel(), s === !1 ? f() : s instanceof Error ? g(s) : (b.message = s ?? `Promise timed out after ${t} milliseconds`, g(b));
|
|
282
|
+
}, t);
|
|
355
283
|
}).finally(() => {
|
|
356
|
-
|
|
284
|
+
d.clear(), o && c && c.removeEventListener("abort", o);
|
|
357
285
|
});
|
|
358
|
-
return
|
|
359
|
-
a.clearTimeout.call(void 0,
|
|
360
|
-
},
|
|
286
|
+
return d.clear = () => {
|
|
287
|
+
a.clearTimeout.call(void 0, u), u = void 0;
|
|
288
|
+
}, d;
|
|
361
289
|
}
|
|
362
|
-
function
|
|
363
|
-
let i = 0,
|
|
364
|
-
for (;
|
|
365
|
-
const a = Math.trunc(
|
|
366
|
-
let
|
|
367
|
-
t(r[
|
|
290
|
+
function Xe(r, e, t) {
|
|
291
|
+
let i = 0, s = r.length;
|
|
292
|
+
for (; s > 0; ) {
|
|
293
|
+
const a = Math.trunc(s / 2);
|
|
294
|
+
let c = i + a;
|
|
295
|
+
t(r[c], e) <= 0 ? (i = ++c, s -= a + 1) : s = a;
|
|
368
296
|
}
|
|
369
297
|
return i;
|
|
370
298
|
}
|
|
371
|
-
var
|
|
372
|
-
class
|
|
299
|
+
var L;
|
|
300
|
+
class et {
|
|
373
301
|
constructor() {
|
|
374
|
-
|
|
302
|
+
p(this, L, []);
|
|
375
303
|
}
|
|
376
304
|
enqueue(e, t) {
|
|
377
|
-
t = {
|
|
378
|
-
priority:
|
|
379
|
-
|
|
380
|
-
};
|
|
381
|
-
const i = {
|
|
382
|
-
priority: t.priority,
|
|
383
|
-
id: t.id,
|
|
305
|
+
const { priority: i = 0, id: s } = t ?? {}, a = {
|
|
306
|
+
priority: i,
|
|
307
|
+
id: s,
|
|
384
308
|
run: e
|
|
385
309
|
};
|
|
386
|
-
if (this.size === 0 ||
|
|
387
|
-
|
|
310
|
+
if (this.size === 0 || n(this, L)[this.size - 1].priority >= i) {
|
|
311
|
+
n(this, L).push(a);
|
|
388
312
|
return;
|
|
389
313
|
}
|
|
390
|
-
const
|
|
391
|
-
|
|
314
|
+
const c = Xe(n(this, L), a, (u, o) => o.priority - u.priority);
|
|
315
|
+
n(this, L).splice(c, 0, a);
|
|
392
316
|
}
|
|
393
317
|
setPriority(e, t) {
|
|
394
|
-
const i =
|
|
318
|
+
const i = n(this, L).findIndex((a) => a.id === e);
|
|
395
319
|
if (i === -1)
|
|
396
320
|
throw new ReferenceError(`No promise function with the id "${e}" exists in the queue.`);
|
|
397
|
-
const [
|
|
398
|
-
this.enqueue(
|
|
321
|
+
const [s] = n(this, L).splice(i, 1);
|
|
322
|
+
this.enqueue(s.run, { priority: t, id: e });
|
|
399
323
|
}
|
|
400
324
|
dequeue() {
|
|
401
|
-
return
|
|
325
|
+
return n(this, L).shift()?.run;
|
|
402
326
|
}
|
|
403
327
|
filter(e) {
|
|
404
|
-
return
|
|
328
|
+
return n(this, L).filter((t) => t.priority === e.priority).map((t) => t.run);
|
|
405
329
|
}
|
|
406
330
|
get size() {
|
|
407
|
-
return
|
|
331
|
+
return n(this, L).length;
|
|
408
332
|
}
|
|
409
333
|
}
|
|
410
|
-
|
|
411
|
-
var k,
|
|
412
|
-
class
|
|
413
|
-
// TODO: The `throwOnTimeout` option should affect the return types of `add()` and `addAll()`
|
|
334
|
+
L = new WeakMap();
|
|
335
|
+
var Z, x, k, Y, j, X, U, ie, ee, D, M, P, I, N, S, se, A, W, q, fe, B, h, oe, Ne, Ie, ue, Oe, Ce, Le, Pe, xe, ce, he, ge, le, we, ye, de, J, ke, Q, Ge, ve;
|
|
336
|
+
class tt extends Ke {
|
|
414
337
|
constructor(t) {
|
|
415
338
|
super();
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
339
|
+
p(this, h);
|
|
340
|
+
p(this, Z);
|
|
341
|
+
p(this, x);
|
|
342
|
+
p(this, k, 0);
|
|
343
|
+
p(this, Y);
|
|
344
|
+
p(this, j, !1);
|
|
345
|
+
p(this, X, !1);
|
|
346
|
+
p(this, U);
|
|
347
|
+
p(this, ie, 0);
|
|
348
|
+
p(this, ee, 0);
|
|
349
|
+
p(this, D);
|
|
350
|
+
p(this, M);
|
|
351
|
+
p(this, P);
|
|
352
|
+
// Circular buffer implementation for better performance
|
|
353
|
+
p(this, I, []);
|
|
354
|
+
p(this, N, 0);
|
|
355
|
+
p(this, S);
|
|
356
|
+
p(this, se);
|
|
357
|
+
p(this, A, 0);
|
|
428
358
|
// The `!` is needed because of https://github.com/microsoft/TypeScript/issues/32194
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
T(this, j);
|
|
359
|
+
p(this, W);
|
|
360
|
+
p(this, q);
|
|
432
361
|
// Use to assign a unique identifier to a promise function, if not explicitly specified
|
|
433
|
-
|
|
362
|
+
p(this, fe, 1n);
|
|
363
|
+
// Track currently running tasks for debugging
|
|
364
|
+
p(this, B, /* @__PURE__ */ new Map());
|
|
434
365
|
/**
|
|
435
|
-
|
|
366
|
+
Get or set the default timeout for all tasks. Can be changed at runtime.
|
|
367
|
+
|
|
368
|
+
Operations will throw a `TimeoutError` if they don't complete within the specified time.
|
|
436
369
|
|
|
437
|
-
|
|
370
|
+
The timeout begins when the operation is dequeued and starts execution, not while it's waiting in the queue.
|
|
371
|
+
|
|
372
|
+
@example
|
|
373
|
+
```
|
|
374
|
+
const queue = new PQueue({timeout: 5000});
|
|
375
|
+
|
|
376
|
+
// Change timeout for all future tasks
|
|
377
|
+
queue.timeout = 10000;
|
|
378
|
+
```
|
|
438
379
|
*/
|
|
439
|
-
|
|
380
|
+
R(this, "timeout");
|
|
440
381
|
if (t = {
|
|
441
|
-
|
|
382
|
+
carryoverIntervalCount: !1,
|
|
442
383
|
intervalCap: Number.POSITIVE_INFINITY,
|
|
443
384
|
interval: 0,
|
|
444
385
|
concurrency: Number.POSITIVE_INFINITY,
|
|
445
386
|
autoStart: !0,
|
|
446
|
-
queueClass:
|
|
387
|
+
queueClass: et,
|
|
388
|
+
strict: !1,
|
|
447
389
|
...t
|
|
448
390
|
}, !(typeof t.intervalCap == "number" && t.intervalCap >= 1))
|
|
449
391
|
throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${t.intervalCap?.toString() ?? ""}\` (${typeof t.intervalCap})`);
|
|
450
392
|
if (t.interval === void 0 || !(Number.isFinite(t.interval) && t.interval >= 0))
|
|
451
393
|
throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${t.interval?.toString() ?? ""}\` (${typeof t.interval})`);
|
|
452
|
-
|
|
394
|
+
if (t.strict && t.interval === 0)
|
|
395
|
+
throw new TypeError("The `strict` option requires a non-zero `interval`");
|
|
396
|
+
if (t.strict && t.intervalCap === Number.POSITIVE_INFINITY)
|
|
397
|
+
throw new TypeError("The `strict` option requires a finite `intervalCap`");
|
|
398
|
+
if (w(this, Z, t.carryoverIntervalCount ?? t.carryoverConcurrencyCount ?? !1), w(this, x, t.intervalCap === Number.POSITIVE_INFINITY || t.interval === 0), w(this, Y, t.intervalCap), w(this, U, t.interval), w(this, P, t.strict), w(this, S, new t.queueClass()), w(this, se, t.queueClass), this.concurrency = t.concurrency, t.timeout !== void 0 && !(Number.isFinite(t.timeout) && t.timeout > 0))
|
|
399
|
+
throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${t.timeout}\` (${typeof t.timeout})`);
|
|
400
|
+
this.timeout = t.timeout, w(this, q, t.autoStart === !1), m(this, h, ke).call(this);
|
|
453
401
|
}
|
|
454
402
|
get concurrency() {
|
|
455
|
-
return
|
|
403
|
+
return n(this, W);
|
|
456
404
|
}
|
|
457
405
|
set concurrency(t) {
|
|
458
406
|
if (!(typeof t == "number" && t >= 1))
|
|
459
407
|
throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${t}\` (${typeof t})`);
|
|
460
|
-
|
|
408
|
+
w(this, W, t), m(this, h, de).call(this);
|
|
461
409
|
}
|
|
462
410
|
/**
|
|
463
411
|
Updates the priority of a promise function by its id, affecting its execution order. Requires a defined concurrency limit to take effect.
|
|
@@ -496,54 +444,78 @@ class Qe extends Ye {
|
|
|
496
444
|
Here, the promise function with `id: '🦀'` executes last.
|
|
497
445
|
*/
|
|
498
446
|
setPriority(t, i) {
|
|
499
|
-
|
|
447
|
+
if (typeof i != "number" || !Number.isFinite(i))
|
|
448
|
+
throw new TypeError(`Expected \`priority\` to be a finite number, got \`${i}\` (${typeof i})`);
|
|
449
|
+
n(this, S).setPriority(t, i);
|
|
500
450
|
}
|
|
501
451
|
async add(t, i = {}) {
|
|
502
|
-
return i
|
|
452
|
+
return i = {
|
|
503
453
|
timeout: this.timeout,
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
454
|
+
...i,
|
|
455
|
+
// Assign unique ID if not provided
|
|
456
|
+
id: i.id ?? (H(this, fe)._++).toString()
|
|
457
|
+
}, new Promise((s, a) => {
|
|
458
|
+
const c = /* @__PURE__ */ Symbol(`task-${i.id}`);
|
|
459
|
+
n(this, S).enqueue(async () => {
|
|
460
|
+
H(this, A)._++, n(this, B).set(c, {
|
|
461
|
+
id: i.id,
|
|
462
|
+
priority: i.priority ?? 0,
|
|
463
|
+
// Match priority-queue default
|
|
464
|
+
startTime: Date.now(),
|
|
465
|
+
timeout: i.timeout
|
|
466
|
+
});
|
|
467
|
+
let u;
|
|
509
468
|
try {
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
n(o), this.emit("completed", o);
|
|
515
|
-
} catch (s) {
|
|
516
|
-
if (s instanceof we && !i.throwOnTimeout) {
|
|
517
|
-
n();
|
|
518
|
-
return;
|
|
469
|
+
try {
|
|
470
|
+
i.signal?.throwIfAborted();
|
|
471
|
+
} catch (d) {
|
|
472
|
+
throw m(this, h, Ge).call(this), n(this, B).delete(c), d;
|
|
519
473
|
}
|
|
520
|
-
|
|
474
|
+
w(this, ee, Date.now());
|
|
475
|
+
let o = t({ signal: i.signal });
|
|
476
|
+
if (i.timeout && (o = Ze(Promise.resolve(o), {
|
|
477
|
+
milliseconds: i.timeout,
|
|
478
|
+
message: `Task timed out after ${i.timeout}ms (queue has ${n(this, A)} running, ${n(this, S).size} waiting)`
|
|
479
|
+
})), i.signal) {
|
|
480
|
+
const { signal: d } = i;
|
|
481
|
+
o = Promise.race([o, new Promise((f, g) => {
|
|
482
|
+
u = () => {
|
|
483
|
+
g(d.reason);
|
|
484
|
+
}, d.addEventListener("abort", u, { once: !0 });
|
|
485
|
+
})]);
|
|
486
|
+
}
|
|
487
|
+
const l = await o;
|
|
488
|
+
s(l), this.emit("completed", l);
|
|
489
|
+
} catch (o) {
|
|
490
|
+
a(o), this.emit("error", o);
|
|
521
491
|
} finally {
|
|
522
|
-
|
|
492
|
+
u && i.signal?.removeEventListener("abort", u), n(this, B).delete(c), queueMicrotask(() => {
|
|
493
|
+
m(this, h, Le).call(this);
|
|
494
|
+
});
|
|
523
495
|
}
|
|
524
|
-
}, i), this.emit("add"),
|
|
496
|
+
}, i), this.emit("add"), m(this, h, le).call(this);
|
|
525
497
|
});
|
|
526
498
|
}
|
|
527
499
|
async addAll(t, i) {
|
|
528
|
-
return Promise.all(t.map(async (
|
|
500
|
+
return Promise.all(t.map(async (s) => this.add(s, i)));
|
|
529
501
|
}
|
|
530
502
|
/**
|
|
531
503
|
Start (or resume) executing enqueued tasks within concurrency limit. No need to call this if queue is not paused (via `options.autoStart = false` or by `.pause()` method.)
|
|
532
504
|
*/
|
|
533
505
|
start() {
|
|
534
|
-
return
|
|
506
|
+
return n(this, q) ? (w(this, q, !1), m(this, h, de).call(this), this) : this;
|
|
535
507
|
}
|
|
536
508
|
/**
|
|
537
509
|
Put queue execution on hold.
|
|
538
510
|
*/
|
|
539
511
|
pause() {
|
|
540
|
-
|
|
512
|
+
w(this, q, !0);
|
|
541
513
|
}
|
|
542
514
|
/**
|
|
543
515
|
Clear the queue.
|
|
544
516
|
*/
|
|
545
517
|
clear() {
|
|
546
|
-
|
|
518
|
+
w(this, S, new (n(this, se))()), m(this, h, he).call(this), m(this, h, ve).call(this), this.emit("empty"), n(this, A) === 0 && (m(this, h, ge).call(this), this.emit("idle")), this.emit("next");
|
|
547
519
|
}
|
|
548
520
|
/**
|
|
549
521
|
Can be called multiple times. Useful if you for example add additional items at a later time.
|
|
@@ -551,7 +523,7 @@ class Qe extends Ye {
|
|
|
551
523
|
@returns A promise that settles when the queue becomes empty.
|
|
552
524
|
*/
|
|
553
525
|
async onEmpty() {
|
|
554
|
-
|
|
526
|
+
n(this, S).size !== 0 && await m(this, h, J).call(this, "empty");
|
|
555
527
|
}
|
|
556
528
|
/**
|
|
557
529
|
@returns A promise that settles when the queue size is less than the given limit: `queue.size < limit`.
|
|
@@ -561,7 +533,7 @@ class Qe extends Ye {
|
|
|
561
533
|
Note that this only limits the number of items waiting to start. There could still be up to `concurrency` jobs already running that this call does not include in its calculation.
|
|
562
534
|
*/
|
|
563
535
|
async onSizeLessThan(t) {
|
|
564
|
-
|
|
536
|
+
n(this, S).size < t || await m(this, h, J).call(this, "next", () => n(this, S).size < t);
|
|
565
537
|
}
|
|
566
538
|
/**
|
|
567
539
|
The difference with `.onEmpty` is that `.onIdle` guarantees that all work from the queue has finished. `.onEmpty` merely signals that the queue is empty, but it could mean that some promises haven't completed yet.
|
|
@@ -569,13 +541,71 @@ class Qe extends Ye {
|
|
|
569
541
|
@returns A promise that settles when the queue becomes empty, and all promises have completed; `queue.size === 0 && queue.pending === 0`.
|
|
570
542
|
*/
|
|
571
543
|
async onIdle() {
|
|
572
|
-
|
|
544
|
+
n(this, A) === 0 && n(this, S).size === 0 || await m(this, h, J).call(this, "idle");
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
The difference with `.onIdle` is that `.onPendingZero` only waits for currently running tasks to finish, ignoring queued tasks.
|
|
548
|
+
|
|
549
|
+
@returns A promise that settles when all currently running tasks have completed; `queue.pending === 0`.
|
|
550
|
+
*/
|
|
551
|
+
async onPendingZero() {
|
|
552
|
+
n(this, A) !== 0 && await m(this, h, J).call(this, "pendingZero");
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
@returns A promise that settles when the queue becomes rate-limited due to intervalCap.
|
|
556
|
+
*/
|
|
557
|
+
async onRateLimit() {
|
|
558
|
+
this.isRateLimited || await m(this, h, J).call(this, "rateLimit");
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
@returns A promise that settles when the queue is no longer rate-limited.
|
|
562
|
+
*/
|
|
563
|
+
async onRateLimitCleared() {
|
|
564
|
+
this.isRateLimited && await m(this, h, J).call(this, "rateLimitCleared");
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
567
|
+
@returns A promise that rejects when any task in the queue errors.
|
|
568
|
+
|
|
569
|
+
Use with `Promise.race([queue.onError(), queue.onIdle()])` to fail fast on the first error while still resolving normally when the queue goes idle.
|
|
570
|
+
|
|
571
|
+
Important: The promise returned by `add()` still rejects. You must handle each `add()` promise (for example, `.catch(() => {})`) to avoid unhandled rejections.
|
|
572
|
+
|
|
573
|
+
@example
|
|
574
|
+
```
|
|
575
|
+
import PQueue from 'p-queue';
|
|
576
|
+
|
|
577
|
+
const queue = new PQueue({concurrency: 2});
|
|
578
|
+
|
|
579
|
+
queue.add(() => fetchData(1)).catch(() => {});
|
|
580
|
+
queue.add(() => fetchData(2)).catch(() => {});
|
|
581
|
+
queue.add(() => fetchData(3)).catch(() => {});
|
|
582
|
+
|
|
583
|
+
// Stop processing on first error
|
|
584
|
+
try {
|
|
585
|
+
await Promise.race([
|
|
586
|
+
queue.onError(),
|
|
587
|
+
queue.onIdle()
|
|
588
|
+
]);
|
|
589
|
+
} catch (error) {
|
|
590
|
+
queue.pause(); // Stop processing remaining tasks
|
|
591
|
+
console.error('Queue failed:', error);
|
|
592
|
+
}
|
|
593
|
+
```
|
|
594
|
+
*/
|
|
595
|
+
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
596
|
+
onError() {
|
|
597
|
+
return new Promise((t, i) => {
|
|
598
|
+
const s = (a) => {
|
|
599
|
+
this.off("error", s), i(a);
|
|
600
|
+
};
|
|
601
|
+
this.on("error", s);
|
|
602
|
+
});
|
|
573
603
|
}
|
|
574
604
|
/**
|
|
575
605
|
Size of the queue, the number of queued items waiting to run.
|
|
576
606
|
*/
|
|
577
607
|
get size() {
|
|
578
|
-
return
|
|
608
|
+
return n(this, S).size;
|
|
579
609
|
}
|
|
580
610
|
/**
|
|
581
611
|
Size of the queue, filtered by the given options.
|
|
@@ -583,88 +613,223 @@ class Qe extends Ye {
|
|
|
583
613
|
For example, this can be used to find the number of items remaining in the queue with a specific priority level.
|
|
584
614
|
*/
|
|
585
615
|
sizeBy(t) {
|
|
586
|
-
return
|
|
616
|
+
return n(this, S).filter(t).length;
|
|
587
617
|
}
|
|
588
618
|
/**
|
|
589
619
|
Number of running items (no longer in the queue).
|
|
590
620
|
*/
|
|
591
621
|
get pending() {
|
|
592
|
-
return
|
|
622
|
+
return n(this, A);
|
|
593
623
|
}
|
|
594
624
|
/**
|
|
595
625
|
Whether the queue is currently paused.
|
|
596
626
|
*/
|
|
597
627
|
get isPaused() {
|
|
598
|
-
return
|
|
628
|
+
return n(this, q);
|
|
629
|
+
}
|
|
630
|
+
/**
|
|
631
|
+
Whether the queue is currently rate-limited due to intervalCap.
|
|
632
|
+
*/
|
|
633
|
+
get isRateLimited() {
|
|
634
|
+
return n(this, j);
|
|
635
|
+
}
|
|
636
|
+
/**
|
|
637
|
+
Whether the queue is saturated. Returns `true` when:
|
|
638
|
+
- All concurrency slots are occupied and tasks are waiting, OR
|
|
639
|
+
- The queue is rate-limited and tasks are waiting
|
|
640
|
+
|
|
641
|
+
Useful for detecting backpressure and potential hanging tasks.
|
|
642
|
+
|
|
643
|
+
```js
|
|
644
|
+
import PQueue from 'p-queue';
|
|
645
|
+
|
|
646
|
+
const queue = new PQueue({concurrency: 2});
|
|
647
|
+
|
|
648
|
+
// Backpressure handling
|
|
649
|
+
if (queue.isSaturated) {
|
|
650
|
+
console.log('Queue is saturated, waiting for capacity...');
|
|
651
|
+
await queue.onSizeLessThan(queue.concurrency);
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
// Monitoring for stuck tasks
|
|
655
|
+
setInterval(() => {
|
|
656
|
+
if (queue.isSaturated) {
|
|
657
|
+
console.warn(`Queue saturated: ${queue.pending} running, ${queue.size} waiting`);
|
|
658
|
+
}
|
|
659
|
+
}, 60000);
|
|
660
|
+
```
|
|
661
|
+
*/
|
|
662
|
+
get isSaturated() {
|
|
663
|
+
return n(this, A) === n(this, W) && n(this, S).size > 0 || this.isRateLimited && n(this, S).size > 0;
|
|
664
|
+
}
|
|
665
|
+
/**
|
|
666
|
+
The tasks currently being executed. Each task includes its `id`, `priority`, `startTime`, and `timeout` (if set).
|
|
667
|
+
|
|
668
|
+
Returns an array of task info objects.
|
|
669
|
+
|
|
670
|
+
```js
|
|
671
|
+
import PQueue from 'p-queue';
|
|
672
|
+
|
|
673
|
+
const queue = new PQueue({concurrency: 2});
|
|
674
|
+
|
|
675
|
+
// Add tasks with IDs for better debugging
|
|
676
|
+
queue.add(() => fetchUser(123), {id: 'user-123'});
|
|
677
|
+
queue.add(() => fetchPosts(456), {id: 'posts-456', priority: 1});
|
|
678
|
+
|
|
679
|
+
// Check what's running
|
|
680
|
+
console.log(queue.runningTasks);
|
|
681
|
+
// => [{
|
|
682
|
+
// id: 'user-123',
|
|
683
|
+
// priority: 0,
|
|
684
|
+
// startTime: 1759253001716,
|
|
685
|
+
// timeout: undefined
|
|
686
|
+
// }, {
|
|
687
|
+
// id: 'posts-456',
|
|
688
|
+
// priority: 1,
|
|
689
|
+
// startTime: 1759253001916,
|
|
690
|
+
// timeout: undefined
|
|
691
|
+
// }]
|
|
692
|
+
```
|
|
693
|
+
*/
|
|
694
|
+
get runningTasks() {
|
|
695
|
+
return [...n(this, B).values()].map((t) => ({ ...t }));
|
|
599
696
|
}
|
|
600
697
|
}
|
|
601
|
-
k = new WeakMap(),
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
H(this, O)._--, S(this, m, K).call(this), this.emit("next");
|
|
607
|
-
}, Re = function() {
|
|
608
|
-
S(this, m, ae).call(this), S(this, m, oe).call(this), v(this, q, void 0);
|
|
609
|
-
}, be = function() {
|
|
610
|
-
const t = Date.now();
|
|
611
|
-
if (l(this, N) === void 0) {
|
|
612
|
-
const i = l(this, W) - t;
|
|
613
|
-
if (i < 0)
|
|
614
|
-
v(this, x, l(this, k) ? l(this, O) : 0);
|
|
698
|
+
Z = new WeakMap(), x = new WeakMap(), k = new WeakMap(), Y = new WeakMap(), j = new WeakMap(), X = new WeakMap(), U = new WeakMap(), ie = new WeakMap(), ee = new WeakMap(), D = new WeakMap(), M = new WeakMap(), P = new WeakMap(), I = new WeakMap(), N = new WeakMap(), S = new WeakMap(), se = new WeakMap(), A = new WeakMap(), W = new WeakMap(), q = new WeakMap(), fe = new WeakMap(), B = new WeakMap(), h = new WeakSet(), oe = function(t) {
|
|
699
|
+
for (; n(this, N) < n(this, I).length; ) {
|
|
700
|
+
const s = n(this, I)[n(this, N)];
|
|
701
|
+
if (s !== void 0 && t - s >= n(this, U))
|
|
702
|
+
H(this, N)._++;
|
|
615
703
|
else
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
704
|
+
break;
|
|
705
|
+
}
|
|
706
|
+
(n(this, N) > 100 && n(this, N) > n(this, I).length / 2 || n(this, N) === n(this, I).length) && (w(this, I, n(this, I).slice(n(this, N))), w(this, N, 0));
|
|
707
|
+
}, // Helper methods for interval consumption
|
|
708
|
+
Ne = function(t) {
|
|
709
|
+
n(this, P) ? n(this, I).push(t) : H(this, k)._++;
|
|
710
|
+
}, Ie = function() {
|
|
711
|
+
n(this, P) ? n(this, I).length > n(this, N) && n(this, I).pop() : n(this, k) > 0 && H(this, k)._--;
|
|
712
|
+
}, ue = function() {
|
|
713
|
+
return n(this, I).length - n(this, N);
|
|
714
|
+
}, Oe = function() {
|
|
715
|
+
return n(this, x) ? !0 : n(this, P) ? m(this, h, ue).call(this) < n(this, Y) : n(this, k) < n(this, Y);
|
|
716
|
+
}, Ce = function() {
|
|
717
|
+
return n(this, A) < n(this, W);
|
|
718
|
+
}, Le = function() {
|
|
719
|
+
H(this, A)._--, n(this, A) === 0 && this.emit("pendingZero"), m(this, h, le).call(this), this.emit("next");
|
|
720
|
+
}, Pe = function() {
|
|
721
|
+
w(this, M, void 0), m(this, h, ye).call(this), m(this, h, we).call(this);
|
|
722
|
+
}, xe = function(t) {
|
|
723
|
+
if (n(this, P)) {
|
|
724
|
+
if (m(this, h, oe).call(this, t), m(this, h, ue).call(this) >= n(this, Y)) {
|
|
725
|
+
const s = n(this, I)[n(this, N)], a = n(this, U) - (t - s);
|
|
726
|
+
return m(this, h, ce).call(this, a), !0;
|
|
727
|
+
}
|
|
728
|
+
return !1;
|
|
729
|
+
}
|
|
730
|
+
if (n(this, D) === void 0) {
|
|
731
|
+
const i = n(this, ie) - t;
|
|
732
|
+
if (i < 0) {
|
|
733
|
+
if (n(this, ee) > 0) {
|
|
734
|
+
const s = t - n(this, ee);
|
|
735
|
+
if (s < n(this, U))
|
|
736
|
+
return m(this, h, ce).call(this, n(this, U) - s), !0;
|
|
737
|
+
}
|
|
738
|
+
w(this, k, n(this, Z) ? n(this, A) : 0);
|
|
739
|
+
} else
|
|
740
|
+
return m(this, h, ce).call(this, i), !0;
|
|
619
741
|
}
|
|
620
742
|
return !1;
|
|
621
|
-
},
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
743
|
+
}, ce = function(t) {
|
|
744
|
+
n(this, M) === void 0 && w(this, M, setTimeout(() => {
|
|
745
|
+
m(this, h, Pe).call(this);
|
|
746
|
+
}, t));
|
|
747
|
+
}, he = function() {
|
|
748
|
+
n(this, D) && (clearInterval(n(this, D)), w(this, D, void 0));
|
|
749
|
+
}, ge = function() {
|
|
750
|
+
n(this, M) && (clearTimeout(n(this, M)), w(this, M, void 0));
|
|
751
|
+
}, le = function() {
|
|
752
|
+
if (n(this, S).size === 0) {
|
|
753
|
+
if (m(this, h, he).call(this), this.emit("empty"), n(this, A) === 0) {
|
|
754
|
+
if (m(this, h, ge).call(this), n(this, P) && n(this, N) > 0) {
|
|
755
|
+
const i = Date.now();
|
|
756
|
+
m(this, h, oe).call(this, i);
|
|
757
|
+
}
|
|
758
|
+
this.emit("idle");
|
|
759
|
+
}
|
|
760
|
+
return !1;
|
|
761
|
+
}
|
|
762
|
+
let t = !1;
|
|
763
|
+
if (!n(this, q)) {
|
|
764
|
+
const i = Date.now(), s = !m(this, h, xe).call(this, i);
|
|
765
|
+
if (n(this, h, Oe) && n(this, h, Ce)) {
|
|
766
|
+
const a = n(this, S).dequeue();
|
|
767
|
+
n(this, x) || (m(this, h, Ne).call(this, i), m(this, h, Q).call(this)), this.emit("active"), a(), s && m(this, h, we).call(this), t = !0;
|
|
629
768
|
}
|
|
630
769
|
}
|
|
631
|
-
return
|
|
632
|
-
},
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
},
|
|
636
|
-
},
|
|
637
|
-
|
|
770
|
+
return t;
|
|
771
|
+
}, we = function() {
|
|
772
|
+
n(this, x) || n(this, D) !== void 0 || n(this, P) || (w(this, D, setInterval(() => {
|
|
773
|
+
m(this, h, ye).call(this);
|
|
774
|
+
}, n(this, U))), w(this, ie, Date.now() + n(this, U)));
|
|
775
|
+
}, ye = function() {
|
|
776
|
+
n(this, P) || (n(this, k) === 0 && n(this, A) === 0 && n(this, D) && m(this, h, he).call(this), w(this, k, n(this, Z) ? n(this, A) : 0)), m(this, h, de).call(this), m(this, h, Q).call(this);
|
|
638
777
|
}, /**
|
|
639
778
|
Executes all queued functions until it reaches the limit.
|
|
640
779
|
*/
|
|
641
|
-
|
|
642
|
-
for (;
|
|
780
|
+
de = function() {
|
|
781
|
+
for (; m(this, h, le).call(this); )
|
|
643
782
|
;
|
|
644
|
-
},
|
|
645
|
-
return new Promise((
|
|
646
|
-
t.addEventListener("abort", () => {
|
|
647
|
-
n(t.reason);
|
|
648
|
-
}, { once: !0 });
|
|
649
|
-
});
|
|
650
|
-
}, Z = async function(t, i) {
|
|
651
|
-
return new Promise((n) => {
|
|
783
|
+
}, J = async function(t, i) {
|
|
784
|
+
return new Promise((s) => {
|
|
652
785
|
const a = () => {
|
|
653
|
-
i && !i() || (this.off(t, a),
|
|
786
|
+
i && !i() || (this.off(t, a), s());
|
|
654
787
|
};
|
|
655
788
|
this.on(t, a);
|
|
656
789
|
});
|
|
790
|
+
}, ke = function() {
|
|
791
|
+
n(this, x) || (this.on("add", () => {
|
|
792
|
+
n(this, S).size > 0 && m(this, h, Q).call(this);
|
|
793
|
+
}), this.on("next", () => {
|
|
794
|
+
m(this, h, Q).call(this);
|
|
795
|
+
}));
|
|
796
|
+
}, Q = function() {
|
|
797
|
+
n(this, x) || n(this, X) || (w(this, X, !0), queueMicrotask(() => {
|
|
798
|
+
w(this, X, !1), m(this, h, ve).call(this);
|
|
799
|
+
}));
|
|
800
|
+
}, Ge = function() {
|
|
801
|
+
n(this, x) || (m(this, h, Ie).call(this), m(this, h, Q).call(this));
|
|
802
|
+
}, ve = function() {
|
|
803
|
+
const t = n(this, j);
|
|
804
|
+
if (n(this, x) || n(this, S).size === 0) {
|
|
805
|
+
t && (w(this, j, !1), this.emit("rateLimitCleared"));
|
|
806
|
+
return;
|
|
807
|
+
}
|
|
808
|
+
let i;
|
|
809
|
+
if (n(this, P)) {
|
|
810
|
+
const a = Date.now();
|
|
811
|
+
m(this, h, oe).call(this, a), i = m(this, h, ue).call(this);
|
|
812
|
+
} else
|
|
813
|
+
i = n(this, k);
|
|
814
|
+
const s = i >= n(this, Y);
|
|
815
|
+
s !== t && (w(this, j, s), this.emit(s ? "rateLimit" : "rateLimitCleared"));
|
|
657
816
|
};
|
|
658
|
-
var
|
|
659
|
-
class
|
|
660
|
-
constructor(
|
|
661
|
-
super(
|
|
817
|
+
var Fe = /* @__PURE__ */ ((r) => (r.API_ERROR = "ApiError", r.NETWORK_ERROR = "NetworkError", r.VALIDATION_ERROR = "ValidationError", r.GEOCODING_ERROR = "GeocodingError", r.RATE_LIMIT_ERROR = "RateLimitError", r.TIMEOUT_ERROR = "TimeoutError", r.AUTHENTICATION_ERROR = "AuthenticationError", r.SERVER_ERROR = "ServerError", r.CLIENT_ERROR = "ClientError", r.CONFIGURATION_ERROR = "ConfigurationError", r))(Fe || {});
|
|
818
|
+
class C extends Error {
|
|
819
|
+
constructor(t, i, s = {}) {
|
|
820
|
+
super(i);
|
|
821
|
+
R(this, "type");
|
|
822
|
+
R(this, "statusCode");
|
|
823
|
+
R(this, "response");
|
|
824
|
+
R(this, "originalError");
|
|
825
|
+
R(this, "context");
|
|
826
|
+
this.name = "BmltQueryError", this.type = t, this.statusCode = s.statusCode, this.response = s.response, this.originalError = s.originalError, this.context = s.context, Object.setPrototypeOf(this, C.prototype);
|
|
662
827
|
}
|
|
663
828
|
/**
|
|
664
829
|
* Check if error is of a specific type
|
|
665
830
|
*/
|
|
666
|
-
isType(
|
|
667
|
-
return this.type ===
|
|
831
|
+
isType(t) {
|
|
832
|
+
return this.type === t;
|
|
668
833
|
}
|
|
669
834
|
/**
|
|
670
835
|
* Check if error is retryable
|
|
@@ -737,62 +902,62 @@ class b extends Error {
|
|
|
737
902
|
};
|
|
738
903
|
}
|
|
739
904
|
}
|
|
740
|
-
class
|
|
741
|
-
static createApiError(e, t, i,
|
|
905
|
+
class G {
|
|
906
|
+
static createApiError(e, t, i, s) {
|
|
742
907
|
let a;
|
|
743
|
-
return t ? t >= 500 ? a = "ServerError" : t === 401 || t === 403 ? a = "AuthenticationError" : t === 429 ? a = "RateLimitError" : t >= 400 ? a = "ClientError" : a = "ApiError" : a = "ApiError", new
|
|
908
|
+
return t ? t >= 500 ? a = "ServerError" : t === 401 || t === 403 ? a = "AuthenticationError" : t === 429 ? a = "RateLimitError" : t >= 400 ? a = "ClientError" : a = "ApiError" : a = "ApiError", new C(a, e, {
|
|
744
909
|
statusCode: t,
|
|
745
910
|
response: i,
|
|
746
|
-
originalError:
|
|
911
|
+
originalError: s
|
|
747
912
|
});
|
|
748
913
|
}
|
|
749
914
|
static createNetworkError(e, t) {
|
|
750
|
-
return new
|
|
915
|
+
return new C("NetworkError", e, {
|
|
751
916
|
originalError: t
|
|
752
917
|
});
|
|
753
918
|
}
|
|
754
919
|
static createTimeoutError(e, t) {
|
|
755
|
-
return new
|
|
920
|
+
return new C("TimeoutError", e, {
|
|
756
921
|
originalError: t
|
|
757
922
|
});
|
|
758
923
|
}
|
|
759
924
|
static createValidationError(e, t) {
|
|
760
|
-
return new
|
|
925
|
+
return new C("ValidationError", e, {
|
|
761
926
|
context: t
|
|
762
927
|
});
|
|
763
928
|
}
|
|
764
929
|
static createGeocodingError(e, t, i) {
|
|
765
|
-
return new
|
|
930
|
+
return new C("GeocodingError", e, {
|
|
766
931
|
originalError: t,
|
|
767
932
|
context: i
|
|
768
933
|
});
|
|
769
934
|
}
|
|
770
935
|
static createRateLimitError(e, t, i) {
|
|
771
|
-
return new
|
|
936
|
+
return new C("RateLimitError", e, {
|
|
772
937
|
statusCode: t,
|
|
773
938
|
response: i
|
|
774
939
|
});
|
|
775
940
|
}
|
|
776
941
|
static createConfigurationError(e, t) {
|
|
777
|
-
return new
|
|
942
|
+
return new C("ConfigurationError", e, {
|
|
778
943
|
context: t
|
|
779
944
|
});
|
|
780
945
|
}
|
|
781
946
|
}
|
|
782
|
-
class
|
|
947
|
+
class re {
|
|
783
948
|
/**
|
|
784
949
|
* Handle and transform fetch errors
|
|
785
950
|
*/
|
|
786
951
|
static handleFetchError(e, t) {
|
|
787
952
|
if (e instanceof Error && e.name === "AbortError")
|
|
788
|
-
return
|
|
953
|
+
return G.createTimeoutError("Request timeout", e);
|
|
789
954
|
if (e instanceof TypeError)
|
|
790
|
-
return
|
|
955
|
+
return G.createNetworkError("Network connection failed", e);
|
|
791
956
|
if (t && !t.ok) {
|
|
792
957
|
const i = `HTTP ${t.status}: ${t.statusText}`;
|
|
793
|
-
return
|
|
958
|
+
return G.createApiError(i, t.status, void 0, e);
|
|
794
959
|
}
|
|
795
|
-
return e instanceof Error ?
|
|
960
|
+
return e instanceof Error ? G.createApiError(e.message, void 0, void 0, e) : G.createApiError(
|
|
796
961
|
"Unknown error occurred",
|
|
797
962
|
void 0,
|
|
798
963
|
void 0,
|
|
@@ -803,18 +968,18 @@ class J {
|
|
|
803
968
|
* @deprecated Use handleFetchError instead
|
|
804
969
|
*/
|
|
805
970
|
static handleAxiosError(e) {
|
|
806
|
-
return
|
|
971
|
+
return re.handleFetchError(e);
|
|
807
972
|
}
|
|
808
973
|
/**
|
|
809
974
|
* Handle validation errors with detailed context
|
|
810
975
|
*/
|
|
811
|
-
static handleValidationError(e, t, i,
|
|
976
|
+
static handleValidationError(e, t, i, s) {
|
|
812
977
|
let a = `Invalid ${e}: expected ${i}`;
|
|
813
|
-
return
|
|
978
|
+
return s && s.length > 0 && (a += ` (${s.join(", ")})`), G.createValidationError(a, {
|
|
814
979
|
field: e,
|
|
815
980
|
value: t,
|
|
816
981
|
expectedType: i,
|
|
817
|
-
constraints:
|
|
982
|
+
constraints: s
|
|
818
983
|
});
|
|
819
984
|
}
|
|
820
985
|
/**
|
|
@@ -822,7 +987,7 @@ class J {
|
|
|
822
987
|
*/
|
|
823
988
|
static handleEndpointError(e, t) {
|
|
824
989
|
const i = `Invalid endpoint/format combination: ${e} with ${t}`;
|
|
825
|
-
return
|
|
990
|
+
return G.createValidationError(i, {
|
|
826
991
|
endpoint: e,
|
|
827
992
|
format: t
|
|
828
993
|
});
|
|
@@ -832,7 +997,7 @@ class J {
|
|
|
832
997
|
*/
|
|
833
998
|
static handleUrlError(e, t) {
|
|
834
999
|
const i = `Invalid URL: ${t}`;
|
|
835
|
-
return
|
|
1000
|
+
return G.createValidationError(i, {
|
|
836
1001
|
url: e,
|
|
837
1002
|
reason: t
|
|
838
1003
|
});
|
|
@@ -841,8 +1006,8 @@ class J {
|
|
|
841
1006
|
* Handle coordinate validation errors
|
|
842
1007
|
*/
|
|
843
1008
|
static handleCoordinateError(e, t, i) {
|
|
844
|
-
const
|
|
845
|
-
return
|
|
1009
|
+
const s = i || "Invalid coordinates provided";
|
|
1010
|
+
return G.createValidationError(s, {
|
|
846
1011
|
latitude: e,
|
|
847
1012
|
longitude: t,
|
|
848
1013
|
reason: i
|
|
@@ -852,8 +1017,8 @@ class J {
|
|
|
852
1017
|
* Wrap and enhance existing errors
|
|
853
1018
|
*/
|
|
854
1019
|
static wrapError(e, t, i) {
|
|
855
|
-
const
|
|
856
|
-
return e instanceof
|
|
1020
|
+
const s = `${t}: ${e.message}`;
|
|
1021
|
+
return e instanceof C ? new C(e.type, s, {
|
|
857
1022
|
statusCode: e.statusCode,
|
|
858
1023
|
response: e.response,
|
|
859
1024
|
originalError: e.originalError || e,
|
|
@@ -861,93 +1026,96 @@ class J {
|
|
|
861
1026
|
...e.context,
|
|
862
1027
|
...i
|
|
863
1028
|
}
|
|
864
|
-
}) :
|
|
1029
|
+
}) : G.createApiError(s, void 0, void 0, e);
|
|
865
1030
|
}
|
|
866
1031
|
}
|
|
867
|
-
class
|
|
1032
|
+
class ct {
|
|
868
1033
|
static async withRetry(e, t) {
|
|
869
|
-
const { maxRetries: i, baseDelay:
|
|
870
|
-
let
|
|
871
|
-
for (let
|
|
1034
|
+
const { maxRetries: i, baseDelay: s, maxDelay: a, factor: c, onRetry: u } = t;
|
|
1035
|
+
let o;
|
|
1036
|
+
for (let l = 0; l <= i; l++)
|
|
872
1037
|
try {
|
|
873
1038
|
return await e();
|
|
874
|
-
} catch (
|
|
875
|
-
const f =
|
|
876
|
-
if (
|
|
1039
|
+
} catch (d) {
|
|
1040
|
+
const f = d instanceof C ? d : re.wrapError(d, "Operation failed");
|
|
1041
|
+
if (o = f, l === i || !f.isRetryable())
|
|
877
1042
|
throw f;
|
|
878
|
-
const
|
|
879
|
-
|
|
1043
|
+
const g = Math.min(s * Math.pow(c, l), a);
|
|
1044
|
+
u && u(f, l + 1), await new Promise((b) => setTimeout(b, g));
|
|
880
1045
|
}
|
|
881
|
-
throw
|
|
1046
|
+
throw o;
|
|
882
1047
|
}
|
|
883
1048
|
}
|
|
884
|
-
class
|
|
1049
|
+
class rt {
|
|
885
1050
|
constructor(e = {}) {
|
|
1051
|
+
R(this, "baseURL");
|
|
1052
|
+
R(this, "queue");
|
|
1053
|
+
R(this, "defaultOptions");
|
|
886
1054
|
const {
|
|
887
1055
|
retryCount: t = 3,
|
|
888
1056
|
timeout: i = 1e4,
|
|
889
|
-
userAgent:
|
|
1057
|
+
userAgent: s = "bmlt-query-client/1.0.0",
|
|
890
1058
|
countryCode: a = "us",
|
|
891
|
-
viewbox:
|
|
892
|
-
bounded:
|
|
893
|
-
intervalCap:
|
|
894
|
-
interval:
|
|
1059
|
+
viewbox: c,
|
|
1060
|
+
bounded: u = !1,
|
|
1061
|
+
intervalCap: o = 1,
|
|
1062
|
+
interval: l = 1e3,
|
|
895
1063
|
// 1 second between requests
|
|
896
|
-
concurrency:
|
|
1064
|
+
concurrency: d = 1,
|
|
897
1065
|
carryoverConcurrencyCount: f = !1,
|
|
898
|
-
...
|
|
1066
|
+
...g
|
|
899
1067
|
} = e;
|
|
900
1068
|
this.defaultOptions = {
|
|
901
1069
|
retryCount: t,
|
|
902
1070
|
timeout: i,
|
|
903
|
-
userAgent:
|
|
1071
|
+
userAgent: s,
|
|
904
1072
|
countryCode: a,
|
|
905
|
-
viewbox:
|
|
906
|
-
bounded:
|
|
907
|
-
}, this.baseURL = "https://nominatim.openstreetmap.org", this.queue = new
|
|
908
|
-
intervalCap:
|
|
909
|
-
interval:
|
|
910
|
-
concurrency:
|
|
1073
|
+
viewbox: c,
|
|
1074
|
+
bounded: u
|
|
1075
|
+
}, this.baseURL = "https://nominatim.openstreetmap.org", this.queue = new tt({
|
|
1076
|
+
intervalCap: o,
|
|
1077
|
+
interval: l,
|
|
1078
|
+
concurrency: d,
|
|
911
1079
|
carryoverConcurrencyCount: f,
|
|
912
|
-
...
|
|
1080
|
+
...g
|
|
913
1081
|
});
|
|
914
1082
|
}
|
|
915
1083
|
/**
|
|
916
1084
|
* Make a fetch request with timeout and error handling
|
|
917
1085
|
*/
|
|
918
1086
|
async fetchWithTimeout(e, t, i) {
|
|
919
|
-
const
|
|
1087
|
+
const s = new AbortController(), a = setTimeout(() => s.abort(), t);
|
|
920
1088
|
try {
|
|
921
|
-
const
|
|
1089
|
+
const c = await fetch(e, {
|
|
922
1090
|
method: "GET",
|
|
923
1091
|
headers: {
|
|
924
1092
|
"User-Agent": i
|
|
925
1093
|
},
|
|
926
|
-
signal:
|
|
1094
|
+
signal: s.signal
|
|
927
1095
|
});
|
|
928
|
-
if (!
|
|
929
|
-
if (
|
|
930
|
-
const
|
|
931
|
-
throw
|
|
1096
|
+
if (!c.ok) {
|
|
1097
|
+
if (c.status === 429) {
|
|
1098
|
+
const o = new Error("Rate limit exceeded for geocoding service");
|
|
1099
|
+
throw o.name = "RateLimitError", o.statusCode = 429, o;
|
|
932
1100
|
}
|
|
933
|
-
if (
|
|
934
|
-
const
|
|
935
|
-
`Geocoding service error: ${
|
|
1101
|
+
if (c.status >= 400) {
|
|
1102
|
+
const o = new Error(
|
|
1103
|
+
`Geocoding service error: ${c.status} ${c.statusText}`
|
|
936
1104
|
);
|
|
937
|
-
throw
|
|
1105
|
+
throw o.name = "GeocodingError", o.statusCode = c.status, o;
|
|
938
1106
|
}
|
|
939
1107
|
}
|
|
940
|
-
return await
|
|
941
|
-
} catch (
|
|
942
|
-
if (
|
|
943
|
-
const
|
|
944
|
-
throw
|
|
1108
|
+
return await c.json();
|
|
1109
|
+
} catch (c) {
|
|
1110
|
+
if (c instanceof Error && c.name === "AbortError") {
|
|
1111
|
+
const u = new Error("Request timeout during geocoding");
|
|
1112
|
+
throw u.name = "TimeoutError", u;
|
|
945
1113
|
}
|
|
946
|
-
if (
|
|
947
|
-
const
|
|
948
|
-
throw
|
|
1114
|
+
if (c instanceof TypeError) {
|
|
1115
|
+
const u = new Error("Network error occurred during geocoding");
|
|
1116
|
+
throw u.name = "NetworkError", u;
|
|
949
1117
|
}
|
|
950
|
-
throw
|
|
1118
|
+
throw c;
|
|
951
1119
|
} finally {
|
|
952
1120
|
clearTimeout(a);
|
|
953
1121
|
}
|
|
@@ -957,63 +1125,63 @@ class je {
|
|
|
957
1125
|
*/
|
|
958
1126
|
async geocode(e, t = {}) {
|
|
959
1127
|
const i = { ...this.defaultOptions, ...t };
|
|
960
|
-
return this.queue.add(async () =>
|
|
1128
|
+
return this.queue.add(async () => Se(
|
|
961
1129
|
async () => {
|
|
962
1130
|
try {
|
|
963
|
-
const
|
|
1131
|
+
const s = {
|
|
964
1132
|
q: e,
|
|
965
1133
|
format: "json",
|
|
966
1134
|
addressdetails: 1,
|
|
967
1135
|
limit: 1,
|
|
968
1136
|
dedupe: 1
|
|
969
1137
|
};
|
|
970
|
-
i.countryCode && (
|
|
1138
|
+
i.countryCode && (s.countrycodes = i.countryCode), i.viewbox && (s.viewbox = i.viewbox.join(","), i.bounded && (s.bounded = 1));
|
|
971
1139
|
const a = new URL(`${this.baseURL}/search`);
|
|
972
|
-
Object.entries(
|
|
973
|
-
a.searchParams.append(
|
|
1140
|
+
Object.entries(s).forEach(([l, d]) => {
|
|
1141
|
+
a.searchParams.append(l, String(d));
|
|
974
1142
|
});
|
|
975
|
-
const
|
|
1143
|
+
const c = await this.fetchWithTimeout(
|
|
976
1144
|
a.toString(),
|
|
977
1145
|
i.timeout,
|
|
978
1146
|
i.userAgent
|
|
979
1147
|
);
|
|
980
|
-
if (!
|
|
981
|
-
throw new
|
|
982
|
-
|
|
1148
|
+
if (!c || c.length === 0)
|
|
1149
|
+
throw new C(
|
|
1150
|
+
Fe.GEOCODING_ERROR,
|
|
983
1151
|
`No results found for address: ${e}`
|
|
984
1152
|
);
|
|
985
|
-
const
|
|
986
|
-
latitude: parseFloat(
|
|
987
|
-
longitude: parseFloat(
|
|
1153
|
+
const u = c[0], o = {
|
|
1154
|
+
latitude: parseFloat(u.lat),
|
|
1155
|
+
longitude: parseFloat(u.lon)
|
|
988
1156
|
};
|
|
989
|
-
if (isNaN(
|
|
990
|
-
const
|
|
1157
|
+
if (isNaN(o.latitude) || isNaN(o.longitude)) {
|
|
1158
|
+
const l = new Error(
|
|
991
1159
|
"Invalid coordinates received from geocoding service"
|
|
992
1160
|
);
|
|
993
|
-
throw
|
|
1161
|
+
throw l.name = "GeocodingError", l;
|
|
994
1162
|
}
|
|
995
|
-
if (
|
|
996
|
-
const
|
|
997
|
-
throw
|
|
1163
|
+
if (o.latitude < -90 || o.latitude > 90 || o.longitude < -180 || o.longitude > 180) {
|
|
1164
|
+
const l = new Error("Coordinates out of valid range");
|
|
1165
|
+
throw l.name = "GeocodingError", l;
|
|
998
1166
|
}
|
|
999
1167
|
return {
|
|
1000
|
-
coordinates:
|
|
1001
|
-
display_name:
|
|
1002
|
-
confidence:
|
|
1003
|
-
address:
|
|
1004
|
-
house_number:
|
|
1005
|
-
road:
|
|
1006
|
-
neighbourhood:
|
|
1007
|
-
suburb:
|
|
1008
|
-
city:
|
|
1009
|
-
county:
|
|
1010
|
-
state:
|
|
1011
|
-
postcode:
|
|
1012
|
-
country:
|
|
1168
|
+
coordinates: o,
|
|
1169
|
+
display_name: u.display_name,
|
|
1170
|
+
confidence: u.importance,
|
|
1171
|
+
address: u.address ? {
|
|
1172
|
+
house_number: u.address.house_number,
|
|
1173
|
+
road: u.address.road,
|
|
1174
|
+
neighbourhood: u.address.neighbourhood,
|
|
1175
|
+
suburb: u.address.suburb,
|
|
1176
|
+
city: u.address.city || u.address.town || u.address.village,
|
|
1177
|
+
county: u.address.county,
|
|
1178
|
+
state: u.address.state,
|
|
1179
|
+
postcode: u.address.postcode,
|
|
1180
|
+
country: u.address.country
|
|
1013
1181
|
} : void 0
|
|
1014
1182
|
};
|
|
1015
|
-
} catch (
|
|
1016
|
-
throw
|
|
1183
|
+
} catch (s) {
|
|
1184
|
+
throw s;
|
|
1017
1185
|
}
|
|
1018
1186
|
},
|
|
1019
1187
|
{
|
|
@@ -1021,9 +1189,9 @@ class je {
|
|
|
1021
1189
|
factor: 2,
|
|
1022
1190
|
minTimeout: 1e3,
|
|
1023
1191
|
maxTimeout: 1e4,
|
|
1024
|
-
onFailedAttempt: (
|
|
1192
|
+
onFailedAttempt: (s) => {
|
|
1025
1193
|
console.warn(
|
|
1026
|
-
`Geocoding attempt ${
|
|
1194
|
+
`Geocoding attempt ${s.attemptNumber} failed. ${s.retriesLeft} retries left. Error: ${s.error.message}`
|
|
1027
1195
|
);
|
|
1028
1196
|
}
|
|
1029
1197
|
}
|
|
@@ -1034,7 +1202,7 @@ class je {
|
|
|
1034
1202
|
*/
|
|
1035
1203
|
async batchGeocode(e, t = {}) {
|
|
1036
1204
|
const i = e.map(
|
|
1037
|
-
(a) => this.geocode(a, t).catch((
|
|
1205
|
+
(a) => this.geocode(a, t).catch((c) => (console.warn(`Failed to geocode address "${a}":`, c.message), null))
|
|
1038
1206
|
);
|
|
1039
1207
|
return (await Promise.all(i)).filter((a) => a !== null);
|
|
1040
1208
|
}
|
|
@@ -1043,44 +1211,44 @@ class je {
|
|
|
1043
1211
|
*/
|
|
1044
1212
|
async reverseGeocode(e, t = {}) {
|
|
1045
1213
|
const i = { ...this.defaultOptions, ...t };
|
|
1046
|
-
return this.queue.add(async () =>
|
|
1214
|
+
return this.queue.add(async () => Se(
|
|
1047
1215
|
async () => {
|
|
1048
1216
|
try {
|
|
1049
|
-
const
|
|
1050
|
-
|
|
1217
|
+
const s = new URL(`${this.baseURL}/reverse`);
|
|
1218
|
+
s.searchParams.append("lat", String(e.latitude)), s.searchParams.append("lon", String(e.longitude)), s.searchParams.append("format", "json"), s.searchParams.append("addressdetails", "1");
|
|
1051
1219
|
const a = await this.fetchWithTimeout(
|
|
1052
|
-
|
|
1220
|
+
s.toString(),
|
|
1053
1221
|
i.timeout,
|
|
1054
1222
|
i.userAgent
|
|
1055
1223
|
);
|
|
1056
1224
|
if (!a) {
|
|
1057
|
-
const
|
|
1225
|
+
const u = new Error(
|
|
1058
1226
|
`No results found for coordinates: ${e.latitude}, ${e.longitude}`
|
|
1059
1227
|
);
|
|
1060
|
-
throw
|
|
1228
|
+
throw u.name = "GeocodingError", u;
|
|
1061
1229
|
}
|
|
1062
|
-
const
|
|
1230
|
+
const c = a;
|
|
1063
1231
|
return {
|
|
1064
1232
|
coordinates: {
|
|
1065
|
-
latitude: parseFloat(
|
|
1066
|
-
longitude: parseFloat(
|
|
1233
|
+
latitude: parseFloat(c.lat),
|
|
1234
|
+
longitude: parseFloat(c.lon)
|
|
1067
1235
|
},
|
|
1068
|
-
display_name:
|
|
1069
|
-
confidence:
|
|
1070
|
-
address:
|
|
1071
|
-
house_number:
|
|
1072
|
-
road:
|
|
1073
|
-
neighbourhood:
|
|
1074
|
-
suburb:
|
|
1075
|
-
city:
|
|
1076
|
-
county:
|
|
1077
|
-
state:
|
|
1078
|
-
postcode:
|
|
1079
|
-
country:
|
|
1236
|
+
display_name: c.display_name,
|
|
1237
|
+
confidence: c.importance,
|
|
1238
|
+
address: c.address ? {
|
|
1239
|
+
house_number: c.address.house_number,
|
|
1240
|
+
road: c.address.road,
|
|
1241
|
+
neighbourhood: c.address.neighbourhood,
|
|
1242
|
+
suburb: c.address.suburb,
|
|
1243
|
+
city: c.address.city || c.address.town || c.address.village,
|
|
1244
|
+
county: c.address.county,
|
|
1245
|
+
state: c.address.state,
|
|
1246
|
+
postcode: c.address.postcode,
|
|
1247
|
+
country: c.address.country
|
|
1080
1248
|
} : void 0
|
|
1081
1249
|
};
|
|
1082
|
-
} catch (
|
|
1083
|
-
throw
|
|
1250
|
+
} catch (s) {
|
|
1251
|
+
throw s;
|
|
1084
1252
|
}
|
|
1085
1253
|
},
|
|
1086
1254
|
{
|
|
@@ -1125,78 +1293,79 @@ class je {
|
|
|
1125
1293
|
* Set the user agent string for geocoding requests
|
|
1126
1294
|
*/
|
|
1127
1295
|
setUserAgent(e) {
|
|
1128
|
-
if (!e ||
|
|
1296
|
+
if (!e || e.trim().length === 0)
|
|
1129
1297
|
throw new Error("User agent must be a non-empty string");
|
|
1130
1298
|
this.defaultOptions.userAgent = e.trim();
|
|
1131
1299
|
}
|
|
1132
1300
|
}
|
|
1133
|
-
var
|
|
1134
|
-
function Xe(r) {
|
|
1135
|
-
const { rootServerURL: e, format: t, endpoint: i, parameters: n = {} } = r, s = `${e.endsWith("/") ? e : `${e}/`}client_interface/${t}/`, o = new URLSearchParams();
|
|
1136
|
-
return o.set("switcher", i), Object.entries(n).forEach(([u, c]) => {
|
|
1137
|
-
c != null && (Array.isArray(c) ? c.forEach((h, f) => {
|
|
1138
|
-
(typeof h == "number" || typeof h == "string") && o.append(`${u}[]`, h.toString());
|
|
1139
|
-
}) : typeof c == "boolean" ? o.set(u, c ? "1" : "0") : o.set(u, c.toString()));
|
|
1140
|
-
}), `${s}?${o.toString()}`;
|
|
1141
|
-
}
|
|
1301
|
+
var v = /* @__PURE__ */ ((r) => (r.JSON = "json", r.JSONP = "jsonp", r.TSML = "tsml", r.CSV = "csv", r))(v || {}), _ = /* @__PURE__ */ ((r) => (r.GET_SEARCH_RESULTS = "GetSearchResults", r.GET_FORMATS = "GetFormats", r.GET_SERVICE_BODIES = "GetServiceBodies", r.GET_CHANGES = "GetChanges", r.GET_FIELD_KEYS = "GetFieldKeys", r.GET_FIELD_VALUES = "GetFieldValues", r.GET_NAWS_DUMP = "GetNAWSDump", r.GET_SERVER_INFO = "GetServerInfo", r.GET_COVERAGE_AREA = "GetCoverageArea", r))(_ || {}), $ = /* @__PURE__ */ ((r) => (r[r.SUNDAY = 1] = "SUNDAY", r[r.MONDAY = 2] = "MONDAY", r[r.TUESDAY = 3] = "TUESDAY", r[r.WEDNESDAY = 4] = "WEDNESDAY", r[r.THURSDAY = 5] = "THURSDAY", r[r.FRIDAY = 6] = "FRIDAY", r[r.SATURDAY = 7] = "SATURDAY", r))($ || {}), K = /* @__PURE__ */ ((r) => (r[r.IN_PERSON = 1] = "IN_PERSON", r[r.VIRTUAL = 2] = "VIRTUAL", r[r.HYBRID = 3] = "HYBRID", r))(K || {}), it = /* @__PURE__ */ ((r) => (r.WEEKDAY = "weekday", r.TIME = "time", r.TOWN = "town", r.STATE = "state", r.WEEKDAY_STATE = "weekday_state", r))(it || {}), st = /* @__PURE__ */ ((r) => (r.ENGLISH = "en", r.GERMAN = "de", r.DANISH = "dk", r.SPANISH = "es", r.PERSIAN = "fa", r.FRENCH = "fr", r.ITALIAN = "it", r.POLISH = "pl", r.PORTUGUESE = "pt", r.SWEDISH = "sv", r))(st || {});
|
|
1142
1302
|
function nt(r) {
|
|
1303
|
+
const { rootServerURL: e, format: t, endpoint: i, parameters: s = {} } = r, c = `${e.endsWith("/") ? e : `${e}/`}client_interface/${t}/`, u = new URLSearchParams();
|
|
1304
|
+
return u.set("switcher", i), Object.entries(s).forEach(([o, l]) => {
|
|
1305
|
+
l != null && (Array.isArray(l) ? l.forEach((d, f) => {
|
|
1306
|
+
(typeof d == "number" || typeof d == "string") && u.append(`${o}[]`, d.toString());
|
|
1307
|
+
}) : typeof l == "boolean" ? u.set(o, l ? "1" : "0") : u.set(o, l.toString()));
|
|
1308
|
+
}), `${c}?${u.toString()}`;
|
|
1309
|
+
}
|
|
1310
|
+
function ht(r) {
|
|
1143
1311
|
const e = {};
|
|
1144
1312
|
return Object.entries(r).forEach(([t, i]) => {
|
|
1145
1313
|
if (i != null)
|
|
1146
1314
|
if (Array.isArray(i))
|
|
1147
|
-
e[t] = i.map((
|
|
1148
|
-
if (typeof
|
|
1149
|
-
return
|
|
1150
|
-
if (typeof
|
|
1151
|
-
const a = parseFloat(
|
|
1152
|
-
return isNaN(a) ?
|
|
1315
|
+
e[t] = i.map((s) => {
|
|
1316
|
+
if (typeof s == "number")
|
|
1317
|
+
return s;
|
|
1318
|
+
if (typeof s == "string") {
|
|
1319
|
+
const a = parseFloat(s);
|
|
1320
|
+
return isNaN(a) ? s : a;
|
|
1153
1321
|
}
|
|
1154
|
-
return
|
|
1322
|
+
return s;
|
|
1155
1323
|
});
|
|
1156
1324
|
else if (typeof i == "boolean")
|
|
1157
1325
|
e[t] = i;
|
|
1158
1326
|
else if (typeof i == "string") {
|
|
1159
|
-
const
|
|
1160
|
-
!isNaN(
|
|
1327
|
+
const s = parseFloat(i);
|
|
1328
|
+
!isNaN(s) && isFinite(s) ? e[t] = s : e[t] = i;
|
|
1161
1329
|
} else
|
|
1162
1330
|
e[t] = i;
|
|
1163
1331
|
}), e;
|
|
1164
1332
|
}
|
|
1165
|
-
function
|
|
1333
|
+
function at(r, e) {
|
|
1166
1334
|
const i = {
|
|
1167
1335
|
[_.GET_SEARCH_RESULTS]: [
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1336
|
+
v.JSON,
|
|
1337
|
+
v.JSONP,
|
|
1338
|
+
v.TSML
|
|
1171
1339
|
],
|
|
1172
|
-
[_.GET_FORMATS]: [
|
|
1173
|
-
[_.GET_SERVICE_BODIES]: [
|
|
1174
|
-
[_.GET_CHANGES]: [
|
|
1175
|
-
[_.GET_FIELD_KEYS]: [
|
|
1176
|
-
[_.GET_FIELD_VALUES]: [
|
|
1177
|
-
[_.GET_NAWS_DUMP]: [
|
|
1178
|
-
[_.GET_SERVER_INFO]: [
|
|
1179
|
-
[_.GET_COVERAGE_AREA]: [
|
|
1340
|
+
[_.GET_FORMATS]: [v.JSON, v.JSONP],
|
|
1341
|
+
[_.GET_SERVICE_BODIES]: [v.JSON, v.JSONP],
|
|
1342
|
+
[_.GET_CHANGES]: [v.JSON, v.JSONP],
|
|
1343
|
+
[_.GET_FIELD_KEYS]: [v.JSON, v.JSONP],
|
|
1344
|
+
[_.GET_FIELD_VALUES]: [v.JSON, v.JSONP],
|
|
1345
|
+
[_.GET_NAWS_DUMP]: [v.CSV],
|
|
1346
|
+
[_.GET_SERVER_INFO]: [v.JSON, v.JSONP],
|
|
1347
|
+
[_.GET_COVERAGE_AREA]: [v.JSON, v.JSONP]
|
|
1180
1348
|
}[r];
|
|
1181
1349
|
if (!i.includes(e))
|
|
1182
1350
|
throw new Error(
|
|
1183
1351
|
`Invalid format '${e}' for endpoint '${r}'. Valid formats: ${i.join(", ")}`
|
|
1184
1352
|
);
|
|
1185
1353
|
}
|
|
1186
|
-
function
|
|
1354
|
+
function Ae(r) {
|
|
1187
1355
|
try {
|
|
1188
1356
|
const e = new URL(r);
|
|
1189
1357
|
if (!["http:", "https:"].includes(e.protocol))
|
|
1190
1358
|
throw new Error("Root server URL must use http or https protocol");
|
|
1191
1359
|
return e.href.replace(/\/$/, "");
|
|
1192
|
-
} catch {
|
|
1193
|
-
|
|
1360
|
+
} catch (e) {
|
|
1361
|
+
const t = new Error(`Invalid root server URL: ${r}`);
|
|
1362
|
+
throw t.cause = e, t;
|
|
1194
1363
|
}
|
|
1195
1364
|
}
|
|
1196
|
-
function
|
|
1365
|
+
function lt(r) {
|
|
1197
1366
|
return typeof r == "number" ? [r] : typeof r == "string" ? r.split(",").map((e) => parseInt(e.trim(), 10)).filter((e) => !isNaN(e)) : Array.isArray(r) ? r.map((e) => typeof e == "number" ? e : parseInt(String(e), 10)).filter((e) => !isNaN(e)) : [];
|
|
1198
1367
|
}
|
|
1199
|
-
function
|
|
1368
|
+
function dt(r, e) {
|
|
1200
1369
|
const t = {};
|
|
1201
1370
|
if (typeof r == "number") {
|
|
1202
1371
|
if (r < 0 || r > 23)
|
|
@@ -1210,7 +1379,7 @@ function ot(r, e) {
|
|
|
1210
1379
|
}
|
|
1211
1380
|
return t;
|
|
1212
1381
|
}
|
|
1213
|
-
function
|
|
1382
|
+
function ot(r, e) {
|
|
1214
1383
|
if (typeof r != "number" || isNaN(r))
|
|
1215
1384
|
throw new Error("Latitude must be a valid number");
|
|
1216
1385
|
if (typeof e != "number" || isNaN(e))
|
|
@@ -1220,71 +1389,76 @@ function et(r, e) {
|
|
|
1220
1389
|
if (e < -180 || e > 180)
|
|
1221
1390
|
throw new Error("Longitude must be between -180 and 180 degrees");
|
|
1222
1391
|
}
|
|
1223
|
-
function
|
|
1392
|
+
function ae(r) {
|
|
1224
1393
|
if (typeof r != "number" || isNaN(r))
|
|
1225
1394
|
throw new Error("Radius must be a valid number");
|
|
1226
1395
|
if (r <= 0)
|
|
1227
1396
|
throw new Error("Radius must be greater than 0");
|
|
1228
1397
|
}
|
|
1229
|
-
function
|
|
1398
|
+
function ft(r) {
|
|
1230
1399
|
return r * 1.60934;
|
|
1231
1400
|
}
|
|
1232
|
-
function
|
|
1401
|
+
function mt(r) {
|
|
1233
1402
|
return r / 1.60934;
|
|
1234
1403
|
}
|
|
1235
|
-
class
|
|
1404
|
+
class Et {
|
|
1236
1405
|
constructor(e) {
|
|
1406
|
+
R(this, "timeout");
|
|
1407
|
+
R(this, "userAgent");
|
|
1408
|
+
R(this, "geocodingService");
|
|
1409
|
+
R(this, "rootServerURL");
|
|
1410
|
+
R(this, "defaultFormat");
|
|
1237
1411
|
const {
|
|
1238
1412
|
rootServerURL: t,
|
|
1239
|
-
defaultFormat: i =
|
|
1240
|
-
timeout:
|
|
1413
|
+
defaultFormat: i = v.JSON,
|
|
1414
|
+
timeout: s = 3e4,
|
|
1241
1415
|
userAgent: a = "bmlt-query-client/1.0.0",
|
|
1242
|
-
geocodingOptions:
|
|
1243
|
-
enableGeocoding:
|
|
1416
|
+
geocodingOptions: c = {},
|
|
1417
|
+
enableGeocoding: u = !0
|
|
1244
1418
|
} = e;
|
|
1245
|
-
this.rootServerURL =
|
|
1419
|
+
this.rootServerURL = Ae(t), this.defaultFormat = i, this.timeout = s, this.userAgent = a, u && (this.geocodingService = new rt(c));
|
|
1246
1420
|
}
|
|
1247
1421
|
/**
|
|
1248
1422
|
* Make a request to the BMLT API
|
|
1249
1423
|
*/
|
|
1250
1424
|
async makeRequest(e, t = {}, i = this.defaultFormat) {
|
|
1251
|
-
let
|
|
1425
|
+
let s;
|
|
1252
1426
|
try {
|
|
1253
|
-
|
|
1254
|
-
const a =
|
|
1427
|
+
at(e, i);
|
|
1428
|
+
const a = nt({
|
|
1255
1429
|
rootServerURL: this.rootServerURL,
|
|
1256
1430
|
format: i,
|
|
1257
1431
|
endpoint: e,
|
|
1258
1432
|
parameters: t
|
|
1259
|
-
}),
|
|
1433
|
+
}), c = new AbortController(), u = setTimeout(() => c.abort(), this.timeout);
|
|
1260
1434
|
try {
|
|
1261
|
-
|
|
1435
|
+
s = await fetch(a, {
|
|
1262
1436
|
method: "GET",
|
|
1263
1437
|
headers: {
|
|
1264
1438
|
"User-Agent": this.userAgent
|
|
1265
1439
|
},
|
|
1266
|
-
signal:
|
|
1440
|
+
signal: c.signal
|
|
1267
1441
|
});
|
|
1268
1442
|
} finally {
|
|
1269
|
-
clearTimeout(
|
|
1443
|
+
clearTimeout(u);
|
|
1270
1444
|
}
|
|
1271
|
-
if (!
|
|
1272
|
-
throw
|
|
1273
|
-
new Error(`HTTP ${
|
|
1274
|
-
|
|
1445
|
+
if (!s.ok)
|
|
1446
|
+
throw re.handleFetchError(
|
|
1447
|
+
new Error(`HTTP ${s.status}: ${s.statusText}`),
|
|
1448
|
+
s
|
|
1275
1449
|
);
|
|
1276
|
-
const
|
|
1277
|
-
if (i ===
|
|
1278
|
-
return
|
|
1279
|
-
if (i ===
|
|
1280
|
-
const
|
|
1281
|
-
if (!
|
|
1450
|
+
const o = await s.text();
|
|
1451
|
+
if (i === v.CSV)
|
|
1452
|
+
return o;
|
|
1453
|
+
if (i === v.JSONP) {
|
|
1454
|
+
const l = t.callback || "callback", d = o.match(new RegExp(`${l}\\((.+)\\);?$`));
|
|
1455
|
+
if (!d)
|
|
1282
1456
|
throw new Error("Invalid JSONP response format");
|
|
1283
|
-
return JSON.parse(
|
|
1457
|
+
return JSON.parse(d[1]);
|
|
1284
1458
|
}
|
|
1285
|
-
return i ===
|
|
1459
|
+
return i === v.JSON || i === v.TSML ? JSON.parse(o) : o;
|
|
1286
1460
|
} catch (a) {
|
|
1287
|
-
throw
|
|
1461
|
+
throw re.handleFetchError(a, s);
|
|
1288
1462
|
}
|
|
1289
1463
|
}
|
|
1290
1464
|
/**
|
|
@@ -1300,26 +1474,26 @@ class ct {
|
|
|
1300
1474
|
async searchMeetingsByAddress(e) {
|
|
1301
1475
|
if (!this.geocodingService)
|
|
1302
1476
|
throw new Error("Geocoding is not enabled. Initialize client with enableGeocoding: true");
|
|
1303
|
-
const { address: t, radiusMiles: i, radiusKm:
|
|
1304
|
-
...
|
|
1305
|
-
lat_val:
|
|
1306
|
-
long_val:
|
|
1477
|
+
const { address: t, radiusMiles: i, radiusKm: s, sortByDistance: a = !0, searchParams: c = {} } = e, u = await this.geocodingService.geocode(t), o = {
|
|
1478
|
+
...c,
|
|
1479
|
+
lat_val: u.coordinates.latitude,
|
|
1480
|
+
long_val: u.coordinates.longitude,
|
|
1307
1481
|
sort_results_by_distance: a
|
|
1308
1482
|
};
|
|
1309
|
-
return i !== void 0 ? (
|
|
1483
|
+
return i !== void 0 ? (ae(i), o.geo_width = i) : s !== void 0 && (ae(s), o.geo_width_km = s), this.searchMeetings(o);
|
|
1310
1484
|
}
|
|
1311
1485
|
/**
|
|
1312
1486
|
* Search for meetings by coordinates
|
|
1313
1487
|
*/
|
|
1314
|
-
async searchMeetingsByCoordinates(e, t, i,
|
|
1315
|
-
|
|
1488
|
+
async searchMeetingsByCoordinates(e, t, i, s = {}) {
|
|
1489
|
+
ot(e.latitude, e.longitude);
|
|
1316
1490
|
const a = {
|
|
1317
|
-
...
|
|
1491
|
+
...s,
|
|
1318
1492
|
lat_val: e.latitude,
|
|
1319
1493
|
long_val: e.longitude,
|
|
1320
1494
|
sort_results_by_distance: !0
|
|
1321
1495
|
};
|
|
1322
|
-
return t !== void 0 ? (
|
|
1496
|
+
return t !== void 0 ? (ae(t), a.geo_width = t) : i !== void 0 && (ae(i), a.geo_width_km = i), this.searchMeetings(a);
|
|
1323
1497
|
}
|
|
1324
1498
|
/**
|
|
1325
1499
|
* Get available meeting formats
|
|
@@ -1359,7 +1533,7 @@ class ct {
|
|
|
1359
1533
|
* Get NAWS dump for a service body (CSV format only)
|
|
1360
1534
|
*/
|
|
1361
1535
|
async getNAWSDump(e) {
|
|
1362
|
-
return this.makeRequest(_.GET_NAWS_DUMP, e,
|
|
1536
|
+
return this.makeRequest(_.GET_NAWS_DUMP, e, v.CSV);
|
|
1363
1537
|
}
|
|
1364
1538
|
/**
|
|
1365
1539
|
* Get server information
|
|
@@ -1399,7 +1573,7 @@ class ct {
|
|
|
1399
1573
|
* Update the root server URL
|
|
1400
1574
|
*/
|
|
1401
1575
|
setRootServerURL(e) {
|
|
1402
|
-
this.rootServerURL =
|
|
1576
|
+
this.rootServerURL = Ae(e);
|
|
1403
1577
|
}
|
|
1404
1578
|
/**
|
|
1405
1579
|
* Get the default data format
|
|
@@ -1438,7 +1612,7 @@ class ct {
|
|
|
1438
1612
|
* Set the user agent string for HTTP requests
|
|
1439
1613
|
*/
|
|
1440
1614
|
setUserAgent(e) {
|
|
1441
|
-
if (!e ||
|
|
1615
|
+
if (!e || e.trim().length === 0)
|
|
1442
1616
|
throw new Error("User agent must be a non-empty string");
|
|
1443
1617
|
this.userAgent = e.trim(), this.geocodingService && this.geocodingService.setUserAgent(this.userAgent);
|
|
1444
1618
|
}
|
|
@@ -1457,9 +1631,11 @@ class ct {
|
|
|
1457
1631
|
this.timeout = e;
|
|
1458
1632
|
}
|
|
1459
1633
|
}
|
|
1460
|
-
class
|
|
1634
|
+
class F {
|
|
1461
1635
|
constructor(e) {
|
|
1462
|
-
this
|
|
1636
|
+
R(this, "params", {});
|
|
1637
|
+
R(this, "client");
|
|
1638
|
+
this.client = e;
|
|
1463
1639
|
}
|
|
1464
1640
|
/**
|
|
1465
1641
|
* Include or exclude specific meeting IDs
|
|
@@ -1490,25 +1666,25 @@ class C {
|
|
|
1490
1666
|
* Include only in-person meetings
|
|
1491
1667
|
*/
|
|
1492
1668
|
inPersonOnly() {
|
|
1493
|
-
return this.venueTypes(
|
|
1669
|
+
return this.venueTypes(K.IN_PERSON);
|
|
1494
1670
|
}
|
|
1495
1671
|
/**
|
|
1496
1672
|
* Include only virtual meetings
|
|
1497
1673
|
*/
|
|
1498
1674
|
virtualOnly() {
|
|
1499
|
-
return this.venueTypes(
|
|
1675
|
+
return this.venueTypes(K.VIRTUAL);
|
|
1500
1676
|
}
|
|
1501
1677
|
/**
|
|
1502
1678
|
* Include only hybrid meetings
|
|
1503
1679
|
*/
|
|
1504
1680
|
hybridOnly() {
|
|
1505
|
-
return this.venueTypes(
|
|
1681
|
+
return this.venueTypes(K.HYBRID);
|
|
1506
1682
|
}
|
|
1507
1683
|
/**
|
|
1508
1684
|
* Include virtual and hybrid meetings
|
|
1509
1685
|
*/
|
|
1510
1686
|
virtualOrHybrid() {
|
|
1511
|
-
return this.venueTypes(
|
|
1687
|
+
return this.venueTypes(K.VIRTUAL, K.HYBRID);
|
|
1512
1688
|
}
|
|
1513
1689
|
/**
|
|
1514
1690
|
* Filter by meeting formats
|
|
@@ -1670,7 +1846,7 @@ class C {
|
|
|
1670
1846
|
* Clone the current query builder
|
|
1671
1847
|
*/
|
|
1672
1848
|
clone() {
|
|
1673
|
-
const e = new
|
|
1849
|
+
const e = new F(this.client);
|
|
1674
1850
|
return e.params = { ...this.params }, e;
|
|
1675
1851
|
}
|
|
1676
1852
|
/**
|
|
@@ -1682,101 +1858,102 @@ class C {
|
|
|
1682
1858
|
/**
|
|
1683
1859
|
* Execute the search by geocoding an address first
|
|
1684
1860
|
*/
|
|
1685
|
-
async executeNearAddress(e, t, i,
|
|
1861
|
+
async executeNearAddress(e, t, i, s = !0) {
|
|
1686
1862
|
return this.client.searchMeetingsByAddress({
|
|
1687
1863
|
address: e,
|
|
1688
1864
|
radiusMiles: t,
|
|
1689
1865
|
radiusKm: i,
|
|
1690
|
-
sortByDistance:
|
|
1866
|
+
sortByDistance: s,
|
|
1691
1867
|
searchParams: this.params
|
|
1692
1868
|
});
|
|
1693
1869
|
}
|
|
1694
1870
|
}
|
|
1695
|
-
class
|
|
1871
|
+
class gt {
|
|
1696
1872
|
constructor(e) {
|
|
1873
|
+
R(this, "client");
|
|
1697
1874
|
this.client = e;
|
|
1698
1875
|
}
|
|
1699
1876
|
/**
|
|
1700
1877
|
* Search for today's meetings
|
|
1701
1878
|
*/
|
|
1702
1879
|
today() {
|
|
1703
|
-
const e = (/* @__PURE__ */ new Date()).getDay(), t = e === 0 ?
|
|
1704
|
-
return new
|
|
1880
|
+
const e = (/* @__PURE__ */ new Date()).getDay(), t = e === 0 ? $.SUNDAY : e;
|
|
1881
|
+
return new F(this.client).onWeekdays(t);
|
|
1705
1882
|
}
|
|
1706
1883
|
/**
|
|
1707
1884
|
* Search for weekend meetings
|
|
1708
1885
|
*/
|
|
1709
1886
|
weekend() {
|
|
1710
|
-
return new
|
|
1887
|
+
return new F(this.client).onWeekdays($.SATURDAY, $.SUNDAY);
|
|
1711
1888
|
}
|
|
1712
1889
|
/**
|
|
1713
1890
|
* Search for weekday meetings
|
|
1714
1891
|
*/
|
|
1715
1892
|
weekdays() {
|
|
1716
|
-
return new
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1893
|
+
return new F(this.client).onWeekdays(
|
|
1894
|
+
$.MONDAY,
|
|
1895
|
+
$.TUESDAY,
|
|
1896
|
+
$.WEDNESDAY,
|
|
1897
|
+
$.THURSDAY,
|
|
1898
|
+
$.FRIDAY
|
|
1722
1899
|
);
|
|
1723
1900
|
}
|
|
1724
1901
|
/**
|
|
1725
1902
|
* Search for evening meetings (after 5 PM)
|
|
1726
1903
|
*/
|
|
1727
1904
|
evening() {
|
|
1728
|
-
return new
|
|
1905
|
+
return new F(this.client).startingAfter(17);
|
|
1729
1906
|
}
|
|
1730
1907
|
/**
|
|
1731
1908
|
* Search for morning meetings (before 12 PM)
|
|
1732
1909
|
*/
|
|
1733
1910
|
morning() {
|
|
1734
|
-
return new
|
|
1911
|
+
return new F(this.client).startingBefore(12);
|
|
1735
1912
|
}
|
|
1736
1913
|
/**
|
|
1737
1914
|
* Search for virtual meetings only
|
|
1738
1915
|
*/
|
|
1739
1916
|
virtual() {
|
|
1740
|
-
return new
|
|
1917
|
+
return new F(this.client).virtualOnly();
|
|
1741
1918
|
}
|
|
1742
1919
|
/**
|
|
1743
1920
|
* Search for in-person meetings only
|
|
1744
1921
|
*/
|
|
1745
1922
|
inPerson() {
|
|
1746
|
-
return new
|
|
1923
|
+
return new F(this.client).inPersonOnly();
|
|
1747
1924
|
}
|
|
1748
1925
|
/**
|
|
1749
1926
|
* Search by meeting name or location
|
|
1750
1927
|
*/
|
|
1751
1928
|
byText(e) {
|
|
1752
|
-
return new
|
|
1929
|
+
return new F(this.client).searchText(e);
|
|
1753
1930
|
}
|
|
1754
1931
|
}
|
|
1755
1932
|
export {
|
|
1756
|
-
|
|
1757
|
-
|
|
1933
|
+
Et as BmltClient,
|
|
1934
|
+
v as BmltDataFormat,
|
|
1758
1935
|
_ as BmltEndpoint,
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1936
|
+
Fe as BmltErrorType,
|
|
1937
|
+
C as BmltQueryError,
|
|
1938
|
+
G as ErrorFactory,
|
|
1939
|
+
re as ErrorHandler,
|
|
1940
|
+
rt as GeocodingService,
|
|
1941
|
+
st as Language,
|
|
1942
|
+
F as MeetingQueryBuilder,
|
|
1943
|
+
gt as QuickSearch,
|
|
1944
|
+
ct as RetryHandler,
|
|
1945
|
+
it as SortKey,
|
|
1946
|
+
K as VenueType,
|
|
1947
|
+
$ as Weekday,
|
|
1948
|
+
nt as buildBmltURL,
|
|
1949
|
+
lt as extractIds,
|
|
1950
|
+
dt as formatTimeValue,
|
|
1951
|
+
mt as kilometersToMiles,
|
|
1952
|
+
ft as milesToKilometers,
|
|
1953
|
+
ht as normalizeParameters,
|
|
1954
|
+
ot as validateCoordinates,
|
|
1955
|
+
at as validateEndpointFormat,
|
|
1956
|
+
ae as validateRadius,
|
|
1957
|
+
Ae as validateRootServerURL
|
|
1781
1958
|
};
|
|
1782
1959
|
//# sourceMappingURL=app.js.map
|