@luzmo/analytics-components-kit 1.0.1-alpha.85 → 1.0.1-alpha.86

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