@epam/statgpt-sdmx-toolkit 0.2.0-rc.5 → 0.2.0-rc.50

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/index.mjs CHANGED
@@ -1,110 +1,147 @@
1
- const I = (e) => {
1
+ const v = (e) => {
2
2
  if (e != null) {
3
3
  const t = e.split("=");
4
4
  return t.length === 1 ? e : t[1];
5
5
  }
6
- }, p = (e) => {
7
- var r;
6
+ }, D = (e) => {
8
7
  if (e == null)
9
8
  return {};
10
- const t = I(e), n = {
9
+ const t = v(e), n = {
11
10
  agency: "",
12
11
  id: "",
13
12
  version: ""
14
- }, s = (o) => typeof o == "string" && /^[a-zA-Z0-9_.-]+$/.test(o);
15
- if (t) {
16
- if (t.includes(":")) {
17
- const o = t.split(":")[0], i = t.split(":")[1].split("(")[0];
18
- n.agency = s(o) ? o : "", n.id = s(i) ? i : "";
19
- }
20
- if (t.includes("(") && t.includes(")")) {
21
- const o = (r = t.split("(")[1]) == null ? void 0 : r.split(")")[0];
22
- n.version = s(o) ? o : "";
23
- }
24
- }
25
- return n;
26
- }, Pe = (e) => {
27
- const [t, n] = e.split(")."), { agency: s, id: r, version: o } = p(t + ")");
13
+ };
14
+ return t && (t.includes(":") && (n.agency = t.split(":")[0], n.id = t.split(":")[1].split("(")[0]), t.includes("(") && t.includes(")") && (n.version = t.split("(")[1]?.split(")")[0])), n;
15
+ }, we = (e) => {
16
+ const [t, n] = e.split(")."), { agency: s, id: r, version: o } = D(t + ")");
28
17
  return { childId: n, agency: s, id: r, version: o };
29
- }, Sn = (e, t, n) => {
18
+ }, Ie = (e, t, n) => {
30
19
  const s = t === "" ? "" : `(${t})`;
31
20
  return `${n}:${e}${s}`;
32
21
  };
33
- var k = /* @__PURE__ */ ((e) => (e.DESCENDANTS = "descendants", e.NONE = "none", e.ALL = "all", e))(k || {}), De = /* @__PURE__ */ ((e) => (e.EXACT = "exact", e.AVAILABLE = "available", e))(De || {});
22
+ var L = /* @__PURE__ */ ((e) => (e.DESCENDANTS = "descendants", e.NONE = "none", e.ALL = "all", e))(L || {}), me = /* @__PURE__ */ ((e) => (e.EXACT = "exact", e.AVAILABLE = "available", e))(me || {});
23
+ function Ne(e) {
24
+ return {
25
+ data: {
26
+ codelists: e.data.codelists,
27
+ conceptSchemes: e.data.conceptSchemes,
28
+ dataConstraints: e.data.dataConstraints?.map($e),
29
+ dataflows: e.data.dataflows,
30
+ dataStructures: e.data.dataStructures,
31
+ metadataStructures: e.data.metadataStructures
32
+ }
33
+ };
34
+ }
35
+ function $e(e) {
36
+ return {
37
+ ...e,
38
+ cubeRegions: e.cubeRegions?.map(Pe)
39
+ };
40
+ }
41
+ function Pe(e) {
42
+ return {
43
+ isIncluded: e.include,
44
+ memberSelection: e.keyValues.map(be)
45
+ };
46
+ }
47
+ function be(e) {
48
+ return {
49
+ included: e.include,
50
+ componentId: e.id,
51
+ selectionValues: e.values.map(_e)
52
+ };
53
+ }
54
+ function _e(e) {
55
+ return {
56
+ memberValue: e.value
57
+ };
58
+ }
34
59
  const Oe = (e = "", t = "", n = "") => `sdmx/3.0/availability/dataflow/${e}/${t}/${n}`;
35
- class Tn {
60
+ class yn {
36
61
  constructor(t) {
37
62
  this.client = t;
38
63
  }
39
64
  async getConstraints(t, n) {
40
- const { agency: s, id: r, version: o } = p(t), i = {
65
+ const { agency: s, id: r, version: o } = D(t), i = {
41
66
  filters: n || [],
42
- mode: De.AVAILABLE,
43
- references: k.NONE
44
- }, c = Oe(s, r, o);
45
- return await this.client.postRequest(c, { body: i });
67
+ mode: me.AVAILABLE,
68
+ references: L.NONE
69
+ }, a = Oe(s, r, o);
70
+ if (this.client.config.sdmxProxyUrl) {
71
+ const c = await this.client.postRequest(
72
+ a,
73
+ { body: i },
74
+ this.client.config.sdmxProxyUrl
75
+ );
76
+ return Ne(c);
77
+ }
78
+ return await this.client.postRequest(
79
+ a,
80
+ { body: i },
81
+ this.client.config.constrainsApiUrl || this.client.config.apiUrl
82
+ );
46
83
  }
47
84
  }
48
- var $ = /* @__PURE__ */ ((e) => (e.CSV = "csv", e.JSON = "json", e.XML = "xml", e))($ || {}), Le = /* @__PURE__ */ ((e) => (e.ID = "id", e.NAME = "name", e.ID_NAME = "both", e))(Le || {}), be = /* @__PURE__ */ ((e) => (e.FULL_DATASET = "full", e.DATA_IN_TABLE = "query", e))(be || {});
49
- const Ue = (e, t) => {
85
+ var y = /* @__PURE__ */ ((e) => (e.CSV = "csv", e.JSON = "json", e.XML = "xml", e))(y || {}), Le = /* @__PURE__ */ ((e) => (e.ID = "id", e.NAME = "name", e.ID_NAME = "both", e))(Le || {}), Me = /* @__PURE__ */ ((e) => (e.FULL_DATASET = "full", e.DATA_IN_TABLE = "query", e))(Me || {});
86
+ const Ce = (e, t) => {
50
87
  switch (e) {
51
- case $.CSV:
52
- return m(
88
+ case y.CSV:
89
+ return A(
53
90
  "application/vnd.sdmx.data+csv;version=2.0.0",
54
91
  t
55
92
  );
56
- case $.XML:
57
- return m(
93
+ case y.XML:
94
+ return A(
58
95
  "application/vnd.sdmx.data+xml;version=3.0.0",
59
96
  t
60
97
  );
61
- case $.JSON:
62
- return m(`application/${e}`, t);
98
+ case y.JSON:
99
+ return A(`application/${e}`, t);
63
100
  default:
64
- return m(
101
+ return A(
65
102
  "application/vnd.sdmx.data+csv;version=2.0.0",
66
103
  t
67
104
  );
68
105
  }
69
- }, m = (e, t) => `${e}; labels=${t}`;
70
- var ye = /* @__PURE__ */ ((e) => (e.REFERENCE_PARTIAL = "referencepartial", e.FULL = "full", e))(ye || {});
71
- const xe = "all", Ye = "sdmx/3.0/data/dataflow", Se = "&", se = ":", Ce = "=", We = "+", Rn = ",", ke = "*", re = (e, t, n) => {
72
- const { filterKey: s, timeFilter: r } = n, { agency: o, id: i, version: c } = p(e), a = [r || "", t].filter((l) => !!l).join(Se);
73
- return `${`${Ye}/${o}/${i}/${c}`}/${s || ke}?${a}`;
74
- }, qe = (e = "", t = "", n = "", s = k.DESCENDANTS) => `sdmx/3.0/structure/dataflow/${e}/${t}/${n}?references=${s}&detail=${ye.REFERENCE_PARTIAL}`;
75
- class wn {
106
+ }, A = (e, t) => `${e}; labels=${t}`;
107
+ var fe = /* @__PURE__ */ ((e) => (e.REFERENCE_PARTIAL = "referencepartial", e.FULL = "full", e))(fe || {});
108
+ const Ue = "all", xe = "sdmx/3.0/data/dataflow", ge = "&", J = ":", Ye = "=", We = "+", Tn = ",", Ve = "*", X = (e, t, n) => {
109
+ const { filterKey: s, timeFilter: r } = n, { agency: o, id: i, version: a } = D(e), c = [r || "", t].filter((d) => !!d).join(ge);
110
+ return `${`${xe}/${o}/${i}/${a}`}/${s || Ve}?${c}`;
111
+ }, ke = (e = "", t = "", n = "", s = L.DESCENDANTS) => `sdmx/3.0/structure/dataflow/${e}/${t}/${n}?references=${s}&detail=${fe.REFERENCE_PARTIAL}`;
112
+ class vn {
76
113
  constructor(t) {
77
114
  this.client = t;
78
115
  }
79
116
  async getDataSet(t, n) {
80
- const { agency: s, id: r, version: o } = p(t);
117
+ const { agency: s, id: r, version: o } = D(t);
81
118
  return await this.client.getRequest(
82
- qe(s, r, o, n)
119
+ ke(s, r, o, n)
83
120
  );
84
121
  }
85
122
  async getDatasetData(t, n) {
86
123
  const s = new URLSearchParams({
87
124
  includeHistory: "false",
88
125
  limit: "1000",
89
- attributes: xe,
126
+ attributes: Ue,
90
127
  dimensionAtObservation: "TIME_PERIOD"
91
128
  // TODO: use time dimensions
92
- }).toString(), r = re(t, s, n);
129
+ }).toString(), r = X(t, s, n);
93
130
  return await this.client.getRequest(r);
94
131
  }
95
- async downloadDataSet(t, n, s, r, o, i, c = !1) {
96
- const a = new URLSearchParams({
132
+ async downloadDataSet(t, n, s, r, o, i, a = !1) {
133
+ const c = new URLSearchParams({
97
134
  format: n,
98
135
  compress: "false",
99
- attributes: c ? "all" : "none",
136
+ attributes: a ? "all" : "none",
100
137
  limit: "1000"
101
- }).toString(), u = re(t, a, o);
138
+ }).toString(), u = X(t, c, o);
102
139
  return this.client.streamRequest(
103
140
  u,
104
141
  {
105
142
  method: "GET",
106
143
  headers: {
107
- Accept: Ue(n, r),
144
+ Accept: Ce(n, r),
108
145
  "Accept-language": s
109
146
  }
110
147
  },
@@ -112,46 +149,52 @@ class wn {
112
149
  );
113
150
  }
114
151
  }
115
- const Me = (e, t) => e.error || e.message || `${t.status} ${t.statusText}`, Qe = "application/json", Be = "Content-Type", x = "Api-Key", Ve = "X-CONVERSATION-ID", N = "Ocp-Apim-Subscription-Key", v = (e) => isNaN(Date.parse(e)) ? null : new Date(e), Y = (e, t, n) => {
152
+ const qe = (e, t) => e.error || e.message || `${t.status} ${t.statusText}`, Qe = "application/json", Be = "Content-Type", P = "Api-Key", Fe = "X-CONVERSATION-ID", T = "Ocp-Apim-Subscription-Key";
153
+ class Z extends Error {
154
+ constructor(t) {
155
+ super(t.message), this.isHttpError = !0, this.name = "HttpError", this.code = t.code, this.status = t.status, this.details = t.details, this.displayMessage = t.displayMessage;
156
+ }
157
+ }
158
+ const S = (e) => isNaN(Date.parse(e)) ? null : new Date(e), b = (e, t, n) => {
116
159
  const s = {
117
- [Be]: (t == null ? void 0 : t.contentType) || Qe
160
+ [Be]: t?.contentType || Qe
118
161
  };
119
- return t != null && t.jwt && (s.Authorization = `Bearer ${t.jwt}`), t != null && t.chatReference && (s[Ve] = t.chatReference), { ...s, ...n };
120
- }, Fe = (e) => {
162
+ return t?.jwt && (s.Authorization = `Bearer ${t.jwt}`), t?.chatReference && (s[Fe] = t.chatReference), { ...s, ...n };
163
+ }, Ge = (e) => {
121
164
  const t = { ...e };
122
- return t[x] && (t[x] = t[x].substring(0, 8) + "...[REDACTED]"), t.Authorization && (t.Authorization = "Bearer [REDACTED]"), t[N] && (t[N] = t[N].substring(0, 8) + "...[REDACTED]"), t;
123
- }, oe = async (e, t, n) => await fetch(e, {
165
+ return t[P] && (t[P] = t[P].substring(0, 8) + "...[REDACTED]"), t.Authorization && (t.Authorization = "Bearer [REDACTED]"), t[T] && (t[T] = t[T].substring(0, 8) + "...[REDACTED]"), t;
166
+ }, ee = async (e, t, n) => await fetch(e, {
124
167
  method: n.method || "GET",
125
168
  headers: t,
126
169
  body: n.body ? JSON.stringify(n.body) : void 0
127
- }), Ge = async (e, t, n) => await fetch(e, {
170
+ }), Ke = async (e, t, n) => await fetch(e, {
128
171
  method: n.method,
129
172
  headers: t,
130
- body: n != null && n.isFormData && typeof (n == null ? void 0 : n.body) == "string" ? n.body : JSON.stringify(n.body),
131
- signal: n == null ? void 0 : n.signal
173
+ body: n?.isFormData && typeof n?.body == "string" ? n.body : JSON.stringify(n.body),
174
+ signal: n?.signal
132
175
  });
133
- class Ke {
176
+ class je {
134
177
  constructor() {
135
178
  this.decoder = new TextDecoder();
136
179
  }
137
180
  async streamChat(t, n, s = {}, r) {
138
- const { onMessage: o, onError: i, onComplete: c, signal: a } = s;
181
+ const { onMessage: o, onError: i, onComplete: a, signal: c } = s;
139
182
  try {
140
183
  const u = await this.initializeStreamRequest(
141
184
  t,
142
185
  n,
143
- a,
186
+ c,
144
187
  r
145
188
  );
146
- await this.processStreamData(u, o), c == null || c();
189
+ await this.processStreamData(u, o), a?.();
147
190
  } catch (u) {
148
191
  this.handleStreamError(u, i);
149
192
  }
150
193
  }
151
194
  async initializeStreamRequest(t, n, s, r) {
152
- const o = Y(void 0, {
195
+ const o = b(void 0, {
153
196
  jwt: r
154
- }), i = await Ge(
197
+ }), i = await Ke(
155
198
  t,
156
199
  {
157
200
  Accept: "text/event-stream",
@@ -164,13 +207,23 @@ class Ke {
164
207
  }
165
208
  );
166
209
  if (!i.ok) {
167
- const c = await i.text();
168
- throw new Error(
169
- JSON.stringify({ status: i.status, message: c })
170
- );
210
+ const a = await i.text();
211
+ let c = {};
212
+ try {
213
+ c = JSON.parse(a);
214
+ } catch {
215
+ c.error = "Failed to parse error body";
216
+ }
217
+ throw new Z({
218
+ status: i.status,
219
+ message: c.error ?? "No response body"
220
+ });
171
221
  }
172
222
  if (!i.body)
173
- throw new Error("No response body");
223
+ throw new Z({
224
+ message: "No response body",
225
+ status: i.status
226
+ });
174
227
  return i.body.getReader();
175
228
  }
176
229
  async processStreamData(t, n) {
@@ -184,11 +237,11 @@ class Ke {
184
237
  }
185
238
  const i = this.decoder.decode(o, { stream: !0 });
186
239
  s += i;
187
- const c = s.split(`
240
+ const a = s.split(`
188
241
  `);
189
- s = c.pop() || "";
190
- for (const a of c)
191
- this.parseSSEDataLine(a, n);
242
+ s = a.pop() || "";
243
+ for (const c of a)
244
+ this.parseSSEDataLine(c, n);
192
245
  }
193
246
  } finally {
194
247
  t.releaseLock();
@@ -196,7 +249,7 @@ class Ke {
196
249
  }
197
250
  handleStreamError(t, n) {
198
251
  const s = t instanceof Error ? t : new Error(String(t));
199
- throw n == null || n(s), s;
252
+ throw n?.(s), s;
200
253
  }
201
254
  parseSSEDataLine(t, n) {
202
255
  const s = t.trim();
@@ -206,17 +259,18 @@ class Ke {
206
259
  console.info("SSE: Stream completed");
207
260
  return;
208
261
  }
262
+ let o;
209
263
  try {
210
- const o = JSON.parse(r);
211
- n == null || n(o);
212
- } catch (o) {
213
- console.error(`Failed to parse SSE data: ${r} ${o}`);
264
+ o = JSON.parse(r);
265
+ } catch (i) {
266
+ console.error(`Failed to parse SSE data: ${r} ${i}`);
214
267
  }
268
+ n?.(o);
215
269
  }
216
270
  }
217
271
  }
218
- new Ke();
219
- class pn {
272
+ new je();
273
+ class Rn {
220
274
  constructor(t) {
221
275
  this.config = t, console.info("SdmxApiClient initialized", {
222
276
  apiUrl: t.apiUrl || "NOT SET"
@@ -225,94 +279,93 @@ class pn {
225
279
  async getRequest(t, n) {
226
280
  return this.request(t, { ...n, method: "GET" });
227
281
  }
228
- async postRequest(t, n) {
229
- return this.request(t, { ...n, method: "POST" });
282
+ async postRequest(t, n, s) {
283
+ return this.request(t, { ...n, method: "POST" }, s);
230
284
  }
231
285
  async streamRequest(t, n, s) {
232
286
  const r = `${this.config.apiUrl}/${t}`, o = {
233
- ...Y(void 0, {
287
+ ...b(void 0, {
234
288
  jwt: this.config.jwt
235
289
  }),
236
290
  ...n.headers
237
291
  };
238
- this.config.apiKey != null && (o[N] = this.config.apiKey);
292
+ this.config.apiKey != null && (o[T] = this.config.apiKey);
239
293
  const i = new ReadableStream({
240
- async start(a) {
241
- var u;
294
+ async start(c) {
242
295
  try {
243
- const l = await oe(r, o, n);
244
- if (!l.ok) {
245
- const g = await l.text();
296
+ const u = await ee(r, o, n);
297
+ if (!u.ok) {
298
+ const f = await u.text();
246
299
  throw console.error(
247
- `Fetch failed! Status: ${l.status}, Body: ${g}`
248
- ), new Error(`Fetch failed with status ${l.status}`);
300
+ `Fetch failed! Status: ${u.status}, Body: ${f}`
301
+ ), new Error(`Fetch failed with status ${u.status}`);
249
302
  }
250
- const f = (u = l.body) == null ? void 0 : u.getReader();
251
- if (!f) throw new Error("Failed to create stream reader");
252
- const E = new Uint8Array([239, 187, 191]);
253
- a.enqueue(E);
254
- const d = async () => {
255
- const { done: g, value: h } = await f.read();
256
- g ? a.close() : (a.enqueue(h), await d());
303
+ const d = u.body?.getReader();
304
+ if (!d) throw new Error("Failed to create stream reader");
305
+ const l = new Uint8Array([239, 187, 191]);
306
+ c.enqueue(l);
307
+ const m = async () => {
308
+ const { done: f, value: p } = await d.read();
309
+ f ? c.close() : (c.enqueue(p), await m());
257
310
  };
258
- d();
259
- } catch (l) {
260
- a.error(l);
311
+ m();
312
+ } catch (u) {
313
+ c.error(u);
261
314
  }
262
315
  }
263
- }), c = new Headers({
316
+ }), a = new Headers({
264
317
  "Content-Disposition": `attachment; filename=${encodeURIComponent(s)}`
265
318
  });
266
- return new Response(i, { headers: c });
319
+ return new Response(i, { headers: a });
267
320
  }
268
- async request(t, n) {
269
- const s = Date.now(), r = t.includes("availability") && this.config.constrainsApiUrl ? `${this.config.constrainsApiUrl}/${t}` : `${this.config.apiUrl}/${t}`, o = {
270
- ...Y(void 0, {
321
+ async request(t, n, s) {
322
+ const r = Date.now(), o = `${s || this.config.apiUrl}/${t}`, i = {
323
+ ...b(void 0, {
271
324
  jwt: this.config.jwt
272
325
  }),
273
326
  ...n.headers
274
327
  };
275
- this.config.apiKey != null && (o["Ocp-Apim-Subscription-Key"] = this.config.apiKey), this.addInfoRequestLog("API Request", r, n, o);
328
+ this.config.apiKey != null && (i["Ocp-Apim-Subscription-Key"] = this.config.apiKey), this.addInfoRequestLog("API Request", o, n, i);
276
329
  try {
277
- const i = await oe(r, o, n), c = Date.now() - s;
278
- let a;
279
- const u = await i.text();
330
+ const a = await ee(o, i, n), c = Date.now() - r;
331
+ let u;
332
+ const d = await a.text();
280
333
  try {
281
- a = u ? JSON.parse(u) : {};
334
+ u = d ? JSON.parse(d) : {};
282
335
  } catch {
283
336
  if (this.addErrorRequestParsing(
284
- r,
337
+ o,
285
338
  n,
286
- i,
339
+ a,
287
340
  c,
288
- u
289
- ), !i.ok)
341
+ d
342
+ ), !a.ok)
290
343
  throw new Error(
291
- `API request failed: ${i.status} ${i.statusText} - ${u.substring(0, 100)}`
344
+ `API request failed: ${a.status} ${a.statusText} - ${d.substring(0, 100)}`
292
345
  );
293
- a = { data: u };
346
+ u = { data: d };
294
347
  }
295
- if (!i.ok) {
296
- this.addErrorRequestLog(r, n, i, c, a);
297
- const l = Me(a, i);
348
+ if (!a.ok) {
349
+ this.addErrorRequestLog(o, n, a, c, u);
350
+ const l = qe(u, a);
298
351
  throw new Error(`API request failed: ${l}`);
299
352
  }
300
- return a;
301
- } catch (i) {
302
- const c = Date.now() - s;
353
+ return u;
354
+ } catch (a) {
355
+ const c = Date.now() - r;
303
356
  throw console.error("API Request Exception", {
304
357
  method: n.method,
305
- url: r,
358
+ url: o,
306
359
  duration: `${c}ms`,
307
- error: i instanceof Error ? i.message : String(i)
308
- }), i;
360
+ error: a instanceof Error ? a.message : String(a)
361
+ }), a;
309
362
  }
310
363
  }
311
364
  addInfoRequestLog(t, n, s, r) {
312
365
  const o = {
313
366
  method: s.method || "GET",
314
367
  url: n,
315
- headers: Fe(r)
368
+ headers: Ge(r)
316
369
  };
317
370
  s.body && (o.body = s.body), console.info(t, o);
318
371
  }
@@ -338,203 +391,190 @@ class pn {
338
391
  });
339
392
  }
340
393
  }
341
- const mn = ["FREQ", "FREQUENCY"];
342
- var je = /* @__PURE__ */ ((e) => (e.CONDITIONAL = "Conditional", e.MANDATORY = "Mandatory", e))(je || {}), q = /* @__PURE__ */ ((e) => (e.DIMENSION = "Dimension", e.MEASURE_DIMENSION = "MeasureDimension", e.TIME_DIMENSION = "TimeDimension", e))(q || {}), ze = /* @__PURE__ */ ((e) => (e.UNBOUNDED = "unbounded", e))(ze || {});
343
- const He = (e, t) => {
344
- var c, a, u, l, f;
345
- const n = (a = (c = e == null ? void 0 : e.data) == null ? void 0 : c.dataSets) == null ? void 0 : a[0], s = (l = (u = e == null ? void 0 : e.data) == null ? void 0 : u.structures) == null ? void 0 : l[0], r = ((f = s == null ? void 0 : s.attributes) == null ? void 0 : f.dimensionGroup) || [], o = n == null ? void 0 : n.dimensionGroupAttributes, i = {};
346
- for (const E of r) {
347
- const d = E.relationship.dimensions, { codedSeriesKey: g, decodedSeriesKey: h } = Te(
394
+ const wn = ["FREQ", "FREQUENCY"];
395
+ var He = /* @__PURE__ */ ((e) => (e.CONDITIONAL = "Conditional", e.MANDATORY = "Mandatory", e))(He || {}), M = /* @__PURE__ */ ((e) => (e.DIMENSION = "Dimension", e.MEASURE_DIMENSION = "MeasureDimension", e.TIME_DIMENSION = "TimeDimension", e))(M || {}), ze = /* @__PURE__ */ ((e) => (e.UNBOUNDED = "unbounded", e))(ze || {});
396
+ const Je = (e, t) => {
397
+ const n = e?.data?.dataSets?.[0], r = e?.data?.structures?.[0]?.attributes?.dimensionGroup || [], o = n?.dimensionGroupAttributes, i = {};
398
+ for (const a of r) {
399
+ const c = a.relationship.dimensions, { codedSeriesKey: u, decodedSeriesKey: d } = he(
348
400
  e,
349
401
  t,
350
- d
402
+ c
351
403
  );
352
- i[E.id] = {
353
- values: (o == null ? void 0 : o[g]) || [],
354
- decodedSeriesKey: h,
355
- codedSeriesKey: g
404
+ i[a.id] = {
405
+ values: o?.[u] || [],
406
+ decodedSeriesKey: d,
407
+ codedSeriesKey: u
356
408
  };
357
409
  }
358
410
  return i;
359
- }, Te = (e, t, n) => {
360
- var c, a;
361
- const s = (a = (c = e == null ? void 0 : e.data) == null ? void 0 : c.structures) == null ? void 0 : a[0], r = [
362
- ...(s == null ? void 0 : s.dimensions.series) || [],
363
- ...(s == null ? void 0 : s.dimensions.observation) || []
364
- ], o = new Array(r == null ? void 0 : r.length), i = new Array(r == null ? void 0 : r.length);
365
- return n == null || n.forEach((u) => {
366
- const l = (r == null ? void 0 : r.findIndex((d) => d.id === u)) || 0, f = t[l], E = r[l].values.findIndex(
367
- (d) => d.id === f || d.value === f
411
+ }, he = (e, t, n) => {
412
+ const s = e?.data?.structures?.[0], r = [
413
+ ...s?.dimensions.series || [],
414
+ ...s?.dimensions.observation || []
415
+ ], o = new Array(r?.length), i = new Array(r?.length);
416
+ return n?.forEach((a) => {
417
+ const c = r?.findIndex((l) => l.id === a) || 0, u = t[c], d = r[c].values.findIndex(
418
+ (l) => l.id === u || l.value === u
368
419
  ) || 0;
369
- o[l] = E >= 0 ? E : f, i[l] = f;
420
+ o[c] = d >= 0 ? d : u, i[c] = u;
370
421
  }), {
371
422
  codedSeriesKey: o.join(":"),
372
423
  decodedSeriesKey: i.join(":")
373
424
  };
374
- }, vn = (e, t, n) => {
375
- var f, E, d, g, h;
376
- const s = (E = (f = e == null ? void 0 : e.data) == null ? void 0 : f.dataSets) == null ? void 0 : E[0], r = (g = (d = e == null ? void 0 : e.data) == null ? void 0 : d.structures) == null ? void 0 : g[0], o = (((h = r == null ? void 0 : r.attributes) == null ? void 0 : h.dimensionGroup) || []).filter(
377
- (D) => {
378
- var A;
379
- return ((A = D.relationship.dimensions) == null ? void 0 : A.length) === 1 && D.relationship.dimensions.includes(t || "");
380
- }
381
- ), i = s == null ? void 0 : s.dimensionGroupAttributes, c = [
382
- ...(r == null ? void 0 : r.dimensions.series) || [],
383
- ...(r == null ? void 0 : r.dimensions.observation) || []
384
- ], a = c == null ? void 0 : c.findIndex((D) => D.id === t), u = new Array(c == null ? void 0 : c.length);
385
- u[a] = n || "";
386
- const l = {};
387
- for (const D of o) {
388
- const A = D.relationship.dimensions, { codedSeriesKey: y, decodedSeriesKey: S } = Te(
425
+ }, In = (e, t, n) => {
426
+ const s = e?.data?.dataSets?.[0], r = e?.data?.structures?.[0], o = (r?.attributes?.dimensionGroup || []).filter(
427
+ (l) => l.relationship.dimensions?.length === 1 && l.relationship.dimensions.includes(t || "")
428
+ ), i = s?.dimensionGroupAttributes, a = [
429
+ ...r?.dimensions.series || [],
430
+ ...r?.dimensions.observation || []
431
+ ], c = a?.findIndex((l) => l.id === t), u = new Array(a?.length);
432
+ u[c] = n || "";
433
+ const d = {};
434
+ for (const l of o) {
435
+ const m = l.relationship.dimensions, { codedSeriesKey: f, decodedSeriesKey: p } = he(
389
436
  e,
390
437
  u,
391
- A
438
+ m
392
439
  );
393
- l[D.id] = {
394
- values: (i == null ? void 0 : i[y]) || [],
395
- decodedSeriesKey: S,
396
- codedSeriesKey: y
440
+ d[l.id] = {
441
+ values: i?.[f] || [],
442
+ decodedSeriesKey: p,
443
+ codedSeriesKey: f
397
444
  };
398
445
  }
399
- return l;
400
- }, Je = (e, t) => {
401
- var s;
446
+ return d;
447
+ }, Xe = (e, t) => {
402
448
  if (t == null)
403
449
  return;
404
- const n = (s = e.values) == null ? void 0 : s[t];
450
+ const n = e.values?.[t];
405
451
  return n ?? (t instanceof Array ? { values: t } : { value: t.toString() });
406
- }, Xe = "Observation", $n = (e) => {
407
- var u, l, f, E, d, g;
408
- const t = (u = e == null ? void 0 : e.data) == null ? void 0 : u.dataSets, n = (f = (l = e == null ? void 0 : e.data) == null ? void 0 : l.structures) == null ? void 0 : f[0];
452
+ }, Ze = "Observation", Nn = (e) => {
453
+ const t = e?.data?.dataSets, n = e?.data?.structures?.[0];
409
454
  if (!t || !n)
410
455
  return [];
411
- const s = n.attributes, r = n.dimensions, o = (s == null ? void 0 : s.dimensionGroup) || [], i = t[0].series || t[0].observations, c = (E = r.series) != null && E.length ? r.series : r.observation, a = [];
412
- for (const h in i) {
413
- const D = [], { name: A, parsedTimeSeriesValue: y } = Ze(
414
- h,
415
- c
416
- ), S = i[h], P = S.attributes || [];
417
- if (Object.keys(S).length === 0) {
418
- a.push({
419
- name: A,
420
- parsedTimeSeriesValue: y,
421
- values: D,
456
+ const s = n.attributes, r = n.dimensions, o = s?.dimensionGroup || [], i = t[0].series || t[0].observations, a = r.series?.length ? r.series : r.observation, c = [];
457
+ for (const u in i) {
458
+ const d = [], { name: l, parsedTimeSeriesValue: m } = et(
459
+ u,
460
+ a
461
+ ), f = i[u], p = f.attributes || [];
462
+ if (Object.keys(f).length === 0) {
463
+ c.push({
464
+ name: l,
465
+ parsedTimeSeriesValue: m,
466
+ values: d,
422
467
  attributes: [],
423
468
  dataSetAttrs: []
424
469
  });
425
470
  continue;
426
471
  }
427
- D.push(
428
- ...st(S, n)
472
+ d.push(
473
+ ...rt(f, n)
429
474
  );
430
- const O = C(
431
- (s == null ? void 0 : s.series) || [],
432
- (T) => P[T]
433
- ), L = rt(
434
- ((d = n.attributes) == null ? void 0 : d.dataSet) || [],
435
- ((g = t[0].attributes) == null ? void 0 : g.filter((T) => T != null)) || []
436
- ), b = He(
475
+ const w = _(
476
+ s?.series || [],
477
+ (E) => p[E]
478
+ ), I = ot(
479
+ n.attributes?.dataSet || [],
480
+ t[0].attributes?.filter((E) => E != null) || []
481
+ ), N = Je(
437
482
  e,
438
- y
439
- ), U = o.map((T, Ie) => {
440
- const ne = b[T.id], _e = Je(
441
- T,
442
- ne.values[Ie]
483
+ m
484
+ ), $ = o.map((E, ve) => {
485
+ const z = N[E.id], Re = Xe(
486
+ E,
487
+ z.values[ve]
443
488
  );
444
489
  return {
445
- attribute: T,
446
- dimensionGroupValue: _e,
447
- dimensionGroupData: ne
490
+ attribute: E,
491
+ dimensionGroupValue: Re,
492
+ dimensionGroupData: z
448
493
  };
449
494
  });
450
- a.push({
451
- name: A,
452
- parsedTimeSeriesValue: y,
453
- values: D,
454
- attributes: O,
455
- dataSetAttrs: L,
456
- dimensionGroupAttributes: U
495
+ c.push({
496
+ name: l,
497
+ parsedTimeSeriesValue: m,
498
+ values: d,
499
+ attributes: w,
500
+ dataSetAttrs: I,
501
+ dimensionGroupAttributes: $
457
502
  });
458
503
  }
459
- return a;
460
- }, Ze = (e, t) => {
504
+ return c;
505
+ }, et = (e, t) => {
461
506
  const n = e.split(new RegExp("(?<!\\|):(?!\\||$)")), s = [];
462
507
  for (let r = 0; r < n.length; r++) {
463
- const o = t == null ? void 0 : t[r], i = Number(n[r]);
508
+ const o = t?.[r], i = Number(n[r]);
464
509
  if (i < 0 || o == null)
465
510
  continue;
466
- const c = o.values[i];
467
- if (c == null) {
511
+ const a = o.values[i];
512
+ if (a == null) {
468
513
  s.push(n[r].replace("|:", ":"));
469
514
  continue;
470
515
  }
471
- s.push((c == null ? void 0 : c.id) || (c == null ? void 0 : c.value) || "");
516
+ s.push(a?.id || a?.value || "");
472
517
  }
473
518
  return {
474
- name: tt(s),
519
+ name: nt(s),
475
520
  parsedTimeSeriesValue: s
476
521
  };
477
- }, C = (e, t) => {
522
+ }, _ = (e, t) => {
478
523
  const n = [];
479
524
  for (let s = 0; s < e.length; s++) {
480
- const r = e[s], o = t(s), i = o != null && r.values != null ? et(o, r) : void 0;
525
+ const r = e[s], o = t(s), i = o != null && r.values != null ? tt(o, r) : void 0;
481
526
  n.push({
482
527
  name: r.id,
483
528
  value: i
484
529
  });
485
530
  }
486
531
  return n;
487
- }, et = (e, t) => {
532
+ }, tt = (e, t) => {
488
533
  const n = t.values[e];
489
- return n == null ? typeof e == "object" ? e : e.toString() : (n == null ? void 0 : n.id) || (n == null ? void 0 : n.value) || (n == null ? void 0 : n.ids) || (n == null ? void 0 : n.values);
490
- }, tt = (e) => e.map((t) => t ? nt(t) : "").join("."), nt = (e) => e.replace(/\./g, "|.").replace(/:/g, "|:"), st = (e, t) => {
491
- var i, c, a, u, l;
492
- const n = (c = (i = t.measures) == null ? void 0 : i.observation) == null ? void 0 : c.length;
534
+ return n == null ? typeof e == "object" ? e : e.toString() : n?.id || n?.value || n?.ids || n?.values;
535
+ }, nt = (e) => e.map((t) => t ? st(t) : "").join("."), st = (e) => e.replace(/\./g, "|.").replace(/:/g, "|:"), rt = (e, t) => {
536
+ const n = t.measures?.observation?.length;
493
537
  if (e.observations == null)
494
538
  return [
495
539
  {
496
- values: ie(e, t.measures),
497
- obsAttributes: C(
498
- ((a = t.attributes) == null ? void 0 : a.observation) || [],
499
- (f) => e[f + n]
540
+ values: te(e, t.measures),
541
+ obsAttributes: _(
542
+ t.attributes?.observation || [],
543
+ (i) => e[i + n]
500
544
  ),
501
- dimensionAtObservation: Xe
545
+ dimensionAtObservation: Ze
502
546
  }
503
547
  ];
504
- const s = e.observations, r = (u = t.dimensions.observation) == null ? void 0 : u[0], o = [];
505
- for (const f in s) {
506
- const E = r == null ? void 0 : r.values[f];
548
+ const s = e.observations, r = t.dimensions.observation?.[0], o = [];
549
+ for (const i in s) {
550
+ const a = r?.values[i];
507
551
  o.push({
508
- dimensionAtObservation: (E == null ? void 0 : E.value) || (E == null ? void 0 : E.id),
509
- values: ie(
510
- s[f],
552
+ dimensionAtObservation: a?.value || a?.id,
553
+ values: te(
554
+ s[i],
511
555
  t.measures
512
556
  ),
513
- obsAttributes: C(
514
- ((l = t.attributes) == null ? void 0 : l.observation) || [],
515
- (d) => s[f][d + n]
557
+ obsAttributes: _(
558
+ t.attributes?.observation || [],
559
+ (c) => s[i][c + n]
516
560
  )
517
561
  });
518
562
  }
519
563
  return o;
520
- }, ie = (e, t) => {
521
- var n;
522
- return ((n = t == null ? void 0 : t.observation) == null ? void 0 : n.map((s, r) => ({ name: s.id, value: e[r] }))) || [];
523
- }, rt = (e, t) => e.reduce(
564
+ }, te = (e, t) => t?.observation?.map((n, s) => ({ name: n.id, value: e[s] })) || [], ot = (e, t) => e.reduce(
524
565
  (n, s, r) => {
525
566
  const o = t[r];
526
- return ot(n, s, o, ""), n;
567
+ return it(n, s, o, ""), n;
527
568
  },
528
569
  []
529
- ), ot = (e, t, n, s) => {
530
- var o, i, c;
531
- const r = n != null ? ((o = t == null ? void 0 : t.values) == null ? void 0 : o.length) > 0 ? ((i = t.values[n]) == null ? void 0 : i.id) || ((c = t.values[n]) == null ? void 0 : c.value) : String(n) : s;
570
+ ), it = (e, t, n, s) => {
571
+ const r = n != null ? t?.values?.length > 0 ? t.values[n]?.id || t.values[n]?.value : String(n) : s;
532
572
  e.push({
533
573
  name: t.id,
534
574
  value: r || ""
535
575
  });
536
- }, it = /^[0-9][0-9][0-9][0-9]-Q[1-4]$/, ct = /^[0-9][0-9][0-9][0-9]-W[0-9][0-9]?$/, at = /^[0-9][0-9][0-9][0-9]-S[1-2]$/, ut = /^[0-9][0-9][0-9][0-9]$/, lt = /^[0-9][0-9][0-9][0-9]-(0[1-9]|1[0-2])-[0-9][0-9]$/, dt = /^[0-9][0-9][0-9][0-9]-M(0[1-9]|(1[0-2]))$/, M = (e) => ut.exec(e), Q = (e) => !!M(e), ft = (e) => at.exec(e), B = (e) => !!ft(e), V = (e) => dt.exec(e), F = (e) => !!V(e), G = (e) => it.exec(e), K = (e) => !!G(e), gt = (e) => lt.exec(e), Et = (e) => !!gt(e), ht = (e) => ct.exec(e), j = (e) => !!ht(e), z = 1440 * 60 * 1e3, H = 7 * z;
537
- function J(e) {
576
+ }, at = /^[0-9][0-9][0-9][0-9]-Q[1-4]$/, ct = /^[0-9][0-9][0-9][0-9]-W[0-9][0-9]?$/, ut = /^[0-9][0-9][0-9][0-9]-S[1-2]$/, dt = /^[0-9][0-9][0-9][0-9]$/, lt = /^[0-9][0-9][0-9][0-9]-(0[1-9]|1[0-2])-[0-9][0-9]$/, mt = /^[0-9][0-9][0-9][0-9]-M(0[1-9]|(1[0-2]))$/, C = (e) => dt.exec(e), U = (e) => !!C(e), ft = (e) => ut.exec(e), x = (e) => !!ft(e), Y = (e) => mt.exec(e), W = (e) => !!Y(e), V = (e) => at.exec(e), k = (e) => !!V(e), gt = (e) => lt.exec(e), ht = (e) => !!gt(e), pt = (e) => ct.exec(e), q = (e) => !!pt(e), Q = 1440 * 60 * 1e3, B = 7 * Q;
577
+ function F(e) {
538
578
  const t = `${e}-01-01`, n = new Date(t);
539
579
  if (n.getDay() !== 4) {
540
580
  const r = 1 + (4 - n.getDay() + 7) % 7;
@@ -542,55 +582,55 @@ function J(e) {
542
582
  }
543
583
  return n;
544
584
  }
545
- function At(e) {
585
+ function Et(e) {
546
586
  const t = new Date(e), s = -((t.getDay() + 6) % 7) + 3;
547
587
  return t.setDate(t.getDate() + s), new Date(t.valueOf());
548
588
  }
549
- function ce(e, t = "W") {
550
- const n = `${e}-12-31`, s = _(new Date(n), t);
589
+ function ne(e, t = "W") {
590
+ const n = `${e}-12-31`, s = R(new Date(n), t);
551
591
  if (s.weekYear === e)
552
592
  return s.weekNumber;
553
593
  const r = `${e}-12-24`;
554
- return _(new Date(r), t).weekNumber;
594
+ return R(new Date(r), t).weekNumber;
555
595
  }
556
- function Re(e, t, n = "W") {
596
+ function pe(e, t, n = "W") {
557
597
  return `${e}-${n}${t < 10 ? "0" + t : t}`;
558
598
  }
559
- function _(e, t = "W") {
560
- const n = At(e), s = n.getFullYear(), r = J(s), o = 1 + Math.ceil(
561
- (n.getTime() - r.getTime()) / H
599
+ function R(e, t = "W") {
600
+ const n = Et(e), s = n.getFullYear(), r = F(s), o = 1 + Math.ceil(
601
+ (n.getTime() - r.getTime()) / B
562
602
  );
563
603
  return {
564
- code: Re(s, o, t),
604
+ code: pe(s, o, t),
565
605
  weekNumber: o,
566
606
  weekYear: s
567
607
  };
568
608
  }
569
609
  function Dt(e) {
570
- const [t, n] = e.split("-W"), r = J(+t).getTime() + (+n - 1) * H - 3 * z;
610
+ const [t, n] = e.split("-W"), r = F(+t).getTime() + (+n - 1) * B - 3 * Q;
571
611
  return new Date(r);
572
612
  }
573
- function yt(e) {
574
- const [t, n] = e.split("-W"), r = J(+t).getTime() + (+n - 1) * H + 3 * z;
613
+ function At(e) {
614
+ const [t, n] = e.split("-W"), r = F(+t).getTime() + (+n - 1) * B + 3 * Q;
575
615
  return new Date(r);
576
616
  }
577
- function we(e) {
578
- return Q(e) ? St(e) : B(e) ? Rt(e) : K(e) ? pt(e) : F(e) ? vt(e) : j(e) ? Dt(e) : Nt(e);
617
+ function Ee(e) {
618
+ return U(e) ? St(e) : x(e) ? Tt(e) : k(e) ? Rt(e) : W(e) ? It(e) : q(e) ? Dt(e) : $t(e);
579
619
  }
580
- function pe(e) {
581
- return Q(e) ? Tt(e) : B(e) ? wt(e) : K(e) ? mt(e) : F(e) ? $t(e) : j(e) ? yt(e) : It(e);
620
+ function De(e) {
621
+ return U(e) ? yt(e) : x(e) ? vt(e) : k(e) ? wt(e) : W(e) ? Nt(e) : q(e) ? At(e) : Pt(e);
582
622
  }
583
623
  function St(e) {
584
- const t = M(e);
624
+ const t = C(e);
585
625
  if (t)
586
626
  return new Date(Number(t[0]), 0, 1);
587
627
  }
588
- function Tt(e) {
589
- const t = M(e);
628
+ function yt(e) {
629
+ const t = C(e);
590
630
  if (t)
591
631
  return new Date(Number(t[0]) + 1, 0, 1);
592
632
  }
593
- function Rt(e) {
633
+ function Tt(e) {
594
634
  const [t, n] = e.split("-S");
595
635
  switch (+n) {
596
636
  case 1:
@@ -599,7 +639,7 @@ function Rt(e) {
599
639
  return new Date(+t, 6, 1);
600
640
  }
601
641
  }
602
- function wt(e) {
642
+ function vt(e) {
603
643
  const [t, n] = e.split("-S");
604
644
  switch (+n) {
605
645
  case 1:
@@ -608,8 +648,8 @@ function wt(e) {
608
648
  return new Date(+t + 1, 0, 1);
609
649
  }
610
650
  }
611
- function pt(e) {
612
- const t = G(e);
651
+ function Rt(e) {
652
+ const t = V(e);
613
653
  if (!t)
614
654
  return;
615
655
  const [n, s] = t[0].split("-Q");
@@ -624,8 +664,8 @@ function pt(e) {
624
664
  return new Date(+n, 9, 1);
625
665
  }
626
666
  }
627
- function mt(e) {
628
- const t = G(e);
667
+ function wt(e) {
668
+ const t = V(e);
629
669
  if (!t)
630
670
  return;
631
671
  const [n, s] = t[0].split("-Q");
@@ -640,45 +680,45 @@ function mt(e) {
640
680
  return new Date(+n + 1, 0, 1);
641
681
  }
642
682
  }
643
- function vt(e) {
644
- const t = V(e);
683
+ function It(e) {
684
+ const t = Y(e);
645
685
  if (!t)
646
686
  return;
647
687
  const [n, s] = t[0].split("-M");
648
688
  return new Date(+n, +s - 1, 1);
649
689
  }
650
- function $t(e) {
651
- const t = V(e);
690
+ function Nt(e) {
691
+ const t = Y(e);
652
692
  if (!t)
653
693
  return;
654
694
  const [n, s] = t[0].split("-M");
655
695
  return new Date(+n, +s, 1);
656
696
  }
657
- const Nt = (e) => /* @__PURE__ */ new Date(`${e}T00:00:00`), It = (e) => {
697
+ const $t = (e) => /* @__PURE__ */ new Date(`${e}T00:00:00`), Pt = (e) => {
658
698
  const t = /* @__PURE__ */ new Date(`${e}T23:59:00`);
659
699
  return t.setMinutes(t.getMinutes() + 1), t;
660
- }, _t = 1, Pt = (e, t, n, s = !0, r = "Q") => {
661
- const o = [], i = t && t > 3 ? Ct(t, s) : 1, c = n ? Math.floor((n - 1) / 3) : 4;
662
- for (let a = i; a <= c; a++)
663
- o.push(`${e}-${r}${a}`);
700
+ }, bt = 1, _t = (e, t, n, s = !0, r = "Q") => {
701
+ const o = [], i = t && t > 3 ? Yt(t, s) : 1, a = n ? Math.floor((n - 1) / 3) : 4;
702
+ for (let c = i; c <= a; c++)
703
+ o.push(`${e}-${r}${c}`);
664
704
  return o;
665
705
  }, Ot = (e, t, n, s = "S") => {
666
706
  const r = [];
667
707
  return (t || 1) < 7 && (n || 12) > 6 && r.push(`${e}-${s}1`), n == null && r.push(`${e}-${s}2`), r;
668
- }, Nn = (e) => Math.ceil(e / 3), me = (e, t, n = "M") => `${e}-${n}${t.toString().padStart(2, "0")}`, Lt = (e, t, n = "M") => {
708
+ }, $n = (e) => Math.ceil(e / 3), Ae = (e, t, n = "M") => `${e}-${n}${t.toString().padStart(2, "0")}`, Lt = (e, t, n = "M") => {
669
709
  const s = [];
670
710
  for (let r = t; r <= 12; r++)
671
- s.push(me(e, r, n));
711
+ s.push(Ae(e, r, n));
672
712
  return s;
673
- }, bt = (e, t, n, s = "M") => {
713
+ }, Mt = (e, t, n, s = "M") => {
674
714
  const r = [];
675
715
  for (let o = t; o < n; o++)
676
- r.push(me(e, o, s));
716
+ r.push(Ae(e, o, s));
677
717
  return r;
678
- }, Ut = (e, t, n, s = "M") => {
718
+ }, Ct = (e, t, n, s = "M") => {
679
719
  const r = t || 1, o = n == null, i = n || 12;
680
- return o ? Lt(e, r, s) : bt(e, r, i, s);
681
- }, In = (e, t, n = "M") => {
720
+ return o ? Lt(e, r, s) : Mt(e, r, i, s);
721
+ }, Pn = (e, t, n = "M") => {
682
722
  switch (t) {
683
723
  case 0:
684
724
  return [
@@ -707,171 +747,162 @@ const Nt = (e) => /* @__PURE__ */ new Date(`${e}T00:00:00`), It = (e) => {
707
747
  default:
708
748
  return [];
709
749
  }
710
- }, xt = (e, t) => {
711
- const n = R(t, !0), s = R(e), r = n.getFullYear(), o = s.getFullYear(), i = n.getTime() <= s.getTime() ? o + _t - r : 0;
712
- return Array.from({ length: i }, (a, u) => r + u);
713
- }, R = (e, t = !1) => {
714
- const n = Yt(e, t);
750
+ }, Ut = (e, t) => {
751
+ const n = g(t, !0), s = g(e), r = n.getFullYear(), o = s.getFullYear(), i = n.getTime() <= s.getTime() ? o + bt - r : 0;
752
+ return Array.from({ length: i }, (c, u) => r + u);
753
+ }, g = (e, t = !1) => {
754
+ const n = xt(e, t);
715
755
  return n ? (n.getTimezoneOffset() > 0 && n.setMinutes(n.getMinutes() + n.getTimezoneOffset()), n) : /* @__PURE__ */ new Date();
716
- }, Yt = (e, t = !1) => {
756
+ }, xt = (e, t = !1) => {
717
757
  const n = Number(e);
718
- return e.toString().length !== 13 ? t ? we(e) : pe(e) : isNaN(n) ? /* @__PURE__ */ new Date(`${e}T00:00:00.000Z`) : new Date(n);
719
- }, Ct = (e, t) => t ? Math.floor((e + 1) / 3) : Math.ceil((e + 1) / 3), _n = (e, t) => {
720
- const n = ue(e) - ue(t);
758
+ return e.toString().length !== 13 ? t ? Ee(e) : De(e) : isNaN(n) ? /* @__PURE__ */ new Date(`${e}T00:00:00.000Z`) : new Date(n);
759
+ }, Yt = (e, t) => t ? Math.floor((e + 1) / 3) : Math.ceil((e + 1) / 3), bn = (e, t) => {
760
+ const n = re(e) - re(t);
721
761
  if (n === 0 && e !== t) {
722
- const s = ae(e), r = ae(t);
762
+ const s = se(e), r = se(t);
723
763
  return s - r;
724
764
  }
725
765
  return n;
726
- }, ae = (e) => Q(e) ? 6 : B(e) ? 5 : K(e) ? 4 : F(e) ? 3 : j(e) ? 2 : Et(e) ? 1 : 0, ue = (e, t = !1) => {
727
- const n = t ? we(e) : pe(e);
728
- return (n == null ? void 0 : n.getTime()) || 0;
729
- };
730
- var X = /* @__PURE__ */ ((e) => (e.LAST_UPDATE_AT = "lastUpdatedAt", e.SERIES_COUNT = "series_count", e))(X || {}), Wt = /* @__PURE__ */ ((e) => (e.C = "c", e))(Wt || {}), w = /* @__PURE__ */ ((e) => (e.EQUALS = "eq", e.NOT_EQUALS = "ne", e.LESS = "lt", e.LESS_OR_EQUAL = "le", e.GREATER = "gt", e.GREATER_OR_EQUAL = "ge", e.CONTAINS = "co", e.NOT_CONTAINS = "nc", e.STARTS = "sw", e.ENDS = "ew", e))(w || {}), kt = /* @__PURE__ */ ((e) => (e.BOOLEAN = "Boolean", e.DATE_TIME = "DateTime", e.DECIMAL = "Decimal", e.INTEGER = "Integer", e.OBSERVATION_TIME_PERIOD = "ObservationalTimePeriod", e.STRING = "String", e.TIME = "Time", e.TIME_RANGE = "TimeRange", e.URI = "URI", e))(kt || {}), qt = /* @__PURE__ */ ((e) => (e.ANNUAL = "A", e.QUARTERLY = "Q", e.MONTHLY = "M", e))(qt || {});
731
- function Pn(e) {
732
- var t, n;
733
- return (n = (t = e == null ? void 0 : e.annotations) == null ? void 0 : t.find((s) => {
734
- if (s.id === X.LAST_UPDATE_AT)
735
- return s;
736
- })) == null ? void 0 : n.value;
766
+ }, se = (e) => U(e) ? 6 : x(e) ? 5 : k(e) ? 4 : W(e) ? 3 : q(e) ? 2 : ht(e) ? 1 : 0, re = (e, t = !1) => (t ? Ee(e) : De(e))?.getTime() || 0;
767
+ var G = /* @__PURE__ */ ((e) => (e.LAST_UPDATE_AT = "lastUpdatedAt", e.SERIES_COUNT = "series_count", e))(G || {}), Wt = /* @__PURE__ */ ((e) => (e.C = "c", e))(Wt || {}), h = /* @__PURE__ */ ((e) => (e.EQUALS = "eq", e.NOT_EQUALS = "ne", e.LESS = "lt", e.LESS_OR_EQUAL = "le", e.GREATER = "gt", e.GREATER_OR_EQUAL = "ge", e.CONTAINS = "co", e.NOT_CONTAINS = "nc", e.STARTS = "sw", e.ENDS = "ew", e))(h || {}), Vt = /* @__PURE__ */ ((e) => (e.BOOLEAN = "Boolean", e.DATE_TIME = "DateTime", e.DECIMAL = "Decimal", e.INTEGER = "Integer", e.OBSERVATION_TIME_PERIOD = "ObservationalTimePeriod", e.STRING = "String", e.TIME = "Time", e.TIME_RANGE = "TimeRange", e.URI = "URI", e))(Vt || {}), kt = /* @__PURE__ */ ((e) => (e.ANNUAL = "A", e.QUARTERLY = "Q", e.MONTHLY = "M", e))(kt || {});
768
+ function _n(e) {
769
+ return e?.annotations?.find((t) => {
770
+ if (t.id === G.LAST_UPDATE_AT)
771
+ return t;
772
+ })?.value;
737
773
  }
738
- const Z = (e, t) => (e == null ? void 0 : e.names) && (e == null ? void 0 : e.names[t]) || (e == null ? void 0 : e.name), ve = (e, t, n) => {
739
- if (!(!e || t != null && t.has(e == null ? void 0 : e.id)) && (t == null || t.set(e == null ? void 0 : e.id, e), e != null && e.parent)) {
740
- const s = n == null ? void 0 : n.get(e == null ? void 0 : e.parent);
741
- ve(s, t, n);
774
+ const K = (e, t) => e?.names && e?.names[t] || e?.name, Se = (e, t, n) => {
775
+ if (!(!e || t?.has(e?.id)) && (t?.set(e?.id, e), e?.parent)) {
776
+ const s = n?.get(e?.parent);
777
+ Se(s, t, n);
742
778
  }
743
- }, Mt = (e, t) => {
744
- const n = /* @__PURE__ */ new Map(), s = new Map(e == null ? void 0 : e.map((r) => [r.id, r]));
745
- return t == null || t.forEach((r) => {
746
- ve(r, n, s);
747
- }), Array.from(n == null ? void 0 : n.values());
748
- }, Qt = "time_period_end", Bt = "time_period_start", Vt = "TIME_PERIOD", On = (e) => {
749
- const t = e == null ? void 0 : e.find(
779
+ }, qt = (e, t) => {
780
+ const n = /* @__PURE__ */ new Map(), s = new Map(e?.map((r) => [r.id, r]));
781
+ return t?.forEach((r) => {
782
+ Se(r, n, s);
783
+ }), Array.from(n?.values());
784
+ }, Qt = "time_period_end", Bt = "time_period_start", Ft = "TIME_PERIOD", On = (e) => {
785
+ const t = e?.find(
750
786
  (o) => o.id === Bt
751
- ), n = e == null ? void 0 : e.find(
787
+ ), n = e?.find(
752
788
  (o) => o.id === Qt
753
- ), s = n != null && n.title ? new Date(n == null ? void 0 : n.title) : null;
789
+ ), s = n?.title ? new Date(n?.title) : null;
754
790
  return {
755
- startPeriod: t != null && t.title ? new Date(t == null ? void 0 : t.title) : null,
791
+ startPeriod: t?.title ? new Date(t?.title) : null,
756
792
  endPeriod: s
757
793
  };
758
- }, Ft = (e, t) => e.id.localeCompare(t.id), Gt = (e, t) => e.memberValue.localeCompare(t.memberValue), Kt = (e, t) => {
759
- const n = new Array(e.length), s = e.map((i, c) => [i, c]);
794
+ }, Gt = (e, t) => e.id.localeCompare(t.id), Kt = (e, t) => e.memberValue.localeCompare(t.memberValue), jt = (e, t) => {
795
+ const n = new Array(e.length), s = e.map((i, a) => [i, a]);
760
796
  s.sort(
761
- (i, c) => Ft(i[0], c[0])
797
+ (i, a) => Gt(i[0], a[0])
762
798
  );
763
799
  const r = [...t];
764
- r.sort(Gt);
800
+ r.sort(Kt);
765
801
  let o = 0;
766
802
  for (const i of s) {
767
- const c = i[0];
768
- for (; o < r.length && r[o].memberValue.localeCompare(c.id) < 0; )
803
+ const a = i[0];
804
+ for (; o < r.length && r[o].memberValue.localeCompare(a.id) < 0; )
769
805
  o += 1;
770
- o < r.length && r[o].memberValue === c.id && (n[i[1]] = i[0]);
806
+ o < r.length && r[o].memberValue === a.id && (n[i[1]] = i[0]);
771
807
  }
772
808
  return n.filter((i) => i != null);
773
- }, jt = (e) => !!(e != null && e.some((t) => t.parent)), Ln = (e, t, n, s, r = []) => {
774
- var i, c;
809
+ }, Ht = (e) => !!e?.some((t) => t.parent), Ln = (e, t, n, s, r = []) => {
775
810
  let o = e || [];
776
811
  if (zt(n || [], t || "")) {
777
- const a = (i = (n || [])[0].cubeRegions) == null ? void 0 : i.find(
778
- ({ isIncluded: u }) => u
812
+ const i = (n || [])[0].cubeRegions?.find(
813
+ ({ isIncluded: a }) => a
779
814
  );
780
- if (a) {
781
- const u = (c = a.memberSelection) == null ? void 0 : c.find(
782
- ({ componentId: l }) => l === t
815
+ if (i) {
816
+ const a = i.memberSelection?.find(
817
+ ({ componentId: c }) => c === t
783
818
  );
784
- u ? o = o.length === 0 ? (u.selectionValues || []).map(({ memberValue: l }) => ({
785
- id: l,
786
- name: l
787
- })) : Kt(o, u.selectionValues) : o = [];
819
+ a ? o = o.length === 0 ? (a.selectionValues || []).map(({ memberValue: c }) => ({
820
+ id: c,
821
+ name: c
822
+ })) : jt(o, a.selectionValues) : o = [];
788
823
  }
789
- } else r.length !== 0 && (o = o.filter(({ id: a }) => r.includes(a)));
790
- return jt(e) && (o = Mt(e, o)), o == null ? void 0 : o.map((a) => ({
791
- ...a,
792
- name: s ? Z(a, s) : a == null ? void 0 : a.name
824
+ } else r.length !== 0 && (o = o.filter(({ id: i }) => r.includes(i)));
825
+ return Ht(e) && (o = qt(e, o)), o?.map((i) => ({
826
+ ...i,
827
+ name: s ? K(i, s) : i?.name
793
828
  }));
794
- }, zt = (e, t) => e != null && e.length > 0 && t != null, bn = (e) => {
795
- var n;
829
+ }, zt = (e, t) => e != null && e.length > 0 && t != null, Mn = (e) => {
796
830
  const t = [];
797
- return (n = e == null ? void 0 : e.filters) == null || n.forEach((s) => {
798
- s.componentCode !== Vt && t.push({
799
- componentCode: s.componentCode,
800
- operator: w.EQUALS,
801
- value: s.values.join(",")
831
+ return e?.filters?.forEach((n) => {
832
+ n.componentCode !== Ft && t.push({
833
+ componentCode: n.componentCode,
834
+ operator: h.EQUALS,
835
+ value: n.values.join(",")
802
836
  });
803
837
  }), t;
804
- }, Ht = /^[v^~<>=]*?(\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+))?(?:-([\da-z\-]+(?:\.[\da-z\-]+)*))?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i, le = (e) => {
838
+ }, Jt = /^[v^~<>=]*?(\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+))?(?:-([\da-z\-]+(?:\.[\da-z\-]+)*))?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i, oe = (e) => {
805
839
  if (typeof e != "string")
806
840
  throw new TypeError("Invalid argument expected string");
807
- const t = e.match(Ht);
841
+ const t = e.match(Jt);
808
842
  if (!t)
809
843
  throw new Error(`Invalid argument not valid semver ('${e}' received)`);
810
844
  return t.shift(), t;
811
- }, de = (e) => e === "*" || e === "x" || e === "X", fe = (e) => {
845
+ }, ie = (e) => e === "*" || e === "x" || e === "X", ae = (e) => {
812
846
  const t = parseInt(e, 10);
813
847
  return isNaN(t) ? e : t;
814
- }, Jt = (e, t) => typeof e != typeof t ? [String(e), String(t)] : [e, t], Xt = (e, t) => {
815
- if (de(e) || de(t))
848
+ }, Xt = (e, t) => typeof e != typeof t ? [String(e), String(t)] : [e, t], Zt = (e, t) => {
849
+ if (ie(e) || ie(t))
816
850
  return 0;
817
- const [n, s] = Jt(fe(e), fe(t));
851
+ const [n, s] = Xt(ae(e), ae(t));
818
852
  return n > s ? 1 : n < s ? -1 : 0;
819
- }, ge = (e, t) => {
853
+ }, ce = (e, t) => {
820
854
  for (let n = 0; n < Math.max(e.length, t.length); n++) {
821
- const s = Xt(e[n] || "0", t[n] || "0");
855
+ const s = Zt(e[n] || "0", t[n] || "0");
822
856
  if (s !== 0)
823
857
  return s;
824
858
  }
825
859
  return 0;
826
- }, Zt = (e, t) => {
827
- const n = le(e), s = le(t), r = n.pop(), o = s.pop(), i = ge(n, s);
828
- return i !== 0 ? i : r && o ? ge(r.split("."), o.split(".")) : r || o ? r ? -1 : 1 : 0;
829
- }, en = (e, t, n) => {
830
- tn(n);
831
- const s = Zt(e, t);
832
- return $e[n].includes(s);
833
- }, $e = {
860
+ }, en = (e, t) => {
861
+ const n = oe(e), s = oe(t), r = n.pop(), o = s.pop(), i = ce(n, s);
862
+ return i !== 0 ? i : r && o ? ce(r.split("."), o.split(".")) : r || o ? r ? -1 : 1 : 0;
863
+ }, tn = (e, t, n) => {
864
+ nn(n);
865
+ const s = en(e, t);
866
+ return ye[n].includes(s);
867
+ }, ye = {
834
868
  ">": [1],
835
869
  ">=": [0, 1],
836
870
  "=": [0],
837
871
  "<=": [-1, 0],
838
872
  "<": [-1],
839
873
  "!=": [-1, 1]
840
- }, Ee = Object.keys($e), tn = (e) => {
841
- if (Ee.indexOf(e) === -1)
842
- throw new Error(`Invalid operator, expected one of ${Ee.join("|")}`);
843
- }, W = "+", ee = (e, t) => {
844
- const { agency: n, id: s, version: r } = p(e), o = t.filter(
845
- (a) => {
846
- var u;
847
- return a.agencyID === n && a.id === s && !((u = a == null ? void 0 : a.version) != null && u.includes(W));
848
- }
874
+ }, ue = Object.keys(ye), nn = (e) => {
875
+ if (ue.indexOf(e) === -1)
876
+ throw new Error(`Invalid operator, expected one of ${ue.join("|")}`);
877
+ }, O = "+", j = (e, t) => {
878
+ const { agency: n, id: s, version: r } = D(e), o = t.filter(
879
+ (c) => c.agencyID === n && c.id === s && !c?.version?.includes(O)
849
880
  );
850
881
  if (o.length === 1)
851
882
  return o[0];
852
- if (!(r != null && r.includes(W)))
853
- return o.find((a) => a.version === r);
883
+ if (!r?.includes(O))
884
+ return o.find((c) => c.version === r);
854
885
  const i = o.map(
855
- (a) => a.version
856
- ), c = nn(r, i);
886
+ (c) => c.version
887
+ ), a = sn(r, i);
857
888
  return o.find(
858
- (a) => a.version === c[0]
889
+ (c) => c.version === a[0]
859
890
  );
860
- }, nn = (e, t) => {
861
- const n = sn(e, t);
862
- return n.length > 0 ? [n[0]] : [];
863
891
  }, sn = (e, t) => {
892
+ const n = rn(e, t);
893
+ return n.length > 0 ? [n[0]] : [];
894
+ }, rn = (e, t) => {
864
895
  const n = [];
865
896
  return t.forEach((s) => {
866
- on(e, s) && n.push(s);
897
+ an(e, s) && n.push(s);
867
898
  }), n;
868
- }, rn = (e) => {
899
+ }, on = (e) => {
869
900
  const t = e.trim().replace(/\d+\+/, "*"), [n] = t.split("*");
870
901
  return new RegExp(`^${n}`);
871
- }, on = (e, t) => {
902
+ }, an = (e, t) => {
872
903
  const n = e.trim().replace(/\+/, "");
873
- return rn(e).test(t) && en(t, n, ">=");
874
- }, te = (e, t) => {
904
+ return on(e).test(t) && tn(t, n, ">=");
905
+ }, H = (e, t) => {
875
906
  const { concept: n } = cn(e, t);
876
907
  return n;
877
908
  }, cn = (e, t) => {
@@ -880,116 +911,104 @@ const Z = (e, t) => (e == null ? void 0 : e.names) && (e == null ? void 0 : e.na
880
911
  concept: void 0,
881
912
  scheme: void 0
882
913
  };
883
- const { childId: n, agency: s, id: r, version: o } = Pe(e);
884
- if (o != null && o.includes(W)) {
885
- const i = ee(
914
+ const { childId: n, agency: s, id: r, version: o } = we(e);
915
+ if (o?.includes(O)) {
916
+ const i = j(
886
917
  e,
887
918
  t
888
919
  );
889
920
  return {
890
- concept: he((i == null ? void 0 : i.concepts) || [], n),
921
+ concept: de(i?.concepts || [], n),
891
922
  scheme: i
892
923
  };
893
924
  }
894
925
  for (const i of t)
895
- if (an(i, r, s, o))
926
+ if (un(i, r, s, o))
896
927
  return {
897
- concept: he((i == null ? void 0 : i.concepts) || [], n),
928
+ concept: de(i?.concepts || [], n),
898
929
  scheme: i
899
930
  };
900
931
  return {
901
932
  concept: void 0,
902
933
  scheme: void 0
903
934
  };
904
- }, he = (e, t) => e == null ? void 0 : e.find((n) => n.id === t), an = (e, t, n, s) => e.id === t && e.agencyID === n && e.version === s, Un = (e = [], t = [], n) => {
905
- var a, u;
906
- const s = (n == null ? void 0 : n.conceptIdentity) || "", r = te(s, t), o = I(
907
- (a = n == null ? void 0 : n.localRepresentation) == null ? void 0 : a.enumeration
908
- ), i = I(
909
- (u = r == null ? void 0 : r.coreRepresentation) == null ? void 0 : u.enumeration
910
- ), c = o || i;
911
- if (c != null)
912
- return ee(c, e);
913
- }, xn = (e, t, n, s) => {
914
- var o, i;
915
- const r = (o = t == null ? void 0 : t.find(
916
- (c) => (c == null ? void 0 : c.id) === (e == null ? void 0 : e.id)
917
- )) == null ? void 0 : o.values;
918
- return ((i = n == null ? void 0 : n.filter((c) => r == null ? void 0 : r.some((a) => a.id === c.id))) == null ? void 0 : i.map((c) => ({
919
- ...c,
920
- name: s ? Z(c, s) : c == null ? void 0 : c.name
921
- }))) || [];
922
- }, un = (e, t) => {
923
- var r, o, i;
924
- const n = (r = t == null ? void 0 : t.dataStructureComponents) == null ? void 0 : r.attributeList, s = (o = e == null ? void 0 : e.metadataStructureComponents) == null ? void 0 : o.metadataAttributeList;
925
- return (i = n == null ? void 0 : n.metadataAttributeUsages) == null ? void 0 : i.map((c) => {
926
- var u;
927
- const a = (u = s == null ? void 0 : s.metadataAttributes) == null ? void 0 : u.find(
928
- (l) => (l == null ? void 0 : l.id) === (c == null ? void 0 : c.metadataAttributeReference)
935
+ }, de = (e, t) => e?.find((n) => n.id === t), un = (e, t, n, s) => e.id === t && e.agencyID === n && e.version === s, Cn = (e = [], t = [], n) => {
936
+ const s = n?.conceptIdentity || "", r = H(s, t), o = v(
937
+ n?.localRepresentation?.enumeration
938
+ ), i = v(
939
+ r?.coreRepresentation?.enumeration
940
+ ), a = o || i;
941
+ if (a != null)
942
+ return j(a, e);
943
+ }, Un = (e, t, n, s) => {
944
+ const r = t?.find(
945
+ (o) => o?.id === e?.id
946
+ )?.values;
947
+ return n?.filter((o) => r?.some((i) => i.id === o.id))?.map((o) => ({
948
+ ...o,
949
+ name: s ? K(o, s) : o?.name
950
+ })) || [];
951
+ }, dn = (e, t) => {
952
+ const n = t?.dataStructureComponents?.attributeList, s = e?.metadataStructureComponents?.metadataAttributeList;
953
+ return n?.metadataAttributeUsages?.map((r) => {
954
+ const o = s?.metadataAttributes?.find(
955
+ (i) => i?.id === r?.metadataAttributeReference
929
956
  );
930
957
  return {
931
- ...a,
932
- attributeRelationship: c.attributeRelationship,
933
- isMandatory: Number(a == null ? void 0 : a.minOccurs) > 0
958
+ ...o,
959
+ attributeRelationship: r.attributeRelationship,
960
+ isMandatory: Number(o?.minOccurs) > 0
934
961
  };
935
962
  });
936
- }, Yn = (e = [], t, n) => {
937
- const s = I(t == null ? void 0 : t.conceptIdentity) || "", r = te(s, e);
938
- return n ? Z(r, n) : (r == null ? void 0 : r.name) ?? (r == null ? void 0 : r.id) ?? (t == null ? void 0 : t.id);
963
+ }, xn = (e = [], t, n) => {
964
+ const s = v(t?.conceptIdentity) || "", r = H(s, e);
965
+ return n ? K(r, n) : r?.name ?? r?.id ?? t?.id;
939
966
  };
940
- function Ae(e) {
941
- var t, n, s;
942
- return (s = (n = (t = e == null ? void 0 : e.dataStructures) == null ? void 0 : t[0]) == null ? void 0 : n.dataStructureComponents) == null ? void 0 : s.dimensionList;
967
+ function le(e) {
968
+ return e?.dataStructures?.[0]?.dataStructureComponents?.dimensionList;
943
969
  }
944
- function Cn(e) {
945
- var t, n, s, r;
946
- return ((r = (s = (n = (t = e == null ? void 0 : e.data) == null ? void 0 : t.structures) == null ? void 0 : n[0]) == null ? void 0 : s.dimensions) == null ? void 0 : r.series) || [];
970
+ function Yn(e) {
971
+ return e?.data?.structures?.[0]?.dimensions?.series || [];
947
972
  }
948
973
  function Wn(e) {
949
- var t, n, s, r, o;
950
- return ((o = (r = (s = (n = (t = e == null ? void 0 : e.data) == null ? void 0 : t.structures) == null ? void 0 : n[0]) == null ? void 0 : s.dimensions) == null ? void 0 : r.observation) == null ? void 0 : o[0].values.map((i) => i.value).filter((i) => i != null)) || [];
974
+ return e?.data?.structures?.[0]?.dimensions?.observation?.[0].values.map((t) => t.value).filter((t) => t != null) || [];
951
975
  }
952
- function kn(e) {
976
+ function Vn(e) {
953
977
  return e.find(
954
- (t) => t.type === q.TIME_DIMENSION
978
+ (t) => t.type === M.TIME_DIMENSION
955
979
  );
956
980
  }
957
- const qn = (e) => {
958
- var i, c, a, u, l, f;
959
- const t = /* @__PURE__ */ new Map(), n = (i = e == null ? void 0 : e.dataStructures) == null ? void 0 : i[0], s = (c = e == null ? void 0 : e.metadataStructures) == null ? void 0 : c[0], r = (e == null ? void 0 : e.conceptSchemes) || [], o = (e == null ? void 0 : e.codelists) || [];
981
+ const kn = (e) => {
982
+ const t = /* @__PURE__ */ new Map(), n = e?.dataStructures?.[0], s = e?.metadataStructures?.[0], r = e?.conceptSchemes || [], o = e?.codelists || [];
960
983
  return e && [
961
- ...((a = Ae(e)) == null ? void 0 : a.dimensions) || [],
962
- ...((u = Ae(e)) == null ? void 0 : u.timeDimensions) || [],
963
- ...un(s, n),
964
- ...((f = (l = n == null ? void 0 : n.dataStructureComponents) == null ? void 0 : l.attributeList) == null ? void 0 : f.attributes) || []
984
+ ...le(e)?.dimensions || [],
985
+ ...le(e)?.timeDimensions || [],
986
+ ...dn(s, n),
987
+ ...n?.dataStructureComponents?.attributeList?.attributes || []
965
988
  ].forEach(
966
- (d) => {
967
- var A, y;
968
- const g = te(
969
- d == null ? void 0 : d.conceptIdentity,
989
+ (a) => {
990
+ const c = H(
991
+ a?.conceptIdentity,
970
992
  r
971
- ), h = ((A = d == null ? void 0 : d.localRepresentation) == null ? void 0 : A.enumeration) || ((y = g == null ? void 0 : g.coreRepresentation) == null ? void 0 : y.enumeration), D = ee(
972
- h,
993
+ ), u = a?.localRepresentation?.enumeration || c?.coreRepresentation?.enumeration, d = j(
994
+ u,
973
995
  o
974
996
  );
975
- d != null && d.id && (h ? t.set(d == null ? void 0 : d.id, {
976
- ...D,
977
- name: g == null ? void 0 : g.name,
978
- names: g == null ? void 0 : g.names
979
- }) : t.set(d == null ? void 0 : d.id, {
980
- id: d == null ? void 0 : d.id,
981
- name: g == null ? void 0 : g.name,
982
- names: g == null ? void 0 : g.names
997
+ a?.id && (u ? t.set(a?.id, {
998
+ ...d,
999
+ name: c?.name,
1000
+ names: c?.names
1001
+ }) : t.set(a?.id, {
1002
+ id: a?.id,
1003
+ name: c?.name,
1004
+ names: c?.names
983
1005
  }));
984
1006
  }
985
1007
  ), t;
986
- }, Mn = (e) => {
987
- var t;
988
- return ((t = e == null ? void 0 : e.find(
989
- (n) => n.id === X.SERIES_COUNT
990
- )) == null ? void 0 : t.title) || "";
991
- }, ln = "/api/download", Qn = (e, t, n, s, r, o, i) => {
992
- const c = new URLSearchParams({
1008
+ }, qn = (e) => e?.find(
1009
+ (t) => t.id === G.SERIES_COUNT
1010
+ )?.title || "", ln = "/api/download", Qn = (e, t, n, s, r, o, i) => {
1011
+ const a = new URLSearchParams({
993
1012
  urn: e,
994
1013
  format: t,
995
1014
  compress: "false",
@@ -998,233 +1017,242 @@ const qn = (e) => {
998
1017
  attribute: s,
999
1018
  language: n,
1000
1019
  isMetadata: i ? "true" : "none"
1001
- }).toString(), a = `${ln}?${c}`;
1002
- window.open(a, "_blank");
1020
+ }).toString(), c = `${ln}?${a}`;
1021
+ window.open(c, "_blank");
1003
1022
  }, Bn = (e, t) => {
1004
- var s, r;
1005
1023
  const n = [];
1006
- for (const o of e) {
1007
- if (o.type !== q.DIMENSION)
1024
+ for (const s of e) {
1025
+ if (s.type !== M.DIMENSION)
1008
1026
  continue;
1009
- const i = t.find((c) => c.componentCode === o.id);
1010
- i != null && ((s = i.values) == null ? void 0 : s.length) > 0 ? n.push((r = i.values) == null ? void 0 : r.join(We)) : n.push("*");
1027
+ const r = t.find((o) => o.componentCode === s.id);
1028
+ r != null && r.values?.length > 0 ? n.push(r.values?.join(We)) : n.push("*");
1011
1029
  }
1012
1030
  return n.join(".");
1013
- }, dn = (e, t) => {
1031
+ }, mn = (e, t) => {
1014
1032
  if (!e || !e.startPeriod && !e.endPeriod)
1015
1033
  return null;
1016
1034
  const n = [], { startPeriod: s, endPeriod: r } = e;
1017
1035
  if (s && n.push(
1018
- `${w.GREATER_OR_EQUAL}${se}${s.toISOString().split("T")[0]}`
1036
+ `${h.GREATER_OR_EQUAL}${J}${s.toISOString().split("T")[0]}`
1019
1037
  ), r && n.push(
1020
- `${w.LESS_OR_EQUAL}${se}${r.toISOString().split("T")[0]}`
1038
+ `${h.LESS_OR_EQUAL}${J}${r.toISOString().split("T")[0]}`
1021
1039
  ), n.length === 0)
1022
1040
  return null;
1023
1041
  const o = t;
1024
1042
  return n.map(
1025
- (i) => `${encodeURIComponent(`c[${o}]`)}${Ce}${encodeURIComponent(i)}`
1026
- ).join(Se);
1027
- }, Vn = (e, t) => {
1043
+ (i) => `${encodeURIComponent(`c[${o}]`)}${Ye}${encodeURIComponent(i)}`
1044
+ ).join(ge);
1045
+ }, Fn = (e, t) => {
1028
1046
  const n = fn(e, t) || null;
1029
- return n ? dn(n, t == null ? void 0 : t.id) : null;
1047
+ return n ? mn(n, t?.id) : null;
1030
1048
  }, fn = (e, t) => {
1031
- var a, u;
1032
- const n = t.id, s = (a = e == null ? void 0 : e.filters) == null ? void 0 : a.find(
1033
- (l) => l.componentCode === n
1049
+ const n = t.id, s = e?.filters?.find(
1050
+ (c) => c.componentCode === n
1034
1051
  );
1035
1052
  if (!s || !s.values)
1036
1053
  return null;
1037
- const r = (u = s.values) == null ? void 0 : u.filter((l) => !!l);
1054
+ const r = s.values?.filter((c) => !!c);
1038
1055
  if (!r.length)
1039
1056
  return null;
1040
1057
  const o = s.operator;
1041
- if (o === w.LESS_OR_EQUAL || o === w.LESS)
1042
- return { startPeriod: null, endPeriod: v(r[0]) };
1043
- if (o === w.GREATER_OR_EQUAL || o === w.GREATER)
1044
- return { startPeriod: v(r[0]), endPeriod: null };
1045
- const i = v(r[0]), c = v(r[1]);
1046
- return { startPeriod: i, endPeriod: c };
1047
- }, Ne = (e, t, n) => {
1048
- const s = R(t, !0), r = R(n), o = R(e, !0), i = R(e), c = s.getTime() > o.getTime() ? s : o, a = r.getTime() < i.getTime() ? r : i;
1058
+ if (o === h.LESS_OR_EQUAL || o === h.LESS)
1059
+ return { startPeriod: null, endPeriod: S(r[0]) };
1060
+ if (o === h.GREATER_OR_EQUAL || o === h.GREATER)
1061
+ return { startPeriod: S(r[0]), endPeriod: null };
1062
+ const i = S(r[0]), a = S(r[1]);
1063
+ return { startPeriod: i, endPeriod: a };
1064
+ }, Te = (e, t, n) => {
1065
+ const s = g(t, !0), r = g(n), o = g(e, !0), i = g(e), a = s.getTime() > o.getTime() ? s : o, c = r.getTime() < i.getTime() ? r : i;
1049
1066
  return {
1050
- start: c,
1051
- end: a
1067
+ start: a,
1068
+ end: c
1052
1069
  };
1053
1070
  }, gn = (e, t, n, s = "W") => {
1054
- const r = +e, { start: o, end: i } = Ne(e, t, n);
1071
+ const r = +e, { start: o, end: i } = Te(e, t, n);
1055
1072
  if (o.getTime() > i.getTime())
1056
1073
  return [];
1057
- const c = _(o, s), a = c.weekYear === r ? c.weekNumber : c.weekYear < r ? 1 : ce(r, s), u = _(i, s), l = u.weekYear === r ? u.weekNumber : u.weekYear > r ? ce(r, s) : 1, f = [];
1058
- if (a < l)
1059
- for (let E = a; E <= l; E++)
1060
- f.push(Re(r, E, s));
1061
- return f;
1062
- }, En = (e) => {
1074
+ const a = R(o, s), c = a.weekYear === r ? a.weekNumber : a.weekYear < r ? 1 : ne(r, s), u = R(i, s), d = u.weekYear === r ? u.weekNumber : u.weekYear > r ? ne(r, s) : 1, l = [];
1075
+ if (c < d)
1076
+ for (let m = c; m <= d; m++)
1077
+ l.push(pe(r, m, s));
1078
+ return l;
1079
+ }, hn = (e) => {
1063
1080
  const t = new Date(e);
1064
1081
  return t.setMinutes(t.getMinutes() - t.getTimezoneOffset()), t.toISOString().slice(0, 10);
1065
- }, hn = (e, t, n) => {
1066
- const { start: s, end: r } = Ne(e, t, n);
1082
+ }, pn = (e, t, n) => {
1083
+ const { start: s, end: r } = Te(e, t, n);
1067
1084
  if (s.getTime() > r.getTime())
1068
1085
  return [];
1069
1086
  const o = [], i = new Date(
1070
1087
  s.getFullYear(),
1071
1088
  s.getMonth(),
1072
1089
  s.getDate()
1073
- ), c = new Date(r.getFullYear(), r.getMonth(), r.getDate());
1074
- for (; i.getTime() < c.getTime(); ) {
1075
- const a = En(i);
1076
- o.push(a), i.setDate(i.getDate() + 1);
1090
+ ), a = new Date(r.getFullYear(), r.getMonth(), r.getDate());
1091
+ for (; i.getTime() < a.getTime(); ) {
1092
+ const c = hn(i);
1093
+ o.push(c), i.setDate(i.getDate() + 1);
1077
1094
  }
1078
1095
  return o;
1079
- }, An = (e) => ({
1080
- isDailyExist: !!(e != null && e.some(({ memberValue: t }) => t === "D")),
1081
- isWeeklyExist: !!(e != null && e.some(({ memberValue: t }) => t === "W")),
1082
- isMonthlyExist: !!(e != null && e.some(({ memberValue: t }) => t === "M")),
1083
- isQuarterlyExist: !!(e != null && e.some(({ memberValue: t }) => t === "Q")),
1084
- isSemiAnnualExist: !!(e != null && e.some(({ memberValue: t }) => t === "S")),
1085
- isYearlyExist: !!(e != null && e.some(
1096
+ }, En = (e) => ({
1097
+ isDailyExist: !!e?.some(({ memberValue: t }) => t === "D"),
1098
+ isWeeklyExist: !!e?.some(({ memberValue: t }) => t === "W"),
1099
+ isMonthlyExist: !!e?.some(({ memberValue: t }) => t === "M"),
1100
+ isQuarterlyExist: !!e?.some(({ memberValue: t }) => t === "Q"),
1101
+ isSemiAnnualExist: !!e?.some(({ memberValue: t }) => t === "S"),
1102
+ isYearlyExist: !!e?.some(
1086
1103
  ({ memberValue: t }) => t === "A" || t === "Y"
1087
- ))
1104
+ )
1088
1105
  }), Dn = (e, t, n, s) => {
1089
- var i, c;
1090
- const r = s === 0 ? ((i = R(t.toString(), !0)) == null ? void 0 : i.getMonth()) + 1 : void 0, o = s === e.length - 1 ? ((c = R(n.toString())) == null ? void 0 : c.getMonth()) + 1 || 1 : void 0;
1106
+ const r = s === 0 ? g(t.toString(), !0)?.getMonth() + 1 : void 0, o = s === e.length - 1 ? g(n.toString())?.getMonth() + 1 || 1 : void 0;
1091
1107
  return { startMonth: r, endMonth: o };
1092
- }, yn = ["FREQUENCY", "FREQ"], Fn = (e, t) => {
1093
- var a, u, l, f, E, d, g;
1094
- const n = (E = (f = (l = (u = (a = e == null ? void 0 : e[0]) == null ? void 0 : a.cubeRegions) == null ? void 0 : u[0]) == null ? void 0 : l.memberSelection) == null ? void 0 : f.find(
1095
- (h) => yn.includes(h.componentId)
1096
- )) == null ? void 0 : E.selectionValues, s = An(n || []), r = ((d = t == null ? void 0 : t.startPeriod) == null ? void 0 : d.getTime()) || 1, o = ((g = t == null ? void 0 : t.endPeriod) == null ? void 0 : g.getTime()) || 1, i = xt(o, r), c = [];
1097
- return i.forEach((h, D) => {
1098
- const A = [], { startMonth: y, endMonth: S } = Dn(
1108
+ }, An = ["FREQUENCY", "FREQ"], Gn = (e, t) => {
1109
+ const n = e?.[0]?.cubeRegions?.[0]?.memberSelection?.find(
1110
+ (c) => An.includes(c.componentId)
1111
+ )?.selectionValues, s = En(n || []), r = t?.startPeriod?.getTime() || 1, o = t?.endPeriod?.getTime() || 1, i = Ut(o, r), a = [];
1112
+ return i.forEach((c, u) => {
1113
+ const d = [], { startMonth: l, endMonth: m } = Dn(
1099
1114
  i,
1100
1115
  new Date(r),
1101
1116
  new Date(o),
1102
- D
1117
+ u
1103
1118
  ), {
1104
- isDailyExist: P,
1105
- isWeeklyExist: O,
1106
- isMonthlyExist: L,
1107
- isQuarterlyExist: b,
1108
- isSemiAnnualExist: U,
1109
- isYearlyExist: T
1119
+ isDailyExist: f,
1120
+ isWeeklyExist: p,
1121
+ isMonthlyExist: w,
1122
+ isQuarterlyExist: I,
1123
+ isSemiAnnualExist: N,
1124
+ isYearlyExist: $
1110
1125
  } = s;
1111
- T && A.push(h.toString()), U && A.push(...Ot(h, y, S)), b && A.push(
1112
- ...Pt(h, y, S, !1)
1113
- ), L && A.push(...Ut(h, y, S)), O && A.push(
1114
- ...gn(h, r.toString(), o.toString())
1115
- ), P && A.push(
1116
- ...hn(h, r.toString(), o.toString())
1117
- ), c.push(...A);
1118
- }), c;
1126
+ $ && d.push(c.toString()), N && d.push(...Ot(c, l, m)), I && d.push(
1127
+ ..._t(c, l, m, !1)
1128
+ ), w && d.push(...Ct(c, l, m)), p && d.push(
1129
+ ...gn(c, r.toString(), o.toString())
1130
+ ), f && d.push(
1131
+ ...pn(c, r.toString(), o.toString())
1132
+ ), a.push(...d);
1133
+ }), a;
1119
1134
  };
1135
+ function Sn(e) {
1136
+ const { urn: t } = e.details;
1137
+ return Ie(t.resourceId, t.version, t.agencyId);
1138
+ }
1139
+ function Kn(e) {
1140
+ const t = {};
1141
+ for (const n of e.datasets) {
1142
+ const s = n.dataset, r = Sn(s);
1143
+ t[r] = s.details.dimensions;
1144
+ }
1145
+ return t;
1146
+ }
1120
1147
  export {
1121
- X as Annotations,
1122
- je as AssignmentStatus,
1123
- Tn as AvailabilityApi,
1124
- Ye as DATASET_DATA_URL,
1125
- wn as DatasetApi,
1126
- q as DimensionType,
1127
- be as DownloadType,
1128
- mn as FREQUENCY_DIMENSION_ID,
1129
- yn as FREQUENCY_DIM_ID,
1148
+ G as Annotations,
1149
+ He as AssignmentStatus,
1150
+ yn as AvailabilityApi,
1151
+ xe as DATASET_DATA_URL,
1152
+ vn as DatasetApi,
1153
+ M as DimensionType,
1154
+ Me as DownloadType,
1155
+ wn as FREQUENCY_DIMENSION_ID,
1156
+ An as FREQUENCY_DIM_ID,
1130
1157
  Le as FileColumnsAttribute,
1131
- ke as GET_v3_FILTER_ALL,
1132
- Rn as GET_v3_FILTER_AND,
1158
+ Ve as GET_v3_FILTER_ALL,
1159
+ Tn as GET_v3_FILTER_AND,
1133
1160
  We as GET_v3_FILTER_OR,
1134
- Xe as OBSERVATION_KEY,
1161
+ Ze as OBSERVATION_KEY,
1135
1162
  ze as OccurrenceType,
1136
- qt as Periods,
1137
- kt as RepresentationTextType,
1163
+ kt as Periods,
1164
+ Vt as RepresentationTextType,
1138
1165
  Wt as SDMX_DATA_QUERY_PARAMS,
1139
- W as SINGLE_WILDCARD_SYMBOL,
1140
- pn as SdmxApiClient,
1141
- De as SdmxAvailabilityMode,
1142
- $ as SdmxDataFormat,
1143
- ye as SdmxDetails,
1144
- k as SdmxReferences,
1145
- w as SeriesFilterOperator,
1146
- Vt as TIME_PERIOD,
1166
+ O as SINGLE_WILDCARD_SYMBOL,
1167
+ Rn as SdmxApiClient,
1168
+ me as SdmxAvailabilityMode,
1169
+ y as SdmxDataFormat,
1170
+ fe as SdmxDetails,
1171
+ L as SdmxReferences,
1172
+ h as SeriesFilterOperator,
1173
+ Ft as TIME_PERIOD,
1147
1174
  Qt as TIME_PERIOD_END,
1148
1175
  Bt as TIME_PERIOD_START,
1176
+ Kn as buildDatasetDimensionsMetadataMap,
1149
1177
  lt as dailyPattern,
1150
- nt as decodeDimensionId,
1151
- Un as findCodelistByDimension,
1152
- re as generateDatasetDataRequest,
1153
- Sn as generateShortUrn,
1154
- Fn as getAdditionalColumns,
1178
+ st as decodeDimensionId,
1179
+ Cn as findCodelistByDimension,
1180
+ X as generateDatasetDataRequest,
1181
+ Ie as generateShortUrn,
1182
+ Gn as getAdditionalColumns,
1155
1183
  On as getAnnotationPeriod,
1156
- ee as getArtifactByUrnWithWildCard,
1157
- vn as getAttachedDimensionsSeriesByDimension,
1158
- He as getAttachedDimensionsSeriesByTsId,
1159
- Te as getAttachedDimensionsSeriesKey,
1160
- Je as getAttributeValueFromDataQueryResponse,
1161
- xn as getAvailableCodes,
1184
+ j as getArtifactByUrnWithWildCard,
1185
+ In as getAttachedDimensionsSeriesByDimension,
1186
+ Je as getAttachedDimensionsSeriesByTsId,
1187
+ he as getAttachedDimensionsSeriesKey,
1188
+ Xe as getAttributeValueFromDataQueryResponse,
1189
+ Un as getAvailableCodes,
1162
1190
  Ln as getAvailableCodesFromConstrains,
1163
- Pe as getChildParsedUrn,
1164
- te as getConcept,
1165
- he as getConceptByUrn,
1191
+ we as getChildParsedUrn,
1192
+ H as getConcept,
1193
+ de as getConceptByUrn,
1166
1194
  cn as getConceptWithScheme,
1167
- un as getConvertedMetaAttributes,
1195
+ dn as getConvertedMetaAttributes,
1168
1196
  gt as getDailyRegExp,
1169
- hn as getDaysColumns,
1170
- Yn as getDimensionTitle,
1171
- Ae as getDimensions,
1172
- Mt as getFilteredItemsWithParents,
1173
- bn as getFiltersDtoFromDataQuery,
1174
- _ as getISOWeek,
1175
- I as getKeyFromUrn,
1176
- Pn as getLastUpdatedTime,
1177
- ce as getLastWeekNumberOfYear,
1178
- Z as getLocalizedName,
1179
- Ut as getMonthlyData,
1180
- In as getMonthlyDataByQuarter,
1181
- V as getMonthlyRegExp,
1182
- pe as getParsedEndPeriodDate,
1183
- $n as getParsedResponse,
1184
- we as getParsedStartPeriodDate,
1185
- R as getPeriodDate,
1186
- An as getPeriods,
1187
- Nn as getQuarterByMonth,
1188
- G as getQuarterlyRegExp,
1189
- Pt as getQuartersData,
1190
- dn as getQueryTimePeriodFilters,
1191
- Ue as getRequestAcceptHeader,
1192
- nn as getResolvedVersionBySingleWildcard,
1197
+ pn as getDaysColumns,
1198
+ xn as getDimensionTitle,
1199
+ le as getDimensions,
1200
+ qt as getFilteredItemsWithParents,
1201
+ Mn as getFiltersDtoFromDataQuery,
1202
+ R as getISOWeek,
1203
+ v as getKeyFromUrn,
1204
+ _n as getLastUpdatedTime,
1205
+ ne as getLastWeekNumberOfYear,
1206
+ K as getLocalizedName,
1207
+ Ct as getMonthlyData,
1208
+ Pn as getMonthlyDataByQuarter,
1209
+ Y as getMonthlyRegExp,
1210
+ De as getParsedEndPeriodDate,
1211
+ Nn as getParsedResponse,
1212
+ Ee as getParsedStartPeriodDate,
1213
+ g as getPeriodDate,
1214
+ En as getPeriods,
1215
+ $n as getQuarterByMonth,
1216
+ V as getQuarterlyRegExp,
1217
+ _t as getQuartersData,
1218
+ mn as getQueryTimePeriodFilters,
1219
+ Ce as getRequestAcceptHeader,
1220
+ sn as getResolvedVersionBySingleWildcard,
1193
1221
  Ot as getSemiAnnualData,
1194
1222
  ft as getSemiAnnuallyRegExp,
1195
- C as getSeriesAttributes,
1196
- Ze as getSeriesName,
1197
- qn as getStructureComponentsMap,
1198
- Cn as getStructureDimensions,
1199
- kn as getTimeDimension,
1223
+ _ as getSeriesAttributes,
1224
+ et as getSeriesName,
1225
+ kn as getStructureComponentsMap,
1226
+ Yn as getStructureDimensions,
1227
+ Vn as getTimeDimension,
1200
1228
  Wn as getTimePeriods,
1201
- Vn as getTimeQueryFilter,
1229
+ Fn as getTimeQueryFilter,
1202
1230
  fn as getTimeRangeFromAttachment,
1203
- Mn as getTimeSeriesCount,
1231
+ qn as getTimeSeriesCount,
1204
1232
  Bn as getTimeSeriesFilterKey,
1205
- tt as getTimeSeriesId,
1206
- Re as getWeekCode,
1207
- yt as getWeeklyPeriodEndDate,
1233
+ nt as getTimeSeriesId,
1234
+ pe as getWeekCode,
1235
+ At as getWeeklyPeriodEndDate,
1208
1236
  Dt as getWeeklyPeriodStartDate,
1209
- ht as getWeeklyRegExp,
1237
+ pt as getWeeklyRegExp,
1210
1238
  gn as getWeeksColumns,
1211
- rn as getWildCardRegexp,
1212
- Ne as getYearPeriod,
1213
- M as getYearlyRegExp,
1214
- xt as getYears,
1215
- Et as isDaily,
1216
- F as isMonthly,
1217
- K as isQuarterly,
1218
- B as isSemiAnnually,
1219
- j as isWeekly,
1220
- on as isWildCardVersionCorrect,
1221
- Q as isYearly,
1222
- dt as monthlyPattern,
1239
+ on as getWildCardRegexp,
1240
+ Te as getYearPeriod,
1241
+ C as getYearlyRegExp,
1242
+ Ut as getYears,
1243
+ ht as isDaily,
1244
+ W as isMonthly,
1245
+ k as isQuarterly,
1246
+ x as isSemiAnnually,
1247
+ q as isWeekly,
1248
+ an as isWildCardVersionCorrect,
1249
+ U as isYearly,
1250
+ mt as monthlyPattern,
1223
1251
  Qn as openDownloadWindow,
1224
- it as quarterPattern,
1225
- at as semiAnnuallyPattern,
1226
- _n as sortPeriods,
1227
- p as splitUrn,
1252
+ at as quarterPattern,
1253
+ ut as semiAnnuallyPattern,
1254
+ bn as sortPeriods,
1255
+ D as splitUrn,
1228
1256
  ct as weeklyPattern,
1229
- ut as yearlyPattern
1257
+ dt as yearlyPattern
1230
1258
  };