bmlt-query-client 1.0.4 → 1.0.6

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