@luzmo/analytics-components-kit 1.0.1-alpha.91 → 1.0.1-alpha.94

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.
Files changed (252) hide show
  1. package/angular/README.md +1 -0
  2. package/angular/components/widget-menu.component.ts +25 -0
  3. package/angular/esm/components/widget-menu.component.d.ts +13 -0
  4. package/angular/esm/components/widget-menu.component.js +49 -0
  5. package/angular/esm/index.d.ts +3 -1
  6. package/angular/esm/index.js +4 -1
  7. package/angular/esm/types.d.ts +4 -0
  8. package/angular/index.ts +4 -1
  9. package/angular/types.ts +6 -0
  10. package/components/ai-chat-message-assistant/index.cjs +1 -1
  11. package/components/ai-chat-message-assistant/index.js +1 -0
  12. package/components/ai-chat-messages-container/index.cjs +1 -1
  13. package/components/ai-chat-messages-container/index.js +2 -2
  14. package/components/ai-interaction-textarea/index.cjs +1 -1
  15. package/components/ai-interaction-textarea/index.js +2 -1
  16. package/components/area-chart-options.config-C7sMAHco.cjs +20 -0
  17. package/components/{area-chart-options.config-u8itidsi.js → area-chart-options.config-_J0sG4NF.js} +26 -14
  18. package/components/{bar-chart-options.config-DIirbAJ0.js → bar-chart-options.config-D1mb5TDl.js} +35 -21
  19. package/components/bar-chart-options.config-DcxEkOT5.cjs +20 -0
  20. package/components/box-plot-options.config-SrrbDEYW.cjs +20 -0
  21. package/components/{box-plot-options.config-BWROiguA.js → box-plot-options.config-xu_i6ms7.js} +88 -52
  22. package/components/{bubble-chart-options.config-4QD8VPhU.js → bubble-chart-options.config-BacgXkJ_.js} +18 -9
  23. package/components/bubble-chart-options.config-Ihn6eVQI.cjs +20 -0
  24. package/components/{bullet-chart-options.config-3bH7uekx.js → bullet-chart-options.config-CDPpX1yc.js} +1 -1
  25. package/components/{bullet-chart-options.config-tWb6Fio-.cjs → bullet-chart-options.config-DfS4Bwds.cjs} +1 -1
  26. package/components/calculate-data-item-icon-CEa82-5u.cjs +20 -0
  27. package/components/calculate-data-item-icon-DjlZwMdO.js +147 -0
  28. package/components/{choropleth-map-options.config-CMxx3ORp.js → choropleth-map-options.config-B_W9-rhe.js} +84 -63
  29. package/components/choropleth-map-options.config-ZW8yoZH2.cjs +20 -0
  30. package/components/{circular-gauge-options.config-DhIKn44k.js → circular-gauge-options.config-DAIjz4Rl.js} +36 -23
  31. package/components/circular-gauge-options.config-msZ4mfpN.cjs +20 -0
  32. package/components/color-B6LaL8qz.cjs +20 -0
  33. package/components/{color-B7m0j8lX.js → color-DuJ4-73S.js} +950 -941
  34. package/components/{color-range-utils-BSfqtB3A.js → color-range-utils-Bvo9sm5A.js} +32 -31
  35. package/components/color-range-utils-C5yXW7ZC.cjs +20 -0
  36. package/components/{column-chart-options.config-D5-yR7iq.js → column-chart-options.config-B5SjBVdy.js} +37 -27
  37. package/components/column-chart-options.config-BjDvA7i9.cjs +20 -0
  38. package/components/{conditional-number-options.config-DPYsdML5.js → conditional-number-options.config-BCEpSK9J.js} +40 -24
  39. package/components/conditional-number-options.config-DgzUo0xi.cjs +20 -0
  40. package/components/dataset-icon/index.cjs +1 -1
  41. package/components/dataset-icon/index.js +2 -1
  42. package/components/dataset-selector-list/index.cjs +1 -1
  43. package/components/dataset-selector-list/index.js +35 -32
  44. package/components/dataset-selector-row/index.cjs +9 -9
  45. package/components/dataset-selector-row/index.js +53 -51
  46. package/components/{date-comparison-filter-options.config-QaoWaFUn.cjs → date-comparison-filter-options.config-DAVncmi0.cjs} +1 -1
  47. package/components/{date-comparison-filter-options.config-CSwGyuBg.js → date-comparison-filter-options.config-JA_yYpJa.js} +6 -3
  48. package/components/{date-filter-options.config-n-zhWaYa.cjs → date-filter-options.config-CWPMtA18.cjs} +1 -1
  49. package/components/{date-filter-options.config-BTVyHRkp.js → date-filter-options.config-DBRxlTWy.js} +6 -3
  50. package/components/display-settings/index.cjs +1 -1
  51. package/components/display-settings/index.js +1 -1
  52. package/components/display-settings-binning/index.cjs +5 -5
  53. package/components/display-settings-binning/index.js +30 -29
  54. package/components/display-settings-datetime/index.cjs +29 -29
  55. package/components/display-settings-datetime/index.js +120 -112
  56. package/components/display-settings-grand-totals/index.cjs +4 -4
  57. package/components/display-settings-grand-totals/index.js +24 -23
  58. package/components/display-settings-numeric/index.cjs +48 -48
  59. package/components/display-settings-numeric/index.js +211 -194
  60. package/components/display-settings-period-over-period/index.cjs +16 -16
  61. package/components/display-settings-period-over-period/index.js +97 -91
  62. package/components/{donut-chart-options.config-3ZqX8Cbb.js → donut-chart-options.config-BulUEiaH.js} +37 -21
  63. package/components/donut-chart-options.config-tNpqBZfR.cjs +20 -0
  64. package/components/draggable-data-item/index.cjs +5 -5
  65. package/components/draggable-data-item/index.js +46 -45
  66. package/components/draggable-data-item-level/index.cjs +11 -11
  67. package/components/draggable-data-item-level/index.js +73 -70
  68. package/components/{dropdown-filter-options.config-CGJTtgAX.js → dropdown-filter-options.config-D9dvPypF.js} +10 -7
  69. package/components/{dropdown-filter-options.config-DJvfCTk7.cjs → dropdown-filter-options.config-DS-MORmq.cjs} +1 -1
  70. package/components/droppable-slot/index.cjs +16 -16
  71. package/components/droppable-slot/index.js +223 -208
  72. package/components/edit-item/index.cjs +9 -9
  73. package/components/edit-item/index.js +119 -116
  74. package/components/edit-option/index.cjs +1 -1
  75. package/components/edit-option/index.js +1 -1
  76. package/components/edit-option-action-button-group/index.cjs +8 -8
  77. package/components/edit-option-action-button-group/index.js +53 -52
  78. package/components/{edit-option-base-Bh29-Cak.js → edit-option-base-DIc7iC-b.js} +1 -1
  79. package/components/{edit-option-base-tFr8Qg2B.cjs → edit-option-base-VhTih9T1.cjs} +1 -1
  80. package/components/edit-option-color-palette-picker/index.cjs +1 -1
  81. package/components/edit-option-color-palette-picker/index.js +1 -1
  82. package/components/edit-option-color-picker/index.cjs +1 -1
  83. package/components/edit-option-color-picker/index.js +1 -1
  84. package/components/edit-option-color-range/index.cjs +19 -19
  85. package/components/edit-option-color-range/index.js +117 -106
  86. package/components/edit-option-multi-language-field/index.cjs +3 -3
  87. package/components/edit-option-multi-language-field/index.js +27 -26
  88. package/components/edit-option-number-field/index.cjs +1 -1
  89. package/components/edit-option-number-field/index.js +1 -1
  90. package/components/edit-option-picker/index.cjs +5 -5
  91. package/components/edit-option-picker/index.js +7 -7
  92. package/components/edit-option-position-picker/index.cjs +4 -4
  93. package/components/edit-option-position-picker/index.js +25 -21
  94. package/components/edit-option-positions-number-field/index.cjs +9 -9
  95. package/components/edit-option-positions-number-field/index.js +81 -76
  96. package/components/edit-option-radio-button-group/index.cjs +6 -6
  97. package/components/edit-option-radio-button-group/index.js +22 -21
  98. package/components/edit-option-slider/index.cjs +1 -1
  99. package/components/edit-option-slider/index.js +1 -1
  100. package/components/edit-option-switch/index.cjs +1 -1
  101. package/components/edit-option-switch/index.js +1 -1
  102. package/components/edit-option-text-field/index.cjs +2 -2
  103. package/components/edit-option-text-field/index.js +23 -22
  104. package/components/en-BKBhKBXY.cjs +20 -0
  105. package/components/en-BOTjhwEc.js +1488 -0
  106. package/components/{en-GB-ialeqj_z.js → en-GB-CEHEs8F2.js} +1 -1
  107. package/components/{en-GB-TqvgIw9B.cjs → en-GB-DG6uS3sM.cjs} +1 -1
  108. package/components/{evolution-number-options.config-Bc9eKYnn.cjs → evolution-number-options.config-BgIZY4gQ.cjs} +1 -1
  109. package/components/{evolution-number-options.config-BIPO_4n3.js → evolution-number-options.config-DzkfeoIN.js} +14 -11
  110. package/components/{extrapolate-color-C0n1UDs-.cjs → extrapolate-color-0j_AeYkz.cjs} +1 -1
  111. package/components/{extrapolate-color-v1PimdQr.js → extrapolate-color-CC9CURf6.js} +1 -1
  112. package/components/filter-data-item-picker/index.cjs +7 -7
  113. package/components/filter-data-item-picker/index.js +86 -85
  114. package/components/filter-expression-picker/index.cjs +1 -1
  115. package/components/filter-expression-picker/index.js +1 -1
  116. package/components/filter-item/index.cjs +6 -6
  117. package/components/filter-item/index.js +119 -109
  118. package/components/filter-value-picker/index.cjs +2 -2
  119. package/components/filter-value-picker/index.js +36 -34
  120. package/components/filter-value-picker-datetime/index.cjs +8 -8
  121. package/components/filter-value-picker-datetime/index.js +71 -56
  122. package/components/filter-value-picker-hierarchy/index.cjs +12 -12
  123. package/components/filter-value-picker-hierarchy/index.js +124 -113
  124. package/components/filter-value-picker-numeric/index.cjs +8 -8
  125. package/components/filter-value-picker-numeric/index.js +110 -101
  126. package/components/focusable-B3E_hQmm.cjs +20 -0
  127. package/components/{focusable-BS2pbY7w.js → focusable-DCIFkpiW.js} +26 -24
  128. package/components/{funnel-chart-options.config-CrJy2U7_.js → funnel-chart-options.config-C_VjTOvD.js} +20 -5
  129. package/components/funnel-chart-options.config-D7H7gFcx.cjs +20 -0
  130. package/components/get-css-variable-BEYG097C.js +1446 -0
  131. package/components/get-css-variable-BZxY4IOa.cjs +35 -0
  132. package/components/get-css-variable-DLiZYZEi.cjs +24 -0
  133. package/components/{get-css-variable-Bb7TxJdX.js → get-css-variable-YlLiVgo8.js} +37 -37
  134. package/components/grid/index.cjs +49 -43
  135. package/components/grid/index.js +1878 -2610
  136. package/components/{heat-map-options.config-CmL87j1j.js → heat-map-options.config-BnLWe8jS.js} +41 -35
  137. package/components/heat-map-options.config-DVH-Bb5-.cjs +20 -0
  138. package/components/heat-table-options.config-B12JEYnp.cjs +20 -0
  139. package/components/{heat-table-options.config-BrCYAgYD.js → heat-table-options.config-CUsDdgUr.js} +88 -60
  140. package/components/helpers-DXQwEH1P.cjs +20 -0
  141. package/components/helpers-v1bPALRP.js +91 -0
  142. package/components/hexbin-map-options.config-DZERRhM8.cjs +20 -0
  143. package/components/{hexbin-map-options.config-BguV1w8q.js → hexbin-map-options.config-F-7uCqxb.js} +38 -20
  144. package/components/{index-BNAmjOkm.cjs → index-BPNsFiyq.cjs} +4 -4
  145. package/components/index-CDi4fe3N.js +1716 -0
  146. package/components/index-CQ9ck-BO.cjs +249 -0
  147. package/components/index-CXn67vdn.cjs +121 -0
  148. package/components/{index-haa7WNrl.js → index-CdIUfo-L.js} +481 -453
  149. package/components/index-Cz9vSXy6.cjs +20 -0
  150. package/components/{index-DdyZ2g5L.js → index-D0GBF6tg.js} +104 -94
  151. package/components/index-Dn0j_pcR.cjs +20 -0
  152. package/components/{index-CqKpf0B8.js → index-Do7O9azB.js} +123 -112
  153. package/components/index-E239Dotg.js +1735 -0
  154. package/components/index.cjs +1 -1
  155. package/components/index.js +20 -18
  156. package/components/item-options-configs.cjs +1 -1
  157. package/components/item-options-configs.js +37 -37
  158. package/components/{line-chart-options.config-BhirTGqD.js → line-chart-options.config-DB3IsXXr.js} +28 -13
  159. package/components/line-chart-options.config-DSugoe0t.cjs +20 -0
  160. package/components/{localize-CcDpq940.js → localize-BX7q0S0M.js} +10 -10
  161. package/components/{localize-C4zNlrwK.cjs → localize-r7ALOUy_.cjs} +1 -1
  162. package/components/{marker-map-options.config-Bx17jmiq.js → marker-map-options.config-DPJ955tt.js} +1 -1
  163. package/components/{marker-map-options.config-CvhCylSC.cjs → marker-map-options.config-_FYZzRwA.cjs} +1 -1
  164. package/components/pivot-table-options.config-BiJXKSFR.cjs +20 -0
  165. package/components/{pivot-table-options.config-CFc7y0IT.js → pivot-table-options.config-DNK_AIG7.js} +24 -15
  166. package/components/pyramid-chart-options.config-C4zbFS26.cjs +20 -0
  167. package/components/{pyramid-chart-options.config-2Waxb11l.js → pyramid-chart-options.config-CcVMatYx.js} +43 -29
  168. package/components/{radar-chart-options.config-CPN5fOl8.js → radar-chart-options.config-CUZn_3Fd.js} +23 -11
  169. package/components/radar-chart-options.config-EqQu6PTh.cjs +20 -0
  170. package/components/{regular-table-options.config-CFKCJQK1.js → regular-table-options.config-BoLZsBry.js} +23 -17
  171. package/components/{regular-table-options.config-YRuoijIk.cjs → regular-table-options.config-DTx3RTnS.cjs} +1 -1
  172. package/components/{route-map-options.config-CyolTJfK.js → route-map-options.config-CN86T7c0.js} +109 -87
  173. package/components/route-map-options.config-D7NJePTu.cjs +20 -0
  174. package/components/{sankey-diagram-options.config-D7OSvSqm.cjs → sankey-diagram-options.config-RFB83YLZ.cjs} +1 -1
  175. package/components/{sankey-diagram-options.config-Ldjk84ro.js → sankey-diagram-options.config-tVLKy_Zn.js} +10 -7
  176. package/components/scatter-plot-options.config-CFfGJXsV.cjs +20 -0
  177. package/components/{scatter-plot-options.config-CfxEfkQ1.js → scatter-plot-options.config-Corlzno1.js} +86 -56
  178. package/components/{search-filter-options.config-Oqco9BKj.cjs → search-filter-options.config-BCaDlYqZ.cjs} +1 -1
  179. package/components/{search-filter-options.config-C0syQmP4.js → search-filter-options.config-BE3JhR-F.js} +6 -3
  180. package/components/{set-locale-hKTMz37h.js → set-locale-Dp3N_gXN.js} +8 -1
  181. package/components/{slicer-filter-options.config-DmOe3440.js → slicer-filter-options.config-3JZZcw5C.js} +18 -9
  182. package/components/slicer-filter-options.config-DNI-XevE.cjs +20 -0
  183. package/components/{slider-filter-options.config-B1M8RcDs.js → slider-filter-options.config-DH4SS8wH.js} +1 -1
  184. package/components/{slider-filter-options.config-k45I-t6G.cjs → slider-filter-options.config-_8Z2zKmU.cjs} +1 -1
  185. package/components/slot-contents-picker/index.cjs +33 -33
  186. package/components/slot-contents-picker/index.js +205 -194
  187. package/components/slot-menu/index.cjs +12 -12
  188. package/components/slot-menu/index.js +184 -171
  189. package/components/slot-menu-list/index.cjs +3 -3
  190. package/components/slot-menu-list/index.js +103 -97
  191. package/components/speedometer-chart-options.config-BX9LTQBH.cjs +20 -0
  192. package/components/{speedometer-chart-options.config-CzOmuEF8.js → speedometer-chart-options.config-SL581yOa.js} +53 -31
  193. package/components/{spike-map-options.config-Cbt1YUw6.js → spike-map-options.config-C5KewecZ.js} +122 -91
  194. package/components/spike-map-options.config-DoBFXPmN.cjs +20 -0
  195. package/components/{sunburst-chart-options.config-Yrxc2i57.cjs → sunburst-chart-options.config-AbNjWS6t.cjs} +1 -1
  196. package/components/{sunburst-chart-options.config-_dyLQxPJ.js → sunburst-chart-options.config-CNauGQJv.js} +20 -9
  197. package/components/{symbol-map-options.config-BORL1NSU.js → symbol-map-options.config-DdDA4aa7.js} +20 -11
  198. package/components/symbol-map-options.config-m-lwLTtu.cjs +20 -0
  199. package/components/treemap-chart-options.config-C0Q9aQ1Z.cjs +20 -0
  200. package/components/{treemap-chart-options.config-B9i9qIm_.js → treemap-chart-options.config-D5AJaF_u.js} +37 -20
  201. package/components/utils.cjs +1 -1
  202. package/components/utils.js +97 -94
  203. package/components/{video-options.config-B0asgYt8.cjs → video-options.config-CGsDTwHc.cjs} +1 -1
  204. package/components/{video-options.config-UX-9MDfS.js → video-options.config-Dk36zJ1B.js} +10 -7
  205. package/components/widget-menu/index.cjs +51 -0
  206. package/components/widget-menu/index.d.ts +8 -0
  207. package/components/widget-menu/index.js +211 -0
  208. package/components/widget-menu/widget-menu.d.ts +77 -0
  209. package/components/{wordcloud-chart-options.config-BKtJT8Va.cjs → wordcloud-chart-options.config-vGfCW8kE.cjs} +1 -1
  210. package/components/{wordcloud-chart-options.config-BoB_KuhA.js → wordcloud-chart-options.config-w2NUIWVA.js} +7 -4
  211. package/custom-elements.json +133 -20
  212. package/index.d.ts +1 -0
  213. package/package.json +6 -1
  214. package/types.d.ts +4 -0
  215. package/components/area-chart-options.config-Bl8bhhOo.cjs +0 -20
  216. package/components/bar-chart-options.config-CePAqM83.cjs +0 -20
  217. package/components/box-plot-options.config-BVNrV2eD.cjs +0 -20
  218. package/components/bubble-chart-options.config-BDgOe3GQ.cjs +0 -20
  219. package/components/calculate-data-item-icon-DMDhKq_m.js +0 -147
  220. package/components/calculate-data-item-icon-DtVGbet3.cjs +0 -20
  221. package/components/choropleth-map-options.config-CWJACFd0.cjs +0 -20
  222. package/components/circular-gauge-options.config-BMxgq3zH.cjs +0 -20
  223. package/components/color-Czp4Im5q.cjs +0 -20
  224. package/components/color-range-utils-DYYR-iwx.cjs +0 -20
  225. package/components/column-chart-options.config-BV9R3ssH.cjs +0 -20
  226. package/components/conditional-number-options.config-Co099Qfm.cjs +0 -20
  227. package/components/donut-chart-options.config-BQyPgnC9.cjs +0 -20
  228. package/components/en-D3ihEGXg.js +0 -1483
  229. package/components/en-DZcn_iz_.cjs +0 -20
  230. package/components/focusable-QLh-LlNt.cjs +0 -20
  231. package/components/funnel-chart-options.config-DrP4AFgk.cjs +0 -20
  232. package/components/get-css-variable-Pzks_rOx.cjs +0 -24
  233. package/components/heat-map-options.config-CIHnPdYE.cjs +0 -20
  234. package/components/heat-table-options.config-DTlZRc_i.cjs +0 -20
  235. package/components/helpers-9I0oLoUB.cjs +0 -20
  236. package/components/helpers-bR8Ibjqh.js +0 -79
  237. package/components/hexbin-map-options.config-CKnn3VAB.cjs +0 -20
  238. package/components/index-BekTY3Em.cjs +0 -121
  239. package/components/index-CFL6gmIu.cjs +0 -20
  240. package/components/index-DNPULp4A.js +0 -1755
  241. package/components/index-DvkzMbLt.cjs +0 -249
  242. package/components/line-chart-options.config-Cqwou5u6.cjs +0 -20
  243. package/components/pivot-table-options.config-uZDAertf.cjs +0 -20
  244. package/components/pyramid-chart-options.config-DoGfEvzU.cjs +0 -20
  245. package/components/radar-chart-options.config-CtNUMN1l.cjs +0 -20
  246. package/components/route-map-options.config-CVTk5RVL.cjs +0 -20
  247. package/components/scatter-plot-options.config-5gN7pMTm.cjs +0 -20
  248. package/components/slicer-filter-options.config-CrusP6a0.cjs +0 -20
  249. package/components/speedometer-chart-options.config-B4ceg_qI.cjs +0 -20
  250. package/components/spike-map-options.config-BkkDqb4g.cjs +0 -20
  251. package/components/symbol-map-options.config-NpBKm64d.cjs +0 -20
  252. package/components/treemap-chart-options.config-x4J54WSw.cjs +0 -20
@@ -1,1755 +0,0 @@
1
- /*! * A kit of modern Luzmo Web Components for analytics in your web application.
2
- *
3
- * Copyright © 2025 Luzmo
4
- * All rights reserved.
5
- * Luzmo web components (“Luzmo Web Components”)
6
- * must be used according to the Luzmo Terms of Service.
7
- * This license allows users with a current active Luzmo account
8
- * to use the Luzmo Web Components. This license terminates
9
- * automatically if a user no longer has an active Luzmo account.
10
- * Please view the Luzmo Terms of Service at: https://www.luzmo.com/information-pages/terms-of-use.
11
- *
12
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18
- * SOFTWARE.
19
- * */
20
- var T = class {
21
- constructor() {
22
- this.listeners = /* @__PURE__ */ new Set(), this.subscribe = this.subscribe.bind(this);
23
- }
24
- subscribe(t) {
25
- return this.listeners.add(t), this.onSubscribe(), () => {
26
- this.listeners.delete(t), this.onUnsubscribe();
27
- };
28
- }
29
- hasListeners() {
30
- return this.listeners.size > 0;
31
- }
32
- onSubscribe() {
33
- }
34
- onUnsubscribe() {
35
- }
36
- }, X = {
37
- // We need the wrapper function syntax below instead of direct references to
38
- // global setTimeout etc.
39
- //
40
- // BAD: `setTimeout: setTimeout`
41
- // GOOD: `setTimeout: (cb, delay) => setTimeout(cb, delay)`
42
- //
43
- // If we use direct references here, then anything that wants to spy on or
44
- // replace the global setTimeout (like tests) won't work since we'll already
45
- // have a hard reference to the original implementation at the time when this
46
- // file was imported.
47
- setTimeout: (t, e) => setTimeout(t, e),
48
- clearTimeout: (t) => clearTimeout(t),
49
- setInterval: (t, e) => setInterval(t, e),
50
- clearInterval: (t) => clearInterval(t)
51
- }, Y = class {
52
- // We cannot have TimeoutManager<T> as we must instantiate it with a concrete
53
- // type at app boot; and if we leave that type, then any new timer provider
54
- // would need to support ReturnType<typeof setTimeout>, which is infeasible.
55
- //
56
- // We settle for type safety for the TimeoutProvider type, and accept that
57
- // this class is unsafe internally to allow for extension.
58
- #t = X;
59
- #e = !1;
60
- setTimeoutProvider(t) {
61
- this.#t = t;
62
- }
63
- setTimeout(t, e) {
64
- return this.#t.setTimeout(t, e);
65
- }
66
- clearTimeout(t) {
67
- this.#t.clearTimeout(t);
68
- }
69
- setInterval(t, e) {
70
- return this.#t.setInterval(t, e);
71
- }
72
- clearInterval(t) {
73
- this.#t.clearInterval(t);
74
- }
75
- }, Q = new Y();
76
- function tt(t) {
77
- setTimeout(t, 0);
78
- }
79
- var M = typeof window > "u" || "Deno" in globalThis;
80
- function v() {
81
- }
82
- function et(t, e) {
83
- return typeof t == "function" ? t(e) : t;
84
- }
85
- function st(t) {
86
- return typeof t == "number" && t >= 0 && t !== 1 / 0;
87
- }
88
- function it(t, e) {
89
- return Math.max(t + (e || 0) - Date.now(), 0);
90
- }
91
- function E(t, e) {
92
- return typeof t == "function" ? t(e) : t;
93
- }
94
- function rt(t, e) {
95
- return typeof t == "function" ? t(e) : t;
96
- }
97
- function U(t, e) {
98
- const {
99
- type: s = "all",
100
- exact: i,
101
- fetchStatus: n,
102
- predicate: a,
103
- queryKey: o,
104
- stale: r
105
- } = t;
106
- if (o) {
107
- if (i) {
108
- if (e.queryHash !== j(o, e.options))
109
- return !1;
110
- } else if (!F(e.queryKey, o))
111
- return !1;
112
- }
113
- if (s !== "all") {
114
- const u = e.isActive();
115
- if (s === "active" && !u || s === "inactive" && u)
116
- return !1;
117
- }
118
- return !(typeof r == "boolean" && e.isStale() !== r || n && n !== e.state.fetchStatus || a && !a(e));
119
- }
120
- function x(t, e) {
121
- const { exact: s, status: i, predicate: n, mutationKey: a } = t;
122
- if (a) {
123
- if (!e.options.mutationKey)
124
- return !1;
125
- if (s) {
126
- if (P(e.options.mutationKey) !== P(a))
127
- return !1;
128
- } else if (!F(e.options.mutationKey, a))
129
- return !1;
130
- }
131
- return !(i && e.state.status !== i || n && !n(e));
132
- }
133
- function j(t, e) {
134
- return (e?.queryKeyHashFn || P)(t);
135
- }
136
- function P(t) {
137
- return JSON.stringify(
138
- t,
139
- (e, s) => R(s) ? Object.keys(s).sort().reduce((i, n) => (i[n] = s[n], i), {}) : s
140
- );
141
- }
142
- function F(t, e) {
143
- return t === e ? !0 : typeof t != typeof e ? !1 : t && e && typeof t == "object" && typeof e == "object" ? Object.keys(e).every((s) => F(t[s], e[s])) : !1;
144
- }
145
- var nt = Object.prototype.hasOwnProperty;
146
- function $(t, e) {
147
- if (t === e)
148
- return t;
149
- const s = L(t) && L(e);
150
- if (!s && !(R(t) && R(e))) return e;
151
- const n = (s ? t : Object.keys(t)).length, a = s ? e : Object.keys(e), o = a.length, r = s ? new Array(o) : {};
152
- let u = 0;
153
- for (let h = 0; h < o; h++) {
154
- const d = s ? h : a[h], l = t[d], m = e[d];
155
- if (l === m) {
156
- r[d] = l, (s ? h < n : nt.call(t, d)) && u++;
157
- continue;
158
- }
159
- if (l === null || m === null || typeof l != "object" || typeof m != "object") {
160
- r[d] = m;
161
- continue;
162
- }
163
- const b = $(l, m);
164
- r[d] = b, b === l && u++;
165
- }
166
- return n === o && u === n ? t : r;
167
- }
168
- function L(t) {
169
- return Array.isArray(t) && t.length === Object.keys(t).length;
170
- }
171
- function R(t) {
172
- if (!H(t))
173
- return !1;
174
- const e = t.constructor;
175
- if (e === void 0)
176
- return !0;
177
- const s = e.prototype;
178
- return !(!H(s) || !s.hasOwnProperty("isPrototypeOf") || Object.getPrototypeOf(t) !== Object.prototype);
179
- }
180
- function H(t) {
181
- return Object.prototype.toString.call(t) === "[object Object]";
182
- }
183
- function at(t) {
184
- return new Promise((e) => {
185
- Q.setTimeout(e, t);
186
- });
187
- }
188
- function ot(t, e, s) {
189
- return typeof s.structuralSharing == "function" ? s.structuralSharing(t, e) : s.structuralSharing !== !1 ? $(t, e) : e;
190
- }
191
- function ut(t, e, s = 0) {
192
- const i = [...t, e];
193
- return s && i.length > s ? i.slice(1) : i;
194
- }
195
- function ht(t, e, s = 0) {
196
- const i = [e, ...t];
197
- return s && i.length > s ? i.slice(0, -1) : i;
198
- }
199
- var I = Symbol();
200
- function J(t, e) {
201
- return !t.queryFn && e?.initialPromise ? () => e.initialPromise : !t.queryFn || t.queryFn === I ? () => Promise.reject(new Error(`Missing queryFn: '${t.queryHash}'`)) : t.queryFn;
202
- }
203
- var ct = class extends T {
204
- #t;
205
- #e;
206
- #s;
207
- constructor() {
208
- super(), this.#s = (t) => {
209
- if (!M && window.addEventListener) {
210
- const e = () => t();
211
- return window.addEventListener("visibilitychange", e, !1), () => {
212
- window.removeEventListener("visibilitychange", e);
213
- };
214
- }
215
- };
216
- }
217
- onSubscribe() {
218
- this.#e || this.setEventListener(this.#s);
219
- }
220
- onUnsubscribe() {
221
- this.hasListeners() || (this.#e?.(), this.#e = void 0);
222
- }
223
- setEventListener(t) {
224
- this.#s = t, this.#e?.(), this.#e = t((e) => {
225
- typeof e == "boolean" ? this.setFocused(e) : this.onFocus();
226
- });
227
- }
228
- setFocused(t) {
229
- this.#t !== t && (this.#t = t, this.onFocus());
230
- }
231
- onFocus() {
232
- const t = this.isFocused();
233
- this.listeners.forEach((e) => {
234
- e(t);
235
- });
236
- }
237
- isFocused() {
238
- return typeof this.#t == "boolean" ? this.#t : globalThis.document?.visibilityState !== "hidden";
239
- }
240
- }, z = new ct();
241
- function lt() {
242
- let t, e;
243
- const s = new Promise((n, a) => {
244
- t = n, e = a;
245
- });
246
- s.status = "pending", s.catch(() => {
247
- });
248
- function i(n) {
249
- Object.assign(s, n), delete s.resolve, delete s.reject;
250
- }
251
- return s.resolve = (n) => {
252
- i({
253
- status: "fulfilled",
254
- value: n
255
- }), t(n);
256
- }, s.reject = (n) => {
257
- i({
258
- status: "rejected",
259
- reason: n
260
- }), e(n);
261
- }, s;
262
- }
263
- var dt = tt;
264
- function ft() {
265
- let t = [], e = 0, s = (r) => {
266
- r();
267
- }, i = (r) => {
268
- r();
269
- }, n = dt;
270
- const a = (r) => {
271
- e ? t.push(r) : n(() => {
272
- s(r);
273
- });
274
- }, o = () => {
275
- const r = t;
276
- t = [], r.length && n(() => {
277
- i(() => {
278
- r.forEach((u) => {
279
- s(u);
280
- });
281
- });
282
- });
283
- };
284
- return {
285
- batch: (r) => {
286
- let u;
287
- e++;
288
- try {
289
- u = r();
290
- } finally {
291
- e--, e || o();
292
- }
293
- return u;
294
- },
295
- /**
296
- * All calls to the wrapped function will be batched.
297
- */
298
- batchCalls: (r) => (...u) => {
299
- a(() => {
300
- r(...u);
301
- });
302
- },
303
- schedule: a,
304
- /**
305
- * Use this method to set a custom notify function.
306
- * This can be used to for example wrap notifications with `React.act` while running tests.
307
- */
308
- setNotifyFunction: (r) => {
309
- s = r;
310
- },
311
- /**
312
- * Use this method to set a custom function to batch notifications together into a single tick.
313
- * By default React Query will use the batch function provided by ReactDOM or React Native.
314
- */
315
- setBatchNotifyFunction: (r) => {
316
- i = r;
317
- },
318
- setScheduler: (r) => {
319
- n = r;
320
- }
321
- };
322
- }
323
- var y = ft(), yt = class extends T {
324
- #t = !0;
325
- #e;
326
- #s;
327
- constructor() {
328
- super(), this.#s = (t) => {
329
- if (!M && window.addEventListener) {
330
- const e = () => t(!0), s = () => t(!1);
331
- return window.addEventListener("online", e, !1), window.addEventListener("offline", s, !1), () => {
332
- window.removeEventListener("online", e), window.removeEventListener("offline", s);
333
- };
334
- }
335
- };
336
- }
337
- onSubscribe() {
338
- this.#e || this.setEventListener(this.#s);
339
- }
340
- onUnsubscribe() {
341
- this.hasListeners() || (this.#e?.(), this.#e = void 0);
342
- }
343
- setEventListener(t) {
344
- this.#s = t, this.#e?.(), this.#e = t(this.setOnline.bind(this));
345
- }
346
- setOnline(t) {
347
- this.#t !== t && (this.#t = t, this.listeners.forEach((s) => {
348
- s(t);
349
- }));
350
- }
351
- isOnline() {
352
- return this.#t;
353
- }
354
- }, D = new yt();
355
- function pt(t) {
356
- return Math.min(1e3 * 2 ** t, 3e4);
357
- }
358
- function B(t) {
359
- return (t ?? "online") === "online" ? D.isOnline() : !0;
360
- }
361
- var K = class extends Error {
362
- constructor(t) {
363
- super("CancelledError"), this.revert = t?.revert, this.silent = t?.silent;
364
- }
365
- };
366
- function W(t) {
367
- let e = !1, s = 0, i;
368
- const n = lt(), a = () => n.status !== "pending", o = (c) => {
369
- if (!a()) {
370
- const p = new K(c);
371
- m(p), t.onCancel?.(p);
372
- }
373
- }, r = () => {
374
- e = !0;
375
- }, u = () => {
376
- e = !1;
377
- }, h = () => z.isFocused() && (t.networkMode === "always" || D.isOnline()) && t.canRun(), d = () => B(t.networkMode) && t.canRun(), l = (c) => {
378
- a() || (i?.(), n.resolve(c));
379
- }, m = (c) => {
380
- a() || (i?.(), n.reject(c));
381
- }, b = () => new Promise((c) => {
382
- i = (p) => {
383
- (a() || h()) && c(p);
384
- }, t.onPause?.();
385
- }).then(() => {
386
- i = void 0, a() || t.onContinue?.();
387
- }), f = () => {
388
- if (a())
389
- return;
390
- let c;
391
- const p = s === 0 ? t.initialPromise : void 0;
392
- try {
393
- c = p ?? t.fn();
394
- } catch (g) {
395
- c = Promise.reject(g);
396
- }
397
- Promise.resolve(c).then(l).catch((g) => {
398
- if (a())
399
- return;
400
- const w = t.retry ?? (M ? 0 : 3), O = t.retryDelay ?? pt, q = typeof O == "function" ? O(s, g) : O, S = w === !0 || typeof w == "number" && s < w || typeof w == "function" && w(s, g);
401
- if (e || !S) {
402
- m(g);
403
- return;
404
- }
405
- s++, t.onFail?.(s, g), at(q).then(() => h() ? void 0 : b()).then(() => {
406
- e ? m(g) : f();
407
- });
408
- });
409
- };
410
- return {
411
- promise: n,
412
- status: () => n.status,
413
- cancel: o,
414
- continue: () => (i?.(), n),
415
- cancelRetry: r,
416
- continueRetry: u,
417
- canStart: d,
418
- start: () => (d() ? f() : b().then(f), n)
419
- };
420
- }
421
- var Z = class {
422
- #t;
423
- destroy() {
424
- this.clearGcTimeout();
425
- }
426
- scheduleGc() {
427
- this.clearGcTimeout(), st(this.gcTime) && (this.#t = Q.setTimeout(() => {
428
- this.optionalRemove();
429
- }, this.gcTime));
430
- }
431
- updateGcTime(t) {
432
- this.gcTime = Math.max(
433
- this.gcTime || 0,
434
- t ?? (M ? 1 / 0 : 300 * 1e3)
435
- );
436
- }
437
- clearGcTimeout() {
438
- this.#t && (Q.clearTimeout(this.#t), this.#t = void 0);
439
- }
440
- }, mt = class extends Z {
441
- #t;
442
- #e;
443
- #s;
444
- #r;
445
- #i;
446
- #a;
447
- #o;
448
- constructor(t) {
449
- super(), this.#o = !1, this.#a = t.defaultOptions, this.setOptions(t.options), this.observers = [], this.#r = t.client, this.#s = this.#r.getQueryCache(), this.queryKey = t.queryKey, this.queryHash = t.queryHash, this.#t = N(this.options), this.state = t.state ?? this.#t, this.scheduleGc();
450
- }
451
- get meta() {
452
- return this.options.meta;
453
- }
454
- get promise() {
455
- return this.#i?.promise;
456
- }
457
- setOptions(t) {
458
- if (this.options = { ...this.#a, ...t }, this.updateGcTime(this.options.gcTime), this.state && this.state.data === void 0) {
459
- const e = N(this.options);
460
- e.data !== void 0 && (this.setState(
461
- G(e.data, e.dataUpdatedAt)
462
- ), this.#t = e);
463
- }
464
- }
465
- optionalRemove() {
466
- !this.observers.length && this.state.fetchStatus === "idle" && this.#s.remove(this);
467
- }
468
- setData(t, e) {
469
- const s = ot(this.state.data, t, this.options);
470
- return this.#n({
471
- data: s,
472
- type: "success",
473
- dataUpdatedAt: e?.updatedAt,
474
- manual: e?.manual
475
- }), s;
476
- }
477
- setState(t, e) {
478
- this.#n({ type: "setState", state: t, setStateOptions: e });
479
- }
480
- cancel(t) {
481
- const e = this.#i?.promise;
482
- return this.#i?.cancel(t), e ? e.then(v).catch(v) : Promise.resolve();
483
- }
484
- destroy() {
485
- super.destroy(), this.cancel({ silent: !0 });
486
- }
487
- reset() {
488
- this.destroy(), this.setState(this.#t);
489
- }
490
- isActive() {
491
- return this.observers.some(
492
- (t) => rt(t.options.enabled, this) !== !1
493
- );
494
- }
495
- isDisabled() {
496
- return this.getObserversCount() > 0 ? !this.isActive() : this.options.queryFn === I || this.state.dataUpdateCount + this.state.errorUpdateCount === 0;
497
- }
498
- isStatic() {
499
- return this.getObserversCount() > 0 ? this.observers.some(
500
- (t) => E(t.options.staleTime, this) === "static"
501
- ) : !1;
502
- }
503
- isStale() {
504
- return this.getObserversCount() > 0 ? this.observers.some(
505
- (t) => t.getCurrentResult().isStale
506
- ) : this.state.data === void 0 || this.state.isInvalidated;
507
- }
508
- isStaleByTime(t = 0) {
509
- return this.state.data === void 0 ? !0 : t === "static" ? !1 : this.state.isInvalidated ? !0 : !it(this.state.dataUpdatedAt, t);
510
- }
511
- onFocus() {
512
- this.observers.find((e) => e.shouldFetchOnWindowFocus())?.refetch({ cancelRefetch: !1 }), this.#i?.continue();
513
- }
514
- onOnline() {
515
- this.observers.find((e) => e.shouldFetchOnReconnect())?.refetch({ cancelRefetch: !1 }), this.#i?.continue();
516
- }
517
- addObserver(t) {
518
- this.observers.includes(t) || (this.observers.push(t), this.clearGcTimeout(), this.#s.notify({ type: "observerAdded", query: this, observer: t }));
519
- }
520
- removeObserver(t) {
521
- this.observers.includes(t) && (this.observers = this.observers.filter((e) => e !== t), this.observers.length || (this.#i && (this.#o ? this.#i.cancel({ revert: !0 }) : this.#i.cancelRetry()), this.scheduleGc()), this.#s.notify({ type: "observerRemoved", query: this, observer: t }));
522
- }
523
- getObserversCount() {
524
- return this.observers.length;
525
- }
526
- invalidate() {
527
- this.state.isInvalidated || this.#n({ type: "invalidate" });
528
- }
529
- async fetch(t, e) {
530
- if (this.state.fetchStatus !== "idle" && // If the promise in the retyer is already rejected, we have to definitely
531
- // re-start the fetch; there is a chance that the query is still in a
532
- // pending state when that happens
533
- this.#i?.status() !== "rejected") {
534
- if (this.state.data !== void 0 && e?.cancelRefetch)
535
- this.cancel({ silent: !0 });
536
- else if (this.#i)
537
- return this.#i.continueRetry(), this.#i.promise;
538
- }
539
- if (t && this.setOptions(t), !this.options.queryFn) {
540
- const r = this.observers.find((u) => u.options.queryFn);
541
- r && this.setOptions(r.options);
542
- }
543
- const s = new AbortController(), i = (r) => {
544
- Object.defineProperty(r, "signal", {
545
- enumerable: !0,
546
- get: () => (this.#o = !0, s.signal)
547
- });
548
- }, n = () => {
549
- const r = J(this.options, e), h = (() => {
550
- const d = {
551
- client: this.#r,
552
- queryKey: this.queryKey,
553
- meta: this.meta
554
- };
555
- return i(d), d;
556
- })();
557
- return this.#o = !1, this.options.persister ? this.options.persister(
558
- r,
559
- h,
560
- this
561
- ) : r(h);
562
- }, o = (() => {
563
- const r = {
564
- fetchOptions: e,
565
- options: this.options,
566
- queryKey: this.queryKey,
567
- client: this.#r,
568
- state: this.state,
569
- fetchFn: n
570
- };
571
- return i(r), r;
572
- })();
573
- this.options.behavior?.onFetch(o, this), this.#e = this.state, (this.state.fetchStatus === "idle" || this.state.fetchMeta !== o.fetchOptions?.meta) && this.#n({ type: "fetch", meta: o.fetchOptions?.meta }), this.#i = W({
574
- initialPromise: e?.initialPromise,
575
- fn: o.fetchFn,
576
- onCancel: (r) => {
577
- r instanceof K && r.revert && this.setState({
578
- ...this.#e,
579
- fetchStatus: "idle"
580
- }), s.abort();
581
- },
582
- onFail: (r, u) => {
583
- this.#n({ type: "failed", failureCount: r, error: u });
584
- },
585
- onPause: () => {
586
- this.#n({ type: "pause" });
587
- },
588
- onContinue: () => {
589
- this.#n({ type: "continue" });
590
- },
591
- retry: o.options.retry,
592
- retryDelay: o.options.retryDelay,
593
- networkMode: o.options.networkMode,
594
- canRun: () => !0
595
- });
596
- try {
597
- const r = await this.#i.start();
598
- if (r === void 0)
599
- throw new Error(`${this.queryHash} data is undefined`);
600
- return this.setData(r), this.#s.config.onSuccess?.(r, this), this.#s.config.onSettled?.(
601
- r,
602
- this.state.error,
603
- this
604
- ), r;
605
- } catch (r) {
606
- if (r instanceof K) {
607
- if (r.silent)
608
- return this.#i.promise;
609
- if (r.revert) {
610
- if (this.state.data === void 0)
611
- throw r;
612
- return this.state.data;
613
- }
614
- }
615
- throw this.#n({
616
- type: "error",
617
- error: r
618
- }), this.#s.config.onError?.(
619
- r,
620
- this
621
- ), this.#s.config.onSettled?.(
622
- this.state.data,
623
- r,
624
- this
625
- ), r;
626
- } finally {
627
- this.scheduleGc();
628
- }
629
- }
630
- #n(t) {
631
- const e = (s) => {
632
- switch (t.type) {
633
- case "failed":
634
- return {
635
- ...s,
636
- fetchFailureCount: t.failureCount,
637
- fetchFailureReason: t.error
638
- };
639
- case "pause":
640
- return {
641
- ...s,
642
- fetchStatus: "paused"
643
- };
644
- case "continue":
645
- return {
646
- ...s,
647
- fetchStatus: "fetching"
648
- };
649
- case "fetch":
650
- return {
651
- ...s,
652
- ...vt(s.data, this.options),
653
- fetchMeta: t.meta ?? null
654
- };
655
- case "success":
656
- const i = {
657
- ...s,
658
- ...G(t.data, t.dataUpdatedAt),
659
- dataUpdateCount: s.dataUpdateCount + 1,
660
- ...!t.manual && {
661
- fetchStatus: "idle",
662
- fetchFailureCount: 0,
663
- fetchFailureReason: null
664
- }
665
- };
666
- return this.#e = t.manual ? i : void 0, i;
667
- case "error":
668
- const n = t.error;
669
- return {
670
- ...s,
671
- error: n,
672
- errorUpdateCount: s.errorUpdateCount + 1,
673
- errorUpdatedAt: Date.now(),
674
- fetchFailureCount: s.fetchFailureCount + 1,
675
- fetchFailureReason: n,
676
- fetchStatus: "idle",
677
- status: "error"
678
- };
679
- case "invalidate":
680
- return {
681
- ...s,
682
- isInvalidated: !0
683
- };
684
- case "setState":
685
- return {
686
- ...s,
687
- ...t.state
688
- };
689
- }
690
- };
691
- this.state = e(this.state), y.batch(() => {
692
- this.observers.forEach((s) => {
693
- s.onQueryUpdate();
694
- }), this.#s.notify({ query: this, type: "updated", action: t });
695
- });
696
- }
697
- };
698
- function vt(t, e) {
699
- return {
700
- fetchFailureCount: 0,
701
- fetchFailureReason: null,
702
- fetchStatus: B(e.networkMode) ? "fetching" : "paused",
703
- ...t === void 0 && {
704
- error: null,
705
- status: "pending"
706
- }
707
- };
708
- }
709
- function G(t, e) {
710
- return {
711
- data: t,
712
- dataUpdatedAt: e ?? Date.now(),
713
- error: null,
714
- isInvalidated: !1,
715
- status: "success"
716
- };
717
- }
718
- function N(t) {
719
- const e = typeof t.initialData == "function" ? t.initialData() : t.initialData, s = e !== void 0, i = s ? typeof t.initialDataUpdatedAt == "function" ? t.initialDataUpdatedAt() : t.initialDataUpdatedAt : 0;
720
- return {
721
- data: e,
722
- dataUpdateCount: 0,
723
- dataUpdatedAt: s ? i ?? Date.now() : 0,
724
- error: null,
725
- errorUpdateCount: 0,
726
- errorUpdatedAt: 0,
727
- fetchFailureCount: 0,
728
- fetchFailureReason: null,
729
- fetchMeta: null,
730
- isInvalidated: !1,
731
- status: s ? "success" : "pending",
732
- fetchStatus: "idle"
733
- };
734
- }
735
- function V(t) {
736
- return {
737
- onFetch: (e, s) => {
738
- const i = e.options, n = e.fetchOptions?.meta?.fetchMore?.direction, a = e.state.data?.pages || [], o = e.state.data?.pageParams || [];
739
- let r = { pages: [], pageParams: [] }, u = 0;
740
- const h = async () => {
741
- let d = !1;
742
- const l = (f) => {
743
- Object.defineProperty(f, "signal", {
744
- enumerable: !0,
745
- get: () => (e.signal.aborted ? d = !0 : e.signal.addEventListener("abort", () => {
746
- d = !0;
747
- }), e.signal)
748
- });
749
- }, m = J(e.options, e.fetchOptions), b = async (f, c, p) => {
750
- if (d)
751
- return Promise.reject();
752
- if (c == null && f.pages.length)
753
- return Promise.resolve(f);
754
- const w = (() => {
755
- const k = {
756
- client: e.client,
757
- queryKey: e.queryKey,
758
- pageParam: c,
759
- direction: p ? "backward" : "forward",
760
- meta: e.options.meta
761
- };
762
- return l(k), k;
763
- })(), O = await m(w), { maxPages: q } = e.options, S = p ? ht : ut;
764
- return {
765
- pages: S(f.pages, O, q),
766
- pageParams: S(f.pageParams, c, q)
767
- };
768
- };
769
- if (n && a.length) {
770
- const f = n === "backward", c = f ? gt : _, p = {
771
- pages: a,
772
- pageParams: o
773
- }, g = c(i, p);
774
- r = await b(p, g, f);
775
- } else {
776
- const f = t ?? a.length;
777
- do {
778
- const c = u === 0 ? o[0] ?? i.initialPageParam : _(i, r);
779
- if (u > 0 && c == null)
780
- break;
781
- r = await b(r, c), u++;
782
- } while (u < f);
783
- }
784
- return r;
785
- };
786
- e.options.persister ? e.fetchFn = () => e.options.persister?.(
787
- h,
788
- {
789
- client: e.client,
790
- queryKey: e.queryKey,
791
- meta: e.options.meta,
792
- signal: e.signal
793
- },
794
- s
795
- ) : e.fetchFn = h;
796
- }
797
- };
798
- }
799
- function _(t, { pages: e, pageParams: s }) {
800
- const i = e.length - 1;
801
- return e.length > 0 ? t.getNextPageParam(
802
- e[i],
803
- e,
804
- s[i],
805
- s
806
- ) : void 0;
807
- }
808
- function gt(t, { pages: e, pageParams: s }) {
809
- return e.length > 0 ? t.getPreviousPageParam?.(e[0], e, s[0], s) : void 0;
810
- }
811
- var bt = class extends Z {
812
- #t;
813
- #e;
814
- #s;
815
- #r;
816
- constructor(t) {
817
- super(), this.#t = t.client, this.mutationId = t.mutationId, this.#s = t.mutationCache, this.#e = [], this.state = t.state || wt(), this.setOptions(t.options), this.scheduleGc();
818
- }
819
- setOptions(t) {
820
- this.options = t, this.updateGcTime(this.options.gcTime);
821
- }
822
- get meta() {
823
- return this.options.meta;
824
- }
825
- addObserver(t) {
826
- this.#e.includes(t) || (this.#e.push(t), this.clearGcTimeout(), this.#s.notify({
827
- type: "observerAdded",
828
- mutation: this,
829
- observer: t
830
- }));
831
- }
832
- removeObserver(t) {
833
- this.#e = this.#e.filter((e) => e !== t), this.scheduleGc(), this.#s.notify({
834
- type: "observerRemoved",
835
- mutation: this,
836
- observer: t
837
- });
838
- }
839
- optionalRemove() {
840
- this.#e.length || (this.state.status === "pending" ? this.scheduleGc() : this.#s.remove(this));
841
- }
842
- continue() {
843
- return this.#r?.continue() ?? // continuing a mutation assumes that variables are set, mutation must have been dehydrated before
844
- this.execute(this.state.variables);
845
- }
846
- async execute(t) {
847
- const e = () => {
848
- this.#i({ type: "continue" });
849
- }, s = {
850
- client: this.#t,
851
- meta: this.options.meta,
852
- mutationKey: this.options.mutationKey
853
- };
854
- this.#r = W({
855
- fn: () => this.options.mutationFn ? this.options.mutationFn(t, s) : Promise.reject(new Error("No mutationFn found")),
856
- onFail: (a, o) => {
857
- this.#i({ type: "failed", failureCount: a, error: o });
858
- },
859
- onPause: () => {
860
- this.#i({ type: "pause" });
861
- },
862
- onContinue: e,
863
- retry: this.options.retry ?? 0,
864
- retryDelay: this.options.retryDelay,
865
- networkMode: this.options.networkMode,
866
- canRun: () => this.#s.canRun(this)
867
- });
868
- const i = this.state.status === "pending", n = !this.#r.canStart();
869
- try {
870
- if (i)
871
- e();
872
- else {
873
- this.#i({ type: "pending", variables: t, isPaused: n }), await this.#s.config.onMutate?.(
874
- t,
875
- this,
876
- s
877
- );
878
- const o = await this.options.onMutate?.(
879
- t,
880
- s
881
- );
882
- o !== this.state.context && this.#i({
883
- type: "pending",
884
- context: o,
885
- variables: t,
886
- isPaused: n
887
- });
888
- }
889
- const a = await this.#r.start();
890
- return await this.#s.config.onSuccess?.(
891
- a,
892
- t,
893
- this.state.context,
894
- this,
895
- s
896
- ), await this.options.onSuccess?.(
897
- a,
898
- t,
899
- this.state.context,
900
- s
901
- ), await this.#s.config.onSettled?.(
902
- a,
903
- null,
904
- this.state.variables,
905
- this.state.context,
906
- this,
907
- s
908
- ), await this.options.onSettled?.(
909
- a,
910
- null,
911
- t,
912
- this.state.context,
913
- s
914
- ), this.#i({ type: "success", data: a }), a;
915
- } catch (a) {
916
- try {
917
- throw await this.#s.config.onError?.(
918
- a,
919
- t,
920
- this.state.context,
921
- this,
922
- s
923
- ), await this.options.onError?.(
924
- a,
925
- t,
926
- this.state.context,
927
- s
928
- ), await this.#s.config.onSettled?.(
929
- void 0,
930
- a,
931
- this.state.variables,
932
- this.state.context,
933
- this,
934
- s
935
- ), await this.options.onSettled?.(
936
- void 0,
937
- a,
938
- t,
939
- this.state.context,
940
- s
941
- ), a;
942
- } finally {
943
- this.#i({ type: "error", error: a });
944
- }
945
- } finally {
946
- this.#s.runNext(this);
947
- }
948
- }
949
- #i(t) {
950
- const e = (s) => {
951
- switch (t.type) {
952
- case "failed":
953
- return {
954
- ...s,
955
- failureCount: t.failureCount,
956
- failureReason: t.error
957
- };
958
- case "pause":
959
- return {
960
- ...s,
961
- isPaused: !0
962
- };
963
- case "continue":
964
- return {
965
- ...s,
966
- isPaused: !1
967
- };
968
- case "pending":
969
- return {
970
- ...s,
971
- context: t.context,
972
- data: void 0,
973
- failureCount: 0,
974
- failureReason: null,
975
- error: null,
976
- isPaused: t.isPaused,
977
- status: "pending",
978
- variables: t.variables,
979
- submittedAt: Date.now()
980
- };
981
- case "success":
982
- return {
983
- ...s,
984
- data: t.data,
985
- failureCount: 0,
986
- failureReason: null,
987
- error: null,
988
- status: "success",
989
- isPaused: !1
990
- };
991
- case "error":
992
- return {
993
- ...s,
994
- data: void 0,
995
- error: t.error,
996
- failureCount: s.failureCount + 1,
997
- failureReason: t.error,
998
- isPaused: !1,
999
- status: "error"
1000
- };
1001
- }
1002
- };
1003
- this.state = e(this.state), y.batch(() => {
1004
- this.#e.forEach((s) => {
1005
- s.onMutationUpdate(t);
1006
- }), this.#s.notify({
1007
- mutation: this,
1008
- type: "updated",
1009
- action: t
1010
- });
1011
- });
1012
- }
1013
- };
1014
- function wt() {
1015
- return {
1016
- context: void 0,
1017
- data: void 0,
1018
- error: null,
1019
- failureCount: 0,
1020
- failureReason: null,
1021
- isPaused: !1,
1022
- status: "idle",
1023
- variables: void 0,
1024
- submittedAt: 0
1025
- };
1026
- }
1027
- var Ct = class extends T {
1028
- constructor(t = {}) {
1029
- super(), this.config = t, this.#t = /* @__PURE__ */ new Set(), this.#e = /* @__PURE__ */ new Map(), this.#s = 0;
1030
- }
1031
- #t;
1032
- #e;
1033
- #s;
1034
- build(t, e, s) {
1035
- const i = new bt({
1036
- client: t,
1037
- mutationCache: this,
1038
- mutationId: ++this.#s,
1039
- options: t.defaultMutationOptions(e),
1040
- state: s
1041
- });
1042
- return this.add(i), i;
1043
- }
1044
- add(t) {
1045
- this.#t.add(t);
1046
- const e = A(t);
1047
- if (typeof e == "string") {
1048
- const s = this.#e.get(e);
1049
- s ? s.push(t) : this.#e.set(e, [t]);
1050
- }
1051
- this.notify({ type: "added", mutation: t });
1052
- }
1053
- remove(t) {
1054
- if (this.#t.delete(t)) {
1055
- const e = A(t);
1056
- if (typeof e == "string") {
1057
- const s = this.#e.get(e);
1058
- if (s)
1059
- if (s.length > 1) {
1060
- const i = s.indexOf(t);
1061
- i !== -1 && s.splice(i, 1);
1062
- } else s[0] === t && this.#e.delete(e);
1063
- }
1064
- }
1065
- this.notify({ type: "removed", mutation: t });
1066
- }
1067
- canRun(t) {
1068
- const e = A(t);
1069
- if (typeof e == "string") {
1070
- const i = this.#e.get(e)?.find(
1071
- (n) => n.state.status === "pending"
1072
- );
1073
- return !i || i === t;
1074
- } else
1075
- return !0;
1076
- }
1077
- runNext(t) {
1078
- const e = A(t);
1079
- return typeof e == "string" ? this.#e.get(e)?.find((i) => i !== t && i.state.isPaused)?.continue() ?? Promise.resolve() : Promise.resolve();
1080
- }
1081
- clear() {
1082
- y.batch(() => {
1083
- this.#t.forEach((t) => {
1084
- this.notify({ type: "removed", mutation: t });
1085
- }), this.#t.clear(), this.#e.clear();
1086
- });
1087
- }
1088
- getAll() {
1089
- return Array.from(this.#t);
1090
- }
1091
- find(t) {
1092
- const e = { exact: !0, ...t };
1093
- return this.getAll().find(
1094
- (s) => x(e, s)
1095
- );
1096
- }
1097
- findAll(t = {}) {
1098
- return this.getAll().filter((e) => x(t, e));
1099
- }
1100
- notify(t) {
1101
- y.batch(() => {
1102
- this.listeners.forEach((e) => {
1103
- e(t);
1104
- });
1105
- });
1106
- }
1107
- resumePausedMutations() {
1108
- const t = this.getAll().filter((e) => e.state.isPaused);
1109
- return y.batch(
1110
- () => Promise.all(
1111
- t.map((e) => e.continue().catch(v))
1112
- )
1113
- );
1114
- }
1115
- };
1116
- function A(t) {
1117
- return t.options.scope?.id;
1118
- }
1119
- var Ot = class extends T {
1120
- constructor(t = {}) {
1121
- super(), this.config = t, this.#t = /* @__PURE__ */ new Map();
1122
- }
1123
- #t;
1124
- build(t, e, s) {
1125
- const i = e.queryKey, n = e.queryHash ?? j(i, e);
1126
- let a = this.get(n);
1127
- return a || (a = new mt({
1128
- client: t,
1129
- queryKey: i,
1130
- queryHash: n,
1131
- options: t.defaultQueryOptions(e),
1132
- state: s,
1133
- defaultOptions: t.getQueryDefaults(i)
1134
- }), this.add(a)), a;
1135
- }
1136
- add(t) {
1137
- this.#t.has(t.queryHash) || (this.#t.set(t.queryHash, t), this.notify({
1138
- type: "added",
1139
- query: t
1140
- }));
1141
- }
1142
- remove(t) {
1143
- const e = this.#t.get(t.queryHash);
1144
- e && (t.destroy(), e === t && this.#t.delete(t.queryHash), this.notify({ type: "removed", query: t }));
1145
- }
1146
- clear() {
1147
- y.batch(() => {
1148
- this.getAll().forEach((t) => {
1149
- this.remove(t);
1150
- });
1151
- });
1152
- }
1153
- get(t) {
1154
- return this.#t.get(t);
1155
- }
1156
- getAll() {
1157
- return [...this.#t.values()];
1158
- }
1159
- find(t) {
1160
- const e = { exact: !0, ...t };
1161
- return this.getAll().find(
1162
- (s) => U(e, s)
1163
- );
1164
- }
1165
- findAll(t = {}) {
1166
- const e = this.getAll();
1167
- return Object.keys(t).length > 0 ? e.filter((s) => U(t, s)) : e;
1168
- }
1169
- notify(t) {
1170
- y.batch(() => {
1171
- this.listeners.forEach((e) => {
1172
- e(t);
1173
- });
1174
- });
1175
- }
1176
- onFocus() {
1177
- y.batch(() => {
1178
- this.getAll().forEach((t) => {
1179
- t.onFocus();
1180
- });
1181
- });
1182
- }
1183
- onOnline() {
1184
- y.batch(() => {
1185
- this.getAll().forEach((t) => {
1186
- t.onOnline();
1187
- });
1188
- });
1189
- }
1190
- }, Pt = class {
1191
- #t;
1192
- #e;
1193
- #s;
1194
- #r;
1195
- #i;
1196
- #a;
1197
- #o;
1198
- #n;
1199
- constructor(t = {}) {
1200
- this.#t = t.queryCache || new Ot(), this.#e = t.mutationCache || new Ct(), this.#s = t.defaultOptions || {}, this.#r = /* @__PURE__ */ new Map(), this.#i = /* @__PURE__ */ new Map(), this.#a = 0;
1201
- }
1202
- mount() {
1203
- this.#a++, this.#a === 1 && (this.#o = z.subscribe(async (t) => {
1204
- t && (await this.resumePausedMutations(), this.#t.onFocus());
1205
- }), this.#n = D.subscribe(async (t) => {
1206
- t && (await this.resumePausedMutations(), this.#t.onOnline());
1207
- }));
1208
- }
1209
- unmount() {
1210
- this.#a--, this.#a === 0 && (this.#o?.(), this.#o = void 0, this.#n?.(), this.#n = void 0);
1211
- }
1212
- isFetching(t) {
1213
- return this.#t.findAll({ ...t, fetchStatus: "fetching" }).length;
1214
- }
1215
- isMutating(t) {
1216
- return this.#e.findAll({ ...t, status: "pending" }).length;
1217
- }
1218
- /**
1219
- * Imperative (non-reactive) way to retrieve data for a QueryKey.
1220
- * Should only be used in callbacks or functions where reading the latest data is necessary, e.g. for optimistic updates.
1221
- *
1222
- * Hint: Do not use this function inside a component, because it won't receive updates.
1223
- * Use `useQuery` to create a `QueryObserver` that subscribes to changes.
1224
- */
1225
- getQueryData(t) {
1226
- const e = this.defaultQueryOptions({ queryKey: t });
1227
- return this.#t.get(e.queryHash)?.state.data;
1228
- }
1229
- ensureQueryData(t) {
1230
- const e = this.defaultQueryOptions(t), s = this.#t.build(this, e), i = s.state.data;
1231
- return i === void 0 ? this.fetchQuery(t) : (t.revalidateIfStale && s.isStaleByTime(E(e.staleTime, s)) && this.prefetchQuery(e), Promise.resolve(i));
1232
- }
1233
- getQueriesData(t) {
1234
- return this.#t.findAll(t).map(({ queryKey: e, state: s }) => {
1235
- const i = s.data;
1236
- return [e, i];
1237
- });
1238
- }
1239
- setQueryData(t, e, s) {
1240
- const i = this.defaultQueryOptions({ queryKey: t }), a = this.#t.get(
1241
- i.queryHash
1242
- )?.state.data, o = et(e, a);
1243
- if (o !== void 0)
1244
- return this.#t.build(this, i).setData(o, { ...s, manual: !0 });
1245
- }
1246
- setQueriesData(t, e, s) {
1247
- return y.batch(
1248
- () => this.#t.findAll(t).map(({ queryKey: i }) => [
1249
- i,
1250
- this.setQueryData(i, e, s)
1251
- ])
1252
- );
1253
- }
1254
- getQueryState(t) {
1255
- const e = this.defaultQueryOptions({ queryKey: t });
1256
- return this.#t.get(
1257
- e.queryHash
1258
- )?.state;
1259
- }
1260
- removeQueries(t) {
1261
- const e = this.#t;
1262
- y.batch(() => {
1263
- e.findAll(t).forEach((s) => {
1264
- e.remove(s);
1265
- });
1266
- });
1267
- }
1268
- resetQueries(t, e) {
1269
- const s = this.#t;
1270
- return y.batch(() => (s.findAll(t).forEach((i) => {
1271
- i.reset();
1272
- }), this.refetchQueries(
1273
- {
1274
- type: "active",
1275
- ...t
1276
- },
1277
- e
1278
- )));
1279
- }
1280
- cancelQueries(t, e = {}) {
1281
- const s = { revert: !0, ...e }, i = y.batch(
1282
- () => this.#t.findAll(t).map((n) => n.cancel(s))
1283
- );
1284
- return Promise.all(i).then(v).catch(v);
1285
- }
1286
- invalidateQueries(t, e = {}) {
1287
- return y.batch(() => (this.#t.findAll(t).forEach((s) => {
1288
- s.invalidate();
1289
- }), t?.refetchType === "none" ? Promise.resolve() : this.refetchQueries(
1290
- {
1291
- ...t,
1292
- type: t?.refetchType ?? t?.type ?? "active"
1293
- },
1294
- e
1295
- )));
1296
- }
1297
- refetchQueries(t, e = {}) {
1298
- const s = {
1299
- ...e,
1300
- cancelRefetch: e.cancelRefetch ?? !0
1301
- }, i = y.batch(
1302
- () => this.#t.findAll(t).filter((n) => !n.isDisabled() && !n.isStatic()).map((n) => {
1303
- let a = n.fetch(void 0, s);
1304
- return s.throwOnError || (a = a.catch(v)), n.state.fetchStatus === "paused" ? Promise.resolve() : a;
1305
- })
1306
- );
1307
- return Promise.all(i).then(v);
1308
- }
1309
- fetchQuery(t) {
1310
- const e = this.defaultQueryOptions(t);
1311
- e.retry === void 0 && (e.retry = !1);
1312
- const s = this.#t.build(this, e);
1313
- return s.isStaleByTime(
1314
- E(e.staleTime, s)
1315
- ) ? s.fetch(e) : Promise.resolve(s.state.data);
1316
- }
1317
- prefetchQuery(t) {
1318
- return this.fetchQuery(t).then(v).catch(v);
1319
- }
1320
- fetchInfiniteQuery(t) {
1321
- return t.behavior = V(t.pages), this.fetchQuery(t);
1322
- }
1323
- prefetchInfiniteQuery(t) {
1324
- return this.fetchInfiniteQuery(t).then(v).catch(v);
1325
- }
1326
- ensureInfiniteQueryData(t) {
1327
- return t.behavior = V(t.pages), this.ensureQueryData(t);
1328
- }
1329
- resumePausedMutations() {
1330
- return D.isOnline() ? this.#e.resumePausedMutations() : Promise.resolve();
1331
- }
1332
- getQueryCache() {
1333
- return this.#t;
1334
- }
1335
- getMutationCache() {
1336
- return this.#e;
1337
- }
1338
- getDefaultOptions() {
1339
- return this.#s;
1340
- }
1341
- setDefaultOptions(t) {
1342
- this.#s = t;
1343
- }
1344
- setQueryDefaults(t, e) {
1345
- this.#r.set(P(t), {
1346
- queryKey: t,
1347
- defaultOptions: e
1348
- });
1349
- }
1350
- getQueryDefaults(t) {
1351
- const e = [...this.#r.values()], s = {};
1352
- return e.forEach((i) => {
1353
- F(t, i.queryKey) && Object.assign(s, i.defaultOptions);
1354
- }), s;
1355
- }
1356
- setMutationDefaults(t, e) {
1357
- this.#i.set(P(t), {
1358
- mutationKey: t,
1359
- defaultOptions: e
1360
- });
1361
- }
1362
- getMutationDefaults(t) {
1363
- const e = [...this.#i.values()], s = {};
1364
- return e.forEach((i) => {
1365
- F(t, i.mutationKey) && Object.assign(s, i.defaultOptions);
1366
- }), s;
1367
- }
1368
- defaultQueryOptions(t) {
1369
- if (t._defaulted)
1370
- return t;
1371
- const e = {
1372
- ...this.#s.queries,
1373
- ...this.getQueryDefaults(t.queryKey),
1374
- ...t,
1375
- _defaulted: !0
1376
- };
1377
- return e.queryHash || (e.queryHash = j(
1378
- e.queryKey,
1379
- e
1380
- )), e.refetchOnReconnect === void 0 && (e.refetchOnReconnect = e.networkMode !== "always"), e.throwOnError === void 0 && (e.throwOnError = !!e.suspense), !e.networkMode && e.persister && (e.networkMode = "offlineFirst"), e.queryFn === I && (e.enabled = !1), e;
1381
- }
1382
- defaultMutationOptions(t) {
1383
- return t?._defaulted ? t : {
1384
- ...this.#s.mutations,
1385
- ...t?.mutationKey && this.getMutationDefaults(t.mutationKey),
1386
- ...t,
1387
- _defaulted: !0
1388
- };
1389
- }
1390
- clear() {
1391
- this.#t.clear(), this.#e.clear();
1392
- }
1393
- };
1394
- class C {
1395
- constructor(e = {}) {
1396
- this.availableDatasets = [], this.apiUrl = e.apiUrl || "https://api.luzmo.com", this.apiVersion = e.apiVersion || "0.1.0", this.authKey = e.authKey || "", this.authToken = e.authToken || "", this.queryClient = new Pt({
1397
- defaultOptions: {
1398
- queries: {
1399
- staleTime: e.staleTime || 300 * 1e3,
1400
- // 5 minutes
1401
- gcTime: e.gcTime || 600 * 1e3,
1402
- // 10 minutes
1403
- retry: e.retry || 3,
1404
- retryDelay: e.retryDelay || ((s) => Math.min(1e3 * 2 ** s, 3e4))
1405
- }
1406
- }
1407
- }), this.initNetworkListeners();
1408
- }
1409
- /**
1410
- * Set API configuration
1411
- * @param config - API configuration
1412
- */
1413
- configure(e = {}) {
1414
- if (e.apiVersion && (this.apiVersion = e.apiVersion), e.apiUrl && (this.apiUrl = e.apiUrl), e.authKey && (this.authKey = e.authKey), e.authToken && (this.authToken = e.authToken), e.staleTime || e.gcTime || e.retry) {
1415
- const s = {};
1416
- e.staleTime && (s.staleTime = e.staleTime), e.gcTime && (s.gcTime = e.gcTime), e.retry && (s.retry = e.retry), this.queryClient.setDefaultOptions({
1417
- queries: {
1418
- ...this.queryClient.getDefaultOptions().queries,
1419
- ...s
1420
- }
1421
- });
1422
- }
1423
- }
1424
- /**
1425
- * Initialize network status listeners
1426
- */
1427
- initNetworkListeners() {
1428
- typeof window < "u" && window.addEventListener("online", () => {
1429
- console.warn("Network connection restored, refreshing data..."), this.refreshAll();
1430
- });
1431
- }
1432
- /**
1433
- * Get API headers
1434
- * @param additionalHeaders - Additional headers to include
1435
- * @returns Headers for API requests
1436
- */
1437
- getHeaders(e = {}) {
1438
- return {
1439
- "Content-Type": "application/json",
1440
- ...e
1441
- };
1442
- }
1443
- /**
1444
- * Make API request with advanced error handling
1445
- * Default method is POST and supports an optional JSON body
1446
- * @param endpoint - API endpoint
1447
- * @param jsonBody - Optional JSON body to send with request
1448
- * @param options - Additional fetch options
1449
- * @returns API response
1450
- * @throws {Error} If API request fails
1451
- */
1452
- async fetchApi(e, s, i = {}) {
1453
- const n = `${this.apiUrl}/${this.apiVersion}${e}`, o = {
1454
- method: i.method || "POST",
1455
- headers: this.getHeaders(i.headers),
1456
- mode: "cors",
1457
- ...i
1458
- };
1459
- s !== void 0 && (s.key = this.authKey, s.token = this.authToken, o.body = JSON.stringify(s));
1460
- try {
1461
- const r = await fetch(n, o);
1462
- if (!r.ok) {
1463
- const u = await r.json().catch(() => null);
1464
- throw r.status === 401 || r.status === 403 ? new Error(
1465
- "Authentication failed. Please check your API token."
1466
- ) : r.status === 404 ? new Error(`Resource not found: ${e}`) : r.status === 429 ? new Error("Rate limit exceeded. Please try again later.") : new Error(
1467
- u?.message || `API request failed with status ${r.status}`
1468
- );
1469
- }
1470
- return await r.json();
1471
- } catch (r) {
1472
- throw console.error(`API request to ${e} failed:`, r), r instanceof Error && (r.endpoint = e, r.timestamp = (/* @__PURE__ */ new Date()).toISOString()), r;
1473
- }
1474
- }
1475
- /**
1476
- * Fetch all available datasets with pagination support
1477
- * @param options - Pagination options
1478
- * @returns Paginated list of datasets
1479
- */
1480
- async fetchAllDatasets(e = {}) {
1481
- const s = e.offset || 0, i = e.limit || 50, n = ["datasets", s, i];
1482
- return await this.queryClient.fetchQuery({
1483
- queryKey: n,
1484
- queryFn: async () => {
1485
- const a = {
1486
- action: "get",
1487
- version: this.apiVersion,
1488
- find: {
1489
- where: {
1490
- type: "dataset"
1491
- },
1492
- limit: i,
1493
- offset: s
1494
- }
1495
- }, o = await this.fetchApi("/securable", a);
1496
- return {
1497
- data: o?.rows ?? [],
1498
- pagination: {
1499
- offset: s,
1500
- limit: i,
1501
- total: o?.count ?? 0,
1502
- pages: Math.ceil((o?.count ?? 0) / i)
1503
- }
1504
- };
1505
- }
1506
- });
1507
- }
1508
- /**
1509
- * Search datasets by name or description
1510
- * @param query - Search query
1511
- * @returns List of matching datasets
1512
- */
1513
- async searchDatasets(e, s) {
1514
- if (!e)
1515
- return { data: [] };
1516
- const i = ["datasets", "search", e, s];
1517
- return await this.queryClient.fetchQuery({
1518
- queryKey: i,
1519
- queryFn: async () => {
1520
- const n = {
1521
- action: "get",
1522
- version: this.apiVersion,
1523
- find: {
1524
- where: {
1525
- type: "dataset"
1526
- }
1527
- }
1528
- };
1529
- e?.length > 0 && (n.find.search = {
1530
- match_types: ["name"],
1531
- keyphrase: e
1532
- }), s?.offset && (n.find.offset = s?.offset), s?.limit && (n.find.limit = s?.limit);
1533
- const a = await this.fetchApi("/securable", n), o = {
1534
- data: a?.rows ?? []
1535
- };
1536
- return s?.limit && (o.pagination = {
1537
- offset: s?.offset ?? 0,
1538
- limit: s?.limit,
1539
- total: a?.count ?? 0,
1540
- pages: Math.ceil((a?.count ?? 0) / s?.limit)
1541
- }), o;
1542
- }
1543
- });
1544
- }
1545
- /**
1546
- * Fetches multiple datasets with their associated columns and formulas metadata
1547
- * @param datasetIds - Array of dataset IDs to fetch
1548
- * @returns Promise that resolves to an array of DatasetMetadata objects containing:
1549
- * - Basic dataset info (id, name, description)
1550
- * - Columns with metadata including joins, hierarchy levels, and currency info
1551
- * - Formulas with their expressions and currency associations
1552
- * @throws Error if datasetIds is empty or null
1553
- */
1554
- async fetchDatasetsWithColumnsAndFormulas(e) {
1555
- if (!e || e.length === 0)
1556
- throw new Error("At least one dataset ID is required");
1557
- const s = ["datasets", e, this.authKey, this.authToken];
1558
- return await this.queryClient.fetchQuery({
1559
- queryKey: s,
1560
- queryFn: async () => {
1561
- const i = {
1562
- action: "get",
1563
- version: this.apiVersion,
1564
- find: {
1565
- where: {
1566
- type: "dataset",
1567
- id: {
1568
- in: e
1569
- }
1570
- },
1571
- attributes: ["name", "id", "description"],
1572
- include: [
1573
- {
1574
- model: "Column",
1575
- attributes: [
1576
- "id",
1577
- "name",
1578
- "description",
1579
- "type",
1580
- "subtype",
1581
- "format",
1582
- "hidden",
1583
- "lowestLevel",
1584
- "expression",
1585
- "duration_levels",
1586
- "duration_format"
1587
- ],
1588
- separate: !0,
1589
- order: [["order", "asc"]],
1590
- include: [
1591
- {
1592
- model: "Column",
1593
- attributes: [
1594
- "id",
1595
- "securable_id",
1596
- "hierarchy_enabled",
1597
- "currency_id"
1598
- ],
1599
- as: "Joins"
1600
- },
1601
- {
1602
- model: "HierarchyLevel",
1603
- attributes: ["id", "level", "name"],
1604
- as: "HierarchyLevels"
1605
- },
1606
- {
1607
- model: "Currency",
1608
- attributes: ["id", "name", "symbol"],
1609
- as: "Currency"
1610
- }
1611
- ]
1612
- },
1613
- {
1614
- model: "Formula",
1615
- attributes: [
1616
- "id",
1617
- "name",
1618
- "description",
1619
- "type",
1620
- "subtype",
1621
- "format",
1622
- "hidden",
1623
- "lowestLevel",
1624
- "expression",
1625
- "duration_levels",
1626
- "duration_format"
1627
- ],
1628
- include: [
1629
- {
1630
- model: "Currency",
1631
- attributes: ["id", "name", "symbol"],
1632
- as: "Currency"
1633
- }
1634
- ]
1635
- }
1636
- ]
1637
- }
1638
- };
1639
- return (await this.fetchApi("/securable", i))?.rows ?? [];
1640
- }
1641
- });
1642
- }
1643
- /**
1644
- * Fetch data from a dataset with filtering
1645
- * @param datasetId - Dataset ID
1646
- * @param queryParams - Query parameters (filters, sort, etc.)
1647
- * @returns Dataset data
1648
- */
1649
- async fetchData(e) {
1650
- if (!e) throw new Error("Query is required");
1651
- const s = ["data", e];
1652
- return await this.queryClient.fetchQuery({
1653
- queryKey: s,
1654
- queryFn: async () => {
1655
- const i = {
1656
- action: "get",
1657
- version: this.apiVersion,
1658
- find: {
1659
- queries: [e]
1660
- }
1661
- }, n = await this.fetchApi("/data", i);
1662
- return {
1663
- data: n?.data || [],
1664
- performance: n?.performance || {}
1665
- };
1666
- }
1667
- });
1668
- }
1669
- /**
1670
- * Refresh all queries
1671
- */
1672
- refreshAll() {
1673
- this.queryClient.refetchQueries();
1674
- }
1675
- /**
1676
- * Invalidate cached data for a dataset
1677
- * @param datasetId - Dataset ID (optional)
1678
- */
1679
- invalidateDatasetData(e) {
1680
- e ? (this.queryClient.invalidateQueries({ queryKey: ["dataset", e] }), this.queryClient.invalidateQueries({ queryKey: ["columns", e] })) : this.queryClient.invalidateQueries({ queryKey: ["datasets"] });
1681
- }
1682
- /**
1683
- * Invalidate all cached data
1684
- */
1685
- invalidateAll() {
1686
- this.queryClient.clear();
1687
- }
1688
- /**
1689
- * Create a singleton instance
1690
- * @param config - API configuration
1691
- * @returns Singleton instance
1692
- */
1693
- static getInstance(e = {}) {
1694
- return C.instance ? Object.keys(e).length > 0 && C.instance.configure(e) : C.instance = new C(e), C.instance;
1695
- }
1696
- async fetchDatasetsRecursive(e) {
1697
- if (!e || e.length === 0)
1698
- throw new Error("At least one dataset ID is required");
1699
- const s = [...new Set(e)], i = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Map(), a = (o) => {
1700
- o && !i.has(o) && !s.includes(o) && s.push(o);
1701
- };
1702
- for (; s.length > 0; ) {
1703
- const o = [];
1704
- for (; s.length > 0 && o.length < 50; ) {
1705
- const r = s.shift();
1706
- i.has(r) || o.push(r);
1707
- }
1708
- if (o.length !== 0)
1709
- try {
1710
- (await this.fetchDatasetsWithColumnsAndFormulas(o)).forEach((u) => {
1711
- const h = this.postProcessDatasetMetadata(u);
1712
- i.add(h.id), this.queryClient.setQueryData(["dataset", h.id], h), (h.outgoingJoins ?? []).map((l) => l.securable_id).filter((l) => !!l && l !== h.id).forEach((l) => {
1713
- a(l);
1714
- }), n.set(h.id, h), this.availableDatasets.some((l) => l.id === h.id) || this.availableDatasets.push({
1715
- id: h.id,
1716
- name: h.name,
1717
- columns: h.columns
1718
- });
1719
- });
1720
- } catch (r) {
1721
- console.error("Error fetching datasets recursively:", r);
1722
- }
1723
- }
1724
- return [...n.values()];
1725
- }
1726
- postProcessDatasetMetadata(e) {
1727
- const s = [], i = (e.columns ?? []).map((n) => {
1728
- const a = n.joins ?? (Array.isArray(n.joins) ? n.joins : []);
1729
- Array.isArray(a) && a.length > 0 && s.push(...a);
1730
- const { joins: o, ...r } = n;
1731
- return {
1732
- ...r,
1733
- joins: a
1734
- };
1735
- });
1736
- return {
1737
- ...e,
1738
- columns: i,
1739
- formulas: e.formulas ?? [],
1740
- outgoingJoins: s,
1741
- dateLoaded: /* @__PURE__ */ new Date()
1742
- };
1743
- }
1744
- getAvailableDatasets() {
1745
- return this.availableDatasets;
1746
- }
1747
- getLinkedDatasetsIds(e) {
1748
- const s = this.queryClient.getQueryData(["dataset", e]);
1749
- return s ? (s.outgoingJoins ?? []).map((i) => i.securable_id).filter((i) => !!i && i !== e) : [];
1750
- }
1751
- }
1752
- const Ft = C.getInstance();
1753
- export {
1754
- Ft as d
1755
- };