@perses-dev/plugin-system 0.0.0-snapshot-scatter-chart-embed-8efdfab → 0.0.0-snapshot-explorer-plugin-c4a7621

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 (431) hide show
  1. package/dist/cjs/components/CalculationSelector/CalculationSelector.js +1 -1
  2. package/dist/cjs/components/DatasourceEditorForm/DatasourceEditorForm.js +83 -163
  3. package/dist/cjs/components/DatasourceSelect.js +12 -15
  4. package/dist/cjs/components/HTTPSettingsEditor/HTTPSettingsEditor.js +528 -0
  5. package/dist/cjs/components/{TimeSeriesQueryEditor → HTTPSettingsEditor}/index.js +2 -2
  6. package/dist/cjs/components/LegendOptionsEditor/LegendOptionsEditor.js +8 -7
  7. package/dist/cjs/components/MetricLabelInput/MetricLabelInput.js +41 -0
  8. package/dist/cjs/{validation/resource.js → components/MetricLabelInput/index.js} +15 -9
  9. package/dist/cjs/components/{TraceQueryEditor/TraceQueryEditor.js → MultiQueryEditor/MultiQueryEditor.js} +39 -40
  10. package/dist/cjs/components/{TimeSeriesQueryEditor/TimeSeriesQueryInput.js → MultiQueryEditor/QueryEditorContainer.js} +23 -11
  11. package/dist/cjs/components/MultiQueryEditor/index.js +30 -0
  12. package/dist/cjs/components/OptionsEditorRadios/OptionsEditorRadios.js +3 -3
  13. package/dist/cjs/components/OptionsEditorTabPanel/OptionsEditorTabPanel.js +1 -1
  14. package/dist/cjs/components/OptionsEditorTabs/OptionsEditorTabs.js +3 -3
  15. package/dist/cjs/components/PanelSpecEditor/PanelSpecEditor.js +54 -62
  16. package/dist/cjs/components/PluginEditor/PluginEditor.js +16 -13
  17. package/dist/cjs/components/PluginEditor/plugin-editor-api.js +44 -33
  18. package/dist/cjs/components/PluginKindSelect/PluginKindSelect.js +55 -7
  19. package/dist/cjs/components/PluginRegistry/PluginRegistry.js +9 -10
  20. package/dist/cjs/components/PluginRegistry/plugin-indexes.js +20 -17
  21. package/dist/cjs/components/PluginSpecEditor/PluginSpecEditor.js +3 -3
  22. package/dist/cjs/components/ProjectSelect.js +7 -7
  23. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +131 -0
  24. package/dist/cjs/components/{TraceQueryEditor → TimeRangeControls}/index.js +1 -1
  25. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +394 -439
  26. package/dist/cjs/components/Variables/VariableEditorForm/VariablePreview.js +17 -15
  27. package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +7 -12
  28. package/dist/cjs/components/Variables/variable-model.js +35 -37
  29. package/dist/cjs/components/index.js +4 -1
  30. package/dist/cjs/constants/user-interface-text.js +4 -1
  31. package/dist/cjs/context/ProjectStoreProvider.js +12 -9
  32. package/dist/cjs/context/ValidationProvider.js +69 -0
  33. package/dist/cjs/context/index.js +1 -0
  34. package/dist/cjs/index.js +1 -1
  35. package/dist/{components/TimeSeriesQueryEditor/index.js → cjs/model/explore.js} +4 -3
  36. package/dist/cjs/model/legend.js +5 -5
  37. package/dist/cjs/remote/PersesPlugin.types.js +16 -0
  38. package/dist/cjs/remote/PluginLoaderComponent.js +75 -0
  39. package/dist/cjs/remote/PluginRuntime.js +267 -0
  40. package/dist/cjs/{validation → remote}/index.js +2 -4
  41. package/dist/cjs/remote/remotePluginLoader.js +61 -0
  42. package/dist/cjs/runtime/DataQueriesProvider/DataQueriesProvider.js +23 -14
  43. package/dist/cjs/runtime/DataQueriesProvider/model.js +10 -9
  44. package/dist/cjs/runtime/QueryCountProvider.js +83 -0
  45. package/dist/cjs/runtime/TimeRangeProvider/TimeRangeProvider.js +37 -13
  46. package/dist/cjs/runtime/TimeRangeProvider/TimeRangeProviderWithQueryParams.js +3 -3
  47. package/dist/cjs/runtime/TimeRangeProvider/TimeRangeSettingsProvider.js +100 -0
  48. package/dist/cjs/runtime/TimeRangeProvider/index.js +2 -1
  49. package/dist/cjs/runtime/TimeRangeProvider/query-params.js +20 -23
  50. package/dist/cjs/runtime/UsageMetricsProvider.js +99 -0
  51. package/dist/cjs/runtime/builtin-variables.js +7 -7
  52. package/dist/cjs/runtime/datasources.js +30 -21
  53. package/dist/cjs/runtime/index.js +4 -2
  54. package/dist/cjs/runtime/plugin-registry.js +48 -36
  55. package/dist/cjs/runtime/time-series-queries.js +35 -40
  56. package/dist/cjs/runtime/trace-queries.js +9 -6
  57. package/dist/cjs/runtime/{template-variables.js → variables.js} +38 -48
  58. package/dist/cjs/stories/shared-utils/decorators/WithDataQueries.js +1 -1
  59. package/dist/cjs/stories/shared-utils/decorators/WithPluginRegistry.js +1 -65
  60. package/dist/cjs/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.js +1 -1
  61. package/dist/cjs/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.js +5 -5
  62. package/dist/cjs/stories/shared-utils/decorators/{WithPluginSystemTemplateVariables.js → WithPluginSystemVariables.js} +9 -9
  63. package/dist/cjs/stories/shared-utils/decorators/WithTimeRange.js +1 -1
  64. package/dist/cjs/stories/shared-utils/decorators/index.js +2 -2
  65. package/dist/cjs/test/mock-data.js +25 -4
  66. package/dist/cjs/test/render.js +2 -11
  67. package/dist/cjs/test/test-plugins/bert/index.js +21 -20
  68. package/dist/cjs/test/test-plugins/ernie/index.js +2 -2
  69. package/dist/cjs/test/test-plugins/index.js +3 -1
  70. package/dist/cjs/test-utils/mock-plugin-registry.js +13 -13
  71. package/dist/cjs/utils/action.js +3 -3
  72. package/dist/cjs/utils/variables.js +24 -24
  73. package/dist/components/CalculationSelector/CalculationSelector.d.ts +2 -2
  74. package/dist/components/CalculationSelector/CalculationSelector.d.ts.map +1 -1
  75. package/dist/components/CalculationSelector/CalculationSelector.js +1 -1
  76. package/dist/components/CalculationSelector/CalculationSelector.js.map +1 -1
  77. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts +7 -7
  78. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts.map +1 -1
  79. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js +86 -166
  80. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js.map +1 -1
  81. package/dist/components/DatasourceSelect.d.ts +4 -4
  82. package/dist/components/DatasourceSelect.d.ts.map +1 -1
  83. package/dist/components/DatasourceSelect.js +9 -12
  84. package/dist/components/DatasourceSelect.js.map +1 -1
  85. package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.d.ts +11 -0
  86. package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.d.ts.map +1 -0
  87. package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.js +474 -0
  88. package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.js.map +1 -0
  89. package/dist/components/HTTPSettingsEditor/index.d.ts +2 -0
  90. package/dist/components/HTTPSettingsEditor/index.d.ts.map +1 -0
  91. package/dist/components/HTTPSettingsEditor/index.js +15 -0
  92. package/dist/components/HTTPSettingsEditor/index.js.map +1 -0
  93. package/dist/components/LegendOptionsEditor/LegendOptionsEditor.d.ts +3 -2
  94. package/dist/components/LegendOptionsEditor/LegendOptionsEditor.d.ts.map +1 -1
  95. package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js +10 -9
  96. package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js.map +1 -1
  97. package/dist/components/MetricLabelInput/MetricLabelInput.d.ts +7 -0
  98. package/dist/components/MetricLabelInput/MetricLabelInput.d.ts.map +1 -0
  99. package/dist/components/MetricLabelInput/MetricLabelInput.js +33 -0
  100. package/dist/components/MetricLabelInput/MetricLabelInput.js.map +1 -0
  101. package/dist/components/MetricLabelInput/index.d.ts +2 -0
  102. package/dist/components/MetricLabelInput/index.d.ts.map +1 -0
  103. package/dist/components/MetricLabelInput/index.js +15 -0
  104. package/dist/components/MetricLabelInput/index.js.map +1 -0
  105. package/dist/components/MultiQueryEditor/MultiQueryEditor.d.ts +17 -0
  106. package/dist/components/MultiQueryEditor/MultiQueryEditor.d.ts.map +1 -0
  107. package/dist/components/{TimeSeriesQueryEditor/TimeSeriesQueryEditor.js → MultiQueryEditor/MultiQueryEditor.js} +42 -39
  108. package/dist/components/MultiQueryEditor/MultiQueryEditor.js.map +1 -0
  109. package/dist/components/MultiQueryEditor/QueryEditorContainer.d.ts +29 -0
  110. package/dist/components/MultiQueryEditor/QueryEditorContainer.d.ts.map +1 -0
  111. package/dist/components/{TimeSeriesQueryEditor/TimeSeriesQueryInput.js → MultiQueryEditor/QueryEditorContainer.js} +33 -10
  112. package/dist/components/MultiQueryEditor/QueryEditorContainer.js.map +1 -0
  113. package/dist/components/MultiQueryEditor/index.d.ts +2 -0
  114. package/dist/components/MultiQueryEditor/index.d.ts.map +1 -0
  115. package/dist/components/MultiQueryEditor/index.js +15 -0
  116. package/dist/components/{TraceQueryEditor → MultiQueryEditor}/index.js.map +1 -1
  117. package/dist/components/OptionsEditorRadios/OptionsEditorRadios.d.ts +4 -4
  118. package/dist/components/OptionsEditorRadios/OptionsEditorRadios.d.ts.map +1 -1
  119. package/dist/components/OptionsEditorRadios/OptionsEditorRadios.js +3 -3
  120. package/dist/components/OptionsEditorRadios/OptionsEditorRadios.js.map +1 -1
  121. package/dist/components/OptionsEditorTabPanel/OptionsEditorTabPanel.d.ts +2 -2
  122. package/dist/components/OptionsEditorTabPanel/OptionsEditorTabPanel.d.ts.map +1 -1
  123. package/dist/components/OptionsEditorTabPanel/OptionsEditorTabPanel.js +1 -1
  124. package/dist/components/OptionsEditorTabPanel/OptionsEditorTabPanel.js.map +1 -1
  125. package/dist/components/OptionsEditorTabs/OptionsEditorTabs.d.ts +5 -5
  126. package/dist/components/OptionsEditorTabs/OptionsEditorTabs.d.ts.map +1 -1
  127. package/dist/components/OptionsEditorTabs/OptionsEditorTabs.js +3 -3
  128. package/dist/components/OptionsEditorTabs/OptionsEditorTabs.js.map +1 -1
  129. package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts +5 -3
  130. package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts.map +1 -1
  131. package/dist/components/PanelSpecEditor/PanelSpecEditor.js +56 -64
  132. package/dist/components/PanelSpecEditor/PanelSpecEditor.js.map +1 -1
  133. package/dist/components/PluginEditor/PluginEditor.d.ts +2 -2
  134. package/dist/components/PluginEditor/PluginEditor.d.ts.map +1 -1
  135. package/dist/components/PluginEditor/PluginEditor.js +16 -13
  136. package/dist/components/PluginEditor/PluginEditor.js.map +1 -1
  137. package/dist/components/PluginEditor/plugin-editor-api.d.ts +16 -10
  138. package/dist/components/PluginEditor/plugin-editor-api.d.ts.map +1 -1
  139. package/dist/components/PluginEditor/plugin-editor-api.js +44 -33
  140. package/dist/components/PluginEditor/plugin-editor-api.js.map +1 -1
  141. package/dist/components/PluginKindSelect/PluginKindSelect.d.ts +11 -5
  142. package/dist/components/PluginKindSelect/PluginKindSelect.d.ts.map +1 -1
  143. package/dist/components/PluginKindSelect/PluginKindSelect.js +61 -10
  144. package/dist/components/PluginKindSelect/PluginKindSelect.js.map +1 -1
  145. package/dist/components/PluginRegistry/PluginRegistry.d.ts +4 -4
  146. package/dist/components/PluginRegistry/PluginRegistry.d.ts.map +1 -1
  147. package/dist/components/PluginRegistry/PluginRegistry.js +9 -10
  148. package/dist/components/PluginRegistry/PluginRegistry.js.map +1 -1
  149. package/dist/components/PluginRegistry/plugin-indexes.d.ts +4 -4
  150. package/dist/components/PluginRegistry/plugin-indexes.d.ts.map +1 -1
  151. package/dist/components/PluginRegistry/plugin-indexes.js +17 -14
  152. package/dist/components/PluginRegistry/plugin-indexes.js.map +1 -1
  153. package/dist/components/PluginSpecEditor/PluginSpecEditor.d.ts +5 -5
  154. package/dist/components/PluginSpecEditor/PluginSpecEditor.d.ts.map +1 -1
  155. package/dist/components/PluginSpecEditor/PluginSpecEditor.js +3 -3
  156. package/dist/components/PluginSpecEditor/PluginSpecEditor.js.map +1 -1
  157. package/dist/components/ProjectSelect.d.ts +3 -3
  158. package/dist/components/ProjectSelect.d.ts.map +1 -1
  159. package/dist/components/ProjectSelect.js +7 -7
  160. package/dist/components/ProjectSelect.js.map +1 -1
  161. package/dist/components/TimeRangeControls/TimeRangeControls.d.ts +14 -0
  162. package/dist/components/TimeRangeControls/TimeRangeControls.d.ts.map +1 -0
  163. package/dist/components/TimeRangeControls/TimeRangeControls.js +110 -0
  164. package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -0
  165. package/dist/components/TimeRangeControls/index.d.ts +2 -0
  166. package/dist/components/TimeRangeControls/index.d.ts.map +1 -0
  167. package/dist/components/{TraceQueryEditor → TimeRangeControls}/index.js +1 -1
  168. package/dist/components/TimeRangeControls/index.js.map +1 -0
  169. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts +4 -3
  170. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
  171. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +395 -442
  172. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
  173. package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts +3 -3
  174. package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts.map +1 -1
  175. package/dist/components/Variables/VariableEditorForm/VariablePreview.js +11 -11
  176. package/dist/components/Variables/VariableEditorForm/VariablePreview.js.map +1 -1
  177. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts +3 -3
  178. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts.map +1 -1
  179. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +7 -12
  180. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -1
  181. package/dist/components/Variables/variable-model.d.ts +2 -1
  182. package/dist/components/Variables/variable-model.d.ts.map +1 -1
  183. package/dist/components/Variables/variable-model.js +29 -31
  184. package/dist/components/Variables/variable-model.js.map +1 -1
  185. package/dist/components/index.d.ts +4 -1
  186. package/dist/components/index.d.ts.map +1 -1
  187. package/dist/components/index.js +4 -1
  188. package/dist/components/index.js.map +1 -1
  189. package/dist/constants/user-interface-text.d.ts +2 -0
  190. package/dist/constants/user-interface-text.d.ts.map +1 -1
  191. package/dist/constants/user-interface-text.js +4 -1
  192. package/dist/constants/user-interface-text.js.map +1 -1
  193. package/dist/context/ProjectStoreProvider.d.ts +4 -4
  194. package/dist/context/ProjectStoreProvider.d.ts.map +1 -1
  195. package/dist/context/ProjectStoreProvider.js +9 -6
  196. package/dist/context/ProjectStoreProvider.js.map +1 -1
  197. package/dist/context/ValidationProvider.d.ts +19 -0
  198. package/dist/context/ValidationProvider.d.ts.map +1 -0
  199. package/dist/context/ValidationProvider.js +52 -0
  200. package/dist/context/ValidationProvider.js.map +1 -0
  201. package/dist/context/index.d.ts +1 -0
  202. package/dist/context/index.d.ts.map +1 -1
  203. package/dist/context/index.js +1 -0
  204. package/dist/context/index.js.map +1 -1
  205. package/dist/context/query-params.d.ts.map +1 -1
  206. package/dist/context/query-params.js.map +1 -1
  207. package/dist/index.d.ts +1 -1
  208. package/dist/index.d.ts.map +1 -1
  209. package/dist/index.js +1 -1
  210. package/dist/index.js.map +1 -1
  211. package/dist/model/datasource.js +3 -1
  212. package/dist/model/datasource.js.map +1 -1
  213. package/dist/model/explore.d.ts +13 -0
  214. package/dist/model/explore.d.ts.map +1 -0
  215. package/dist/{validation/resource.js → model/explore.js} +4 -3
  216. package/dist/model/explore.js.map +1 -0
  217. package/dist/model/legend.d.ts +2 -2
  218. package/dist/model/legend.d.ts.map +1 -1
  219. package/dist/model/legend.js.map +1 -1
  220. package/dist/model/panels.d.ts +17 -5
  221. package/dist/model/panels.d.ts.map +1 -1
  222. package/dist/model/panels.js.map +1 -1
  223. package/dist/model/plugin-base.d.ts +0 -1
  224. package/dist/model/plugin-base.d.ts.map +1 -1
  225. package/dist/model/plugin-base.js.map +1 -1
  226. package/dist/model/plugin-loading.js.map +1 -1
  227. package/dist/model/plugins.d.ts +35 -21
  228. package/dist/model/plugins.d.ts.map +1 -1
  229. package/dist/model/plugins.js.map +1 -1
  230. package/dist/model/time-series-queries.d.ts +4 -3
  231. package/dist/model/time-series-queries.d.ts.map +1 -1
  232. package/dist/model/time-series-queries.js.map +1 -1
  233. package/dist/model/trace-queries.d.ts +1 -1
  234. package/dist/model/trace-queries.d.ts.map +1 -1
  235. package/dist/model/trace-queries.js.map +1 -1
  236. package/dist/model/variables.d.ts +2 -2
  237. package/dist/model/variables.d.ts.map +1 -1
  238. package/dist/model/variables.js +3 -1
  239. package/dist/model/variables.js.map +1 -1
  240. package/dist/remote/PersesPlugin.types.d.ts +7 -0
  241. package/dist/remote/PersesPlugin.types.d.ts.map +1 -0
  242. package/dist/remote/PersesPlugin.types.js +15 -0
  243. package/dist/remote/PersesPlugin.types.js.map +1 -0
  244. package/dist/remote/PluginLoaderComponent.d.ts +10 -0
  245. package/dist/remote/PluginLoaderComponent.d.ts.map +1 -0
  246. package/dist/remote/PluginLoaderComponent.js +67 -0
  247. package/dist/remote/PluginLoaderComponent.js.map +1 -0
  248. package/dist/remote/PluginRuntime.d.ts +11 -0
  249. package/dist/remote/PluginRuntime.d.ts.map +1 -0
  250. package/dist/remote/PluginRuntime.js +202 -0
  251. package/dist/remote/PluginRuntime.js.map +1 -0
  252. package/dist/remote/index.d.ts +3 -0
  253. package/dist/remote/index.d.ts.map +1 -0
  254. package/dist/{validation → remote}/index.js +2 -4
  255. package/dist/remote/index.js.map +1 -0
  256. package/dist/remote/remotePluginLoader.d.ts +3 -0
  257. package/dist/remote/remotePluginLoader.d.ts.map +1 -0
  258. package/dist/remote/remotePluginLoader.js +53 -0
  259. package/dist/remote/remotePluginLoader.js.map +1 -0
  260. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.d.ts +2 -2
  261. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.d.ts.map +1 -1
  262. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js +19 -10
  263. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js.map +1 -1
  264. package/dist/runtime/DataQueriesProvider/model.d.ts +6 -7
  265. package/dist/runtime/DataQueriesProvider/model.d.ts.map +1 -1
  266. package/dist/runtime/DataQueriesProvider/model.js +10 -9
  267. package/dist/runtime/DataQueriesProvider/model.js.map +1 -1
  268. package/dist/runtime/QueryCountProvider.d.ts +9 -0
  269. package/dist/runtime/QueryCountProvider.d.ts.map +1 -0
  270. package/dist/{validation/datasource.js → runtime/QueryCountProvider.js} +14 -10
  271. package/dist/runtime/QueryCountProvider.js.map +1 -0
  272. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.d.ts +6 -2
  273. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.d.ts.map +1 -1
  274. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js +30 -9
  275. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js.map +1 -1
  276. package/dist/runtime/TimeRangeProvider/TimeRangeProviderWithQueryParams.d.ts +2 -2
  277. package/dist/runtime/TimeRangeProvider/TimeRangeProviderWithQueryParams.d.ts.map +1 -1
  278. package/dist/runtime/TimeRangeProvider/TimeRangeProviderWithQueryParams.js +3 -3
  279. package/dist/runtime/TimeRangeProvider/TimeRangeProviderWithQueryParams.js.map +1 -1
  280. package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.d.ts +32 -0
  281. package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.d.ts.map +1 -0
  282. package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.js +82 -0
  283. package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.js.map +1 -0
  284. package/dist/runtime/TimeRangeProvider/index.d.ts +1 -0
  285. package/dist/runtime/TimeRangeProvider/index.d.ts.map +1 -1
  286. package/dist/runtime/TimeRangeProvider/index.js +2 -1
  287. package/dist/runtime/TimeRangeProvider/index.js.map +1 -1
  288. package/dist/runtime/TimeRangeProvider/query-params.d.ts +1 -1
  289. package/dist/runtime/TimeRangeProvider/query-params.d.ts.map +1 -1
  290. package/dist/runtime/TimeRangeProvider/query-params.js +8 -11
  291. package/dist/runtime/TimeRangeProvider/query-params.js.map +1 -1
  292. package/dist/runtime/TimeRangeProvider/refresh-interval.d.ts.map +1 -1
  293. package/dist/runtime/TimeRangeProvider/refresh-interval.js.map +1 -1
  294. package/dist/runtime/UsageMetricsProvider.d.ts +25 -0
  295. package/dist/runtime/UsageMetricsProvider.d.ts.map +1 -0
  296. package/dist/runtime/UsageMetricsProvider.js +77 -0
  297. package/dist/runtime/UsageMetricsProvider.js.map +1 -0
  298. package/dist/runtime/builtin-variables.d.ts +2 -2
  299. package/dist/runtime/builtin-variables.d.ts.map +1 -1
  300. package/dist/runtime/builtin-variables.js +4 -4
  301. package/dist/runtime/builtin-variables.js.map +1 -1
  302. package/dist/runtime/datasources.d.ts +5 -4
  303. package/dist/runtime/datasources.d.ts.map +1 -1
  304. package/dist/runtime/datasources.js +24 -15
  305. package/dist/runtime/datasources.js.map +1 -1
  306. package/dist/runtime/index.d.ts +3 -1
  307. package/dist/runtime/index.d.ts.map +1 -1
  308. package/dist/runtime/index.js +4 -2
  309. package/dist/runtime/index.js.map +1 -1
  310. package/dist/runtime/plugin-registry.d.ts +11 -11
  311. package/dist/runtime/plugin-registry.d.ts.map +1 -1
  312. package/dist/runtime/plugin-registry.js +40 -28
  313. package/dist/runtime/plugin-registry.js.map +1 -1
  314. package/dist/runtime/time-series-queries.d.ts +5 -4
  315. package/dist/runtime/time-series-queries.d.ts.map +1 -1
  316. package/dist/runtime/time-series-queries.js +28 -33
  317. package/dist/runtime/time-series-queries.js.map +1 -1
  318. package/dist/runtime/trace-queries.d.ts +5 -4
  319. package/dist/runtime/trace-queries.d.ts.map +1 -1
  320. package/dist/runtime/trace-queries.js +10 -7
  321. package/dist/runtime/trace-queries.js.map +1 -1
  322. package/dist/runtime/{template-variables.d.ts → variables.d.ts} +7 -7
  323. package/dist/runtime/variables.d.ts.map +1 -0
  324. package/dist/runtime/{template-variables.js → variables.js} +35 -44
  325. package/dist/runtime/variables.js.map +1 -0
  326. package/dist/stories/shared-utils/decorators/WithDataQueries.d.ts +3 -3
  327. package/dist/stories/shared-utils/decorators/WithDataQueries.d.ts.map +1 -1
  328. package/dist/stories/shared-utils/decorators/WithDataQueries.js +1 -1
  329. package/dist/stories/shared-utils/decorators/WithDataQueries.js.map +1 -1
  330. package/dist/stories/shared-utils/decorators/WithPluginRegistry.d.ts +2 -2
  331. package/dist/stories/shared-utils/decorators/WithPluginRegistry.d.ts.map +1 -1
  332. package/dist/stories/shared-utils/decorators/WithPluginRegistry.js +2 -22
  333. package/dist/stories/shared-utils/decorators/WithPluginRegistry.js.map +1 -1
  334. package/dist/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.d.ts +3 -3
  335. package/dist/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.d.ts.map +1 -1
  336. package/dist/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.js +1 -1
  337. package/dist/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.js.map +1 -1
  338. package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.d.ts +3 -3
  339. package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.d.ts.map +1 -1
  340. package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.js +5 -5
  341. package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.js.map +1 -1
  342. package/dist/stories/shared-utils/decorators/WithPluginSystemVariables.d.ts +13 -0
  343. package/dist/stories/shared-utils/decorators/WithPluginSystemVariables.d.ts.map +1 -0
  344. package/dist/stories/shared-utils/decorators/{WithPluginSystemTemplateVariables.js → WithPluginSystemVariables.js} +10 -10
  345. package/dist/stories/shared-utils/decorators/WithPluginSystemVariables.js.map +1 -0
  346. package/dist/stories/shared-utils/decorators/WithTimeRange.d.ts +3 -3
  347. package/dist/stories/shared-utils/decorators/WithTimeRange.d.ts.map +1 -1
  348. package/dist/stories/shared-utils/decorators/WithTimeRange.js +1 -1
  349. package/dist/stories/shared-utils/decorators/WithTimeRange.js.map +1 -1
  350. package/dist/stories/shared-utils/decorators/index.d.ts +1 -1
  351. package/dist/stories/shared-utils/decorators/index.d.ts.map +1 -1
  352. package/dist/stories/shared-utils/decorators/index.js +2 -2
  353. package/dist/stories/shared-utils/decorators/index.js.map +1 -1
  354. package/dist/test/mock-data.d.ts.map +1 -1
  355. package/dist/test/mock-data.js +25 -4
  356. package/dist/test/mock-data.js.map +1 -1
  357. package/dist/test/render.d.ts +4 -4
  358. package/dist/test/render.d.ts.map +1 -1
  359. package/dist/test/render.js +2 -11
  360. package/dist/test/render.js.map +1 -1
  361. package/dist/test/setup-tests.js.map +1 -1
  362. package/dist/test/test-plugins/bert/index.d.ts.map +1 -1
  363. package/dist/test/test-plugins/bert/index.js +21 -20
  364. package/dist/test/test-plugins/bert/index.js.map +1 -1
  365. package/dist/test/test-plugins/ernie/index.js +2 -2
  366. package/dist/test/test-plugins/ernie/index.js.map +1 -1
  367. package/dist/test-utils/mock-plugin-registry.d.ts +6 -4
  368. package/dist/test-utils/mock-plugin-registry.d.ts.map +1 -1
  369. package/dist/test-utils/mock-plugin-registry.js +10 -10
  370. package/dist/test-utils/mock-plugin-registry.js.map +1 -1
  371. package/dist/utils/variables.d.ts +4 -4
  372. package/dist/utils/variables.d.ts.map +1 -1
  373. package/dist/utils/variables.js +19 -19
  374. package/dist/utils/variables.js.map +1 -1
  375. package/package.json +7 -6
  376. package/dist/cjs/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.js +0 -146
  377. package/dist/cjs/components/TraceQueryEditor/TraceQueryInput.js +0 -96
  378. package/dist/cjs/validation/datasource.js +0 -30
  379. package/dist/cjs/validation/role.js +0 -85
  380. package/dist/cjs/validation/rolebinding.js +0 -55
  381. package/dist/cjs/validation/secret.js +0 -176
  382. package/dist/cjs/validation/variable.js +0 -48
  383. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.d.ts +0 -8
  384. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.d.ts.map +0 -1
  385. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.js.map +0 -1
  386. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryInput.d.ts +0 -13
  387. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryInput.d.ts.map +0 -1
  388. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryInput.js.map +0 -1
  389. package/dist/components/TimeSeriesQueryEditor/index.d.ts +0 -2
  390. package/dist/components/TimeSeriesQueryEditor/index.d.ts.map +0 -1
  391. package/dist/components/TimeSeriesQueryEditor/index.js.map +0 -1
  392. package/dist/components/TraceQueryEditor/TraceQueryEditor.d.ts +0 -9
  393. package/dist/components/TraceQueryEditor/TraceQueryEditor.d.ts.map +0 -1
  394. package/dist/components/TraceQueryEditor/TraceQueryEditor.js +0 -130
  395. package/dist/components/TraceQueryEditor/TraceQueryEditor.js.map +0 -1
  396. package/dist/components/TraceQueryEditor/TraceQueryInput.d.ts +0 -13
  397. package/dist/components/TraceQueryEditor/TraceQueryInput.d.ts.map +0 -1
  398. package/dist/components/TraceQueryEditor/TraceQueryInput.js +0 -83
  399. package/dist/components/TraceQueryEditor/TraceQueryInput.js.map +0 -1
  400. package/dist/components/TraceQueryEditor/index.d.ts +0 -2
  401. package/dist/components/TraceQueryEditor/index.d.ts.map +0 -1
  402. package/dist/runtime/template-variables.d.ts.map +0 -1
  403. package/dist/runtime/template-variables.js.map +0 -1
  404. package/dist/stories/shared-utils/decorators/WithPluginSystemTemplateVariables.d.ts +0 -13
  405. package/dist/stories/shared-utils/decorators/WithPluginSystemTemplateVariables.d.ts.map +0 -1
  406. package/dist/stories/shared-utils/decorators/WithPluginSystemTemplateVariables.js.map +0 -1
  407. package/dist/validation/datasource.d.ts +0 -19
  408. package/dist/validation/datasource.d.ts.map +0 -1
  409. package/dist/validation/datasource.js.map +0 -1
  410. package/dist/validation/index.d.ts +0 -5
  411. package/dist/validation/index.d.ts.map +0 -1
  412. package/dist/validation/index.js.map +0 -1
  413. package/dist/validation/resource.d.ts +0 -3
  414. package/dist/validation/resource.d.ts.map +0 -1
  415. package/dist/validation/resource.js.map +0 -1
  416. package/dist/validation/role.d.ts +0 -228
  417. package/dist/validation/role.d.ts.map +0 -1
  418. package/dist/validation/role.js +0 -66
  419. package/dist/validation/role.js.map +0 -1
  420. package/dist/validation/rolebinding.d.ts +0 -137
  421. package/dist/validation/rolebinding.d.ts.map +0 -1
  422. package/dist/validation/rolebinding.js +0 -47
  423. package/dist/validation/rolebinding.js.map +0 -1
  424. package/dist/validation/secret.d.ts +0 -964
  425. package/dist/validation/secret.d.ts.map +0 -1
  426. package/dist/validation/secret.js +0 -157
  427. package/dist/validation/secret.js.map +0 -1
  428. package/dist/validation/variable.d.ts +0 -96
  429. package/dist/validation/variable.d.ts.map +0 -1
  430. package/dist/validation/variable.js +0 -40
  431. package/dist/validation/variable.js.map +0 -1
@@ -23,29 +23,38 @@ export function useDatasourceStore() {
23
23
  /**
24
24
  * Lists all available Datasource selection items for a given datasource plugin kind.
25
25
  * Returns a list, with all information that can be used in a datasource selection context (group, name, selector, kind, ...)
26
- */ export function useListDatasourceSelectItems(datasourcePluginKind, project) {
27
- const { listDatasourceSelectItems } = useDatasourceStore();
28
- return useQuery([
29
- 'listDatasourceSelectItems',
30
- datasourcePluginKind,
31
- project
32
- ], ()=>listDatasourceSelectItems(datasourcePluginKind));
26
+ */ export function useListDatasourceSelectItems(datasourcePluginName, project) {
27
+ const { listDatasourceSelectItems } = useDatasourceStore();
28
+ return useQuery({
29
+ queryKey: [
30
+ 'listDatasourceSelectItems',
31
+ datasourcePluginName,
32
+ project
33
+ ],
34
+ queryFn: ()=>listDatasourceSelectItems(datasourcePluginName)
35
+ });
33
36
  }
34
37
  /**
35
38
  * Provides a convenience hook for getting a DatasourceClient for a given DatasourceSelector.
36
39
  */ export function useDatasourceClient(selector) {
37
40
  const store = useDatasourceStore();
38
- return useQuery([
39
- 'getDatasourceClient',
40
- selector
41
- ], ()=>store.getDatasourceClient(selector));
41
+ return useQuery({
42
+ queryKey: [
43
+ 'getDatasourceClient',
44
+ selector
45
+ ],
46
+ queryFn: ()=>store.getDatasourceClient(selector)
47
+ });
42
48
  }
43
49
  export function useDatasource(selector) {
44
50
  const store = useDatasourceStore();
45
- return useQuery([
46
- 'getDatasource',
47
- selector
48
- ], ()=>store.getDatasource(selector));
51
+ return useQuery({
52
+ queryKey: [
53
+ 'getDatasource',
54
+ selector
55
+ ],
56
+ queryFn: ()=>store.getDatasource(selector)
57
+ });
49
58
  }
50
59
 
51
60
  //# sourceMappingURL=datasources.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/runtime/datasources.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DatasourceSelector, DatasourceSpec } from '@perses-dev/core';\nimport { useQuery } from '@tanstack/react-query';\nimport { createContext, useContext } from 'react';\n\nexport interface DatasourceStore {\n // TODO: Do we even need this method?\n getDatasource(selector: DatasourceSelector): Promise<DatasourceSpec>;\n\n /**\n * Given a DatasourceSelector, gets a `Client` object from the corresponding Datasource plugin.\n */\n getDatasourceClient<Client>(selector: DatasourceSelector): Promise<Client>;\n\n /**\n * Gets a list of datasource selection items for a plugin kind.\n */\n listDatasourceSelectItems(datasourcePluginKind: string): Promise<DatasourceSelectItemGroup[]>;\n\n /**\n * Gets the list of datasources defined in the dashboard\n */\n getLocalDatasources(): Record<string, DatasourceSpec>;\n\n /**\n * Sets the list of datasources defined in the dashboard\n */\n setLocalDatasources(datasources: Record<string, DatasourceSpec>): void;\n\n /**\n * Gets the list of datasources that are available in the dashboard (i.e. dashboards that have been created on the server side that we can use).\n */\n getSavedDatasources(): Record<string, DatasourceSpec>;\n\n /**\n * Sets the list of datasources that are saved in the dashboard\n */\n setSavedDatasources(datasources: Record<string, DatasourceSpec>): void;\n}\n\nexport interface DatasourceSelectItemGroup {\n group?: string;\n editLink?: string;\n items: DatasourceSelectItem[];\n}\n\nexport interface DatasourceSelectItem {\n name: string;\n overridden?: boolean;\n overriding?: boolean;\n saved?: boolean;\n selector: DatasourceSelectItemSelector;\n}\n\n/**\n * Datasource Selector used by the frontend only to differentiate datasources coming from different group.\n */\nexport interface DatasourceSelectItemSelector extends DatasourceSelector {\n /**\n * Group of the datasource.\n * Omit it if you don't store datasource by group.\n */\n group?: string;\n}\n\nexport const DatasourceStoreContext = createContext<DatasourceStore | undefined>(undefined);\n\nexport function useDatasourceStore() {\n const ctx = useContext(DatasourceStoreContext);\n if (ctx === undefined) {\n throw new Error('No DatasourceStoreContext found. Did you forget a Provider?');\n }\n return ctx;\n}\n\n/**\n * Lists all available Datasource selection items for a given datasource plugin kind.\n * Returns a list, with all information that can be used in a datasource selection context (group, name, selector, kind, ...)\n */\nexport function useListDatasourceSelectItems(datasourcePluginKind: string, project?: string) {\n const { listDatasourceSelectItems } = useDatasourceStore();\n return useQuery(['listDatasourceSelectItems', datasourcePluginKind, project], () =>\n listDatasourceSelectItems(datasourcePluginKind)\n );\n}\n\n/**\n * Provides a convenience hook for getting a DatasourceClient for a given DatasourceSelector.\n */\nexport function useDatasourceClient<Client>(selector: DatasourceSelector) {\n const store = useDatasourceStore();\n return useQuery<Client>(['getDatasourceClient', selector], () => store.getDatasourceClient<Client>(selector));\n}\n\nexport function useDatasource(selector: DatasourceSelector) {\n const store = useDatasourceStore();\n return useQuery(['getDatasource', selector], () => store.getDatasource(selector));\n}\n"],"names":["useQuery","createContext","useContext","DatasourceStoreContext","undefined","useDatasourceStore","ctx","Error","useListDatasourceSelectItems","datasourcePluginKind","project","listDatasourceSelectItems","useDatasourceClient","selector","store","getDatasourceClient","useDatasource","getDatasource"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAASA,QAAQ,QAAQ,wBAAwB;AACjD,SAASC,aAAa,EAAEC,UAAU,QAAQ,QAAQ;AA8DlD,OAAO,MAAMC,yBAAyBF,cAA2CG,WAAW;AAE5F,OAAO,SAASC;IACd,MAAMC,MAAMJ,WAAWC;IACvB,IAAIG,QAAQF,WAAW;QACrB,MAAM,IAAIG,MAAM;IAClB;IACA,OAAOD;AACT;AAEA;;;CAGC,GACD,OAAO,SAASE,6BAA6BC,oBAA4B,EAAEC,OAAgB;IACzF,MAAM,EAAEC,0BAAyB,EAAE,GAAGN;IACtC,OAAOL,SAAS;QAAC;QAA6BS;QAAsBC;KAAQ,EAAE,IAC5EC,0BAA0BF;AAE9B;AAEA;;CAEC,GACD,OAAO,SAASG,oBAA4BC,QAA4B;IACtE,MAAMC,QAAQT;IACd,OAAOL,SAAiB;QAAC;QAAuBa;KAAS,EAAE,IAAMC,MAAMC,oBAA4BF;AACrG;AAEA,OAAO,SAASG,cAAcH,QAA4B;IACxD,MAAMC,QAAQT;IACd,OAAOL,SAAS;QAAC;QAAiBa;KAAS,EAAE,IAAMC,MAAMG,cAAcJ;AACzE"}
1
+ {"version":3,"sources":["../../src/runtime/datasources.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DatasourceSelector, DatasourceSpec } from '@perses-dev/core';\nimport { useQuery, UseQueryResult } from '@tanstack/react-query';\nimport { createContext, useContext } from 'react';\n\nexport interface DatasourceStore {\n // TODO: Do we even need this method?\n getDatasource(selector: DatasourceSelector): Promise<DatasourceSpec>;\n\n /**\n * Given a DatasourceSelector, gets a `Client` object from the corresponding Datasource plugin.\n */\n getDatasourceClient<Client>(selector: DatasourceSelector): Promise<Client>;\n\n /**\n * Gets a list of datasource selection items for a plugin kind.\n */\n listDatasourceSelectItems(datasourcePluginName: string): Promise<DatasourceSelectItemGroup[]>;\n\n /**\n * Gets the list of datasources defined in the dashboard\n */\n getLocalDatasources(): Record<string, DatasourceSpec>;\n\n /**\n * Sets the list of datasources defined in the dashboard\n */\n setLocalDatasources(datasources: Record<string, DatasourceSpec>): void;\n\n /**\n * Gets the list of datasources that are available in the dashboard (i.e. dashboards that have been created on the server side that we can use).\n */\n getSavedDatasources(): Record<string, DatasourceSpec>;\n\n /**\n * Sets the list of datasources that are saved in the dashboard\n */\n setSavedDatasources(datasources: Record<string, DatasourceSpec>): void;\n}\n\nexport interface DatasourceSelectItemGroup {\n group?: string;\n editLink?: string;\n items: DatasourceSelectItem[];\n}\n\nexport interface DatasourceSelectItem {\n name: string;\n overridden?: boolean;\n overriding?: boolean;\n saved?: boolean;\n selector: DatasourceSelectItemSelector;\n}\n\n/**\n * Datasource Selector used by the frontend only to differentiate datasources coming from different group.\n */\nexport interface DatasourceSelectItemSelector extends DatasourceSelector {\n /**\n * Group of the datasource.\n * Omit it if you don't store datasource by group.\n */\n group?: string;\n}\n\nexport const DatasourceStoreContext = createContext<DatasourceStore | undefined>(undefined);\n\nexport function useDatasourceStore(): DatasourceStore {\n const ctx = useContext(DatasourceStoreContext);\n if (ctx === undefined) {\n throw new Error('No DatasourceStoreContext found. Did you forget a Provider?');\n }\n return ctx;\n}\n\n/**\n * Lists all available Datasource selection items for a given datasource plugin kind.\n * Returns a list, with all information that can be used in a datasource selection context (group, name, selector, kind, ...)\n */\nexport function useListDatasourceSelectItems(\n datasourcePluginName: string,\n project?: string\n): UseQueryResult<DatasourceSelectItemGroup[]> {\n const { listDatasourceSelectItems } = useDatasourceStore();\n return useQuery<DatasourceSelectItemGroup[]>({\n queryKey: ['listDatasourceSelectItems', datasourcePluginName, project],\n queryFn: () => listDatasourceSelectItems(datasourcePluginName),\n });\n}\n\n/**\n * Provides a convenience hook for getting a DatasourceClient for a given DatasourceSelector.\n */\nexport function useDatasourceClient<Client>(selector: DatasourceSelector): UseQueryResult<Client> {\n const store = useDatasourceStore();\n return useQuery<Client>({\n queryKey: ['getDatasourceClient', selector],\n queryFn: () => store.getDatasourceClient<Client>(selector),\n });\n}\n\nexport function useDatasource(selector: DatasourceSelector): UseQueryResult<DatasourceSpec> {\n const store = useDatasourceStore();\n return useQuery<DatasourceSpec>({\n queryKey: ['getDatasource', selector],\n queryFn: () => store.getDatasource(selector),\n });\n}\n"],"names":["useQuery","createContext","useContext","DatasourceStoreContext","undefined","useDatasourceStore","ctx","Error","useListDatasourceSelectItems","datasourcePluginName","project","listDatasourceSelectItems","queryKey","queryFn","useDatasourceClient","selector","store","getDatasourceClient","useDatasource","getDatasource"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAASA,QAAQ,QAAwB,wBAAwB;AACjE,SAASC,aAAa,EAAEC,UAAU,QAAQ,QAAQ;AA8DlD,OAAO,MAAMC,yBAAyBF,cAA2CG,WAAW;AAE5F,OAAO,SAASC;IACd,MAAMC,MAAMJ,WAAWC;IACvB,IAAIG,QAAQF,WAAW;QACrB,MAAM,IAAIG,MAAM;IAClB;IACA,OAAOD;AACT;AAEA;;;CAGC,GACD,OAAO,SAASE,6BACdC,oBAA4B,EAC5BC,OAAgB;IAEhB,MAAM,EAAEC,yBAAyB,EAAE,GAAGN;IACtC,OAAOL,SAAsC;QAC3CY,UAAU;YAAC;YAA6BH;YAAsBC;SAAQ;QACtEG,SAAS,IAAMF,0BAA0BF;IAC3C;AACF;AAEA;;CAEC,GACD,OAAO,SAASK,oBAA4BC,QAA4B;IACtE,MAAMC,QAAQX;IACd,OAAOL,SAAiB;QACtBY,UAAU;YAAC;YAAuBG;SAAS;QAC3CF,SAAS,IAAMG,MAAMC,mBAAmB,CAASF;IACnD;AACF;AAEA,OAAO,SAASG,cAAcH,QAA4B;IACxD,MAAMC,QAAQX;IACd,OAAOL,SAAyB;QAC9BY,UAAU;YAAC;YAAiBG;SAAS;QACrCF,SAAS,IAAMG,MAAMG,aAAa,CAACJ;IACrC;AACF"}
@@ -1,9 +1,11 @@
1
1
  export * from './builtin-variables';
2
2
  export * from './datasources';
3
3
  export * from './plugin-registry';
4
- export * from './template-variables';
4
+ export * from './variables';
5
5
  export * from './TimeRangeProvider';
6
6
  export * from './time-series-queries';
7
7
  export * from './trace-queries';
8
8
  export * from './DataQueriesProvider';
9
+ export * from './QueryCountProvider';
10
+ export * from './UsageMetricsProvider';
9
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAaA,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAaA,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC"}
@@ -1,4 +1,4 @@
1
- // Copyright 2023 The Perses Authors
1
+ // Copyright 2024 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -13,10 +13,12 @@
13
13
  export * from './builtin-variables';
14
14
  export * from './datasources';
15
15
  export * from './plugin-registry';
16
- export * from './template-variables';
16
+ export * from './variables';
17
17
  export * from './TimeRangeProvider';
18
18
  export * from './time-series-queries';
19
19
  export * from './trace-queries';
20
20
  export * from './DataQueriesProvider';
21
+ export * from './QueryCountProvider';
22
+ export * from './UsageMetricsProvider';
21
23
 
22
24
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/runtime/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './builtin-variables';\nexport * from './datasources';\nexport * from './plugin-registry';\nexport * from './template-variables';\nexport * from './TimeRangeProvider';\nexport * from './time-series-queries';\nexport * from './trace-queries';\nexport * from './DataQueriesProvider';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,sBAAsB;AACpC,cAAc,gBAAgB;AAC9B,cAAc,oBAAoB;AAClC,cAAc,uBAAuB;AACrC,cAAc,sBAAsB;AACpC,cAAc,wBAAwB;AACtC,cAAc,kBAAkB;AAChC,cAAc,wBAAwB"}
1
+ {"version":3,"sources":["../../src/runtime/index.ts"],"sourcesContent":["// Copyright 2024 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './builtin-variables';\nexport * from './datasources';\nexport * from './plugin-registry';\nexport * from './variables';\nexport * from './TimeRangeProvider';\nexport * from './time-series-queries';\nexport * from './trace-queries';\nexport * from './DataQueriesProvider';\nexport * from './QueryCountProvider';\nexport * from './UsageMetricsProvider';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,sBAAsB;AACpC,cAAc,gBAAgB;AAC9B,cAAc,oBAAoB;AAClC,cAAc,cAAc;AAC5B,cAAc,sBAAsB;AACpC,cAAc,wBAAwB;AACtC,cAAc,kBAAkB;AAChC,cAAc,wBAAwB;AACtC,cAAc,uBAAuB;AACrC,cAAc,yBAAyB"}
@@ -1,11 +1,11 @@
1
1
  /// <reference types="react" />
2
- import { UseQueryOptions } from '@tanstack/react-query';
3
2
  import { BuiltinVariableDefinition } from '@perses-dev/core';
4
- import { DefaultPluginKinds, PluginImplementation, PluginMetadata, PluginType } from '../model';
3
+ import { UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
4
+ import { DefaultPluginKinds, PluginImplementation, PluginMetadataWithModule, PluginType } from '../model';
5
5
  export interface PluginRegistryContextType {
6
- getPlugin<T extends PluginType>(pluginType: T, kind: string): Promise<PluginImplementation<T>>;
7
- listPluginMetadata(pluginType: PluginType): Promise<PluginMetadata[]>;
8
- defaultPluginKinds: DefaultPluginKinds;
6
+ getPlugin<T extends PluginType>(kind: T, name: string): Promise<PluginImplementation<T>>;
7
+ listPluginMetadata(pluginTypes: string[]): Promise<PluginMetadataWithModule[]>;
8
+ defaultPluginKinds?: DefaultPluginKinds;
9
9
  }
10
10
  export declare const PluginRegistryContext: import("react").Context<PluginRegistryContextType | undefined>;
11
11
  /**
@@ -13,22 +13,22 @@ export declare const PluginRegistryContext: import("react").Context<PluginRegist
13
13
  * be using `usePlugin` or `useListPluginMetadata` instead.
14
14
  */
15
15
  export declare function usePluginRegistry(): PluginRegistryContextType;
16
- declare type UsePluginOptions<T extends PluginType> = Omit<UseQueryOptions<PluginImplementation<T>, Error, PluginImplementation<T>, [string, PluginType, string]>, 'queryKey' | 'queryFn'>;
16
+ type UsePluginOptions<T extends PluginType> = Omit<UseQueryOptions<PluginImplementation<T>, Error, PluginImplementation<T>, [string, PluginType | undefined, string]>, 'queryKey' | 'queryFn'>;
17
17
  /**
18
18
  * Loads a plugin and returns the plugin implementation, along with loading/error state.
19
19
  */
20
- export declare function usePlugin<T extends PluginType>(pluginType: T, kind: string, options?: UsePluginOptions<T>): import("@tanstack/react-query").UseQueryResult<PluginImplementation<T>, Error>;
20
+ export declare function usePlugin<T extends PluginType>(pluginType: T | undefined, kind: string, options?: UsePluginOptions<T>): UseQueryResult<PluginImplementation<T>, Error>;
21
21
  /**
22
22
  * Loads a list of plugins and returns the plugin implementation, along with loading/error state.
23
23
  */
24
24
  export declare function usePlugins<T extends PluginType>(pluginType: T, plugins: Array<{
25
25
  kind: string;
26
- }>): import("@tanstack/react-query").UseQueryResult<PluginImplementation<T>, unknown>[];
27
- declare type UseListPluginMetadataOptions = Omit<UseQueryOptions<PluginMetadata[], Error, PluginMetadata[], [string, PluginType]>, 'queryKey' | 'queryFn'>;
26
+ }>): Array<UseQueryResult<PluginImplementation<T>>>;
27
+ type UseListPluginMetadataOptions = Omit<UseQueryOptions<PluginMetadataWithModule[], Error, PluginMetadataWithModule[], [string, string[]]>, 'queryKey' | 'queryFn'>;
28
28
  /**
29
29
  * Gets a list of plugin metadata for the specified plugin type and returns it, along with loading/error state.
30
30
  */
31
- export declare function useListPluginMetadata(pluginType: PluginType, options?: UseListPluginMetadataOptions): import("@tanstack/react-query").UseQueryResult<PluginMetadata[], Error>;
32
- export declare function usePluginBuiltinVariableDefinitions(): import("@tanstack/react-query").UseQueryResult<BuiltinVariableDefinition[], unknown>;
31
+ export declare function useListPluginMetadata(pluginTypes: string[], options?: UseListPluginMetadataOptions): UseQueryResult<PluginMetadataWithModule[]>;
32
+ export declare function usePluginBuiltinVariableDefinitions(): UseQueryResult<BuiltinVariableDefinition[]>;
33
33
  export {};
34
34
  //# sourceMappingURL=plugin-registry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugin-registry.d.ts","sourceRoot":"","sources":["../../src/runtime/plugin-registry.ts"],"names":[],"mappings":";AAcA,OAAO,EAAwB,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC9E,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEhG,MAAM,WAAW,yBAAyB;IACxC,SAAS,CAAC,CAAC,SAAS,UAAU,EAAE,UAAU,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/F,kBAAkB,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;IACtE,kBAAkB,EAAE,kBAAkB,CAAC;CACxC;AAED,eAAO,MAAM,qBAAqB,gEAAkE,CAAC;AAErG;;;GAGG;AAC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,SAAS,CACvB,CAAC;AAEF;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,MAAM,EAAE,EACrB,OAAO,CAAC,EAAE,4BAA4B,GACrC,cAAc,CAAC,wBAAwB,EAAE,CAAC,CAO5C;AAED,wBAAgB,mCAAmC,IAAI,cAAc,CAAC,yBAAyB,EAAE,CAAC,CAkBjG"}
@@ -10,8 +10,8 @@
10
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
+ import { useQueries, useQuery } from '@tanstack/react-query';
13
14
  import { createContext, useContext } from 'react';
14
- import { useQuery, useQueries } from '@tanstack/react-query';
15
15
  export const PluginRegistryContext = createContext(undefined);
16
16
  /**
17
17
  * Use the PluginRegistry context directly. This is meant as an escape hatch for custom async flows. You should probably
@@ -26,23 +26,26 @@ export const PluginRegistryContext = createContext(undefined);
26
26
  /**
27
27
  * Loads a plugin and returns the plugin implementation, along with loading/error state.
28
28
  */ export function usePlugin(pluginType, kind, options) {
29
- var _options_enabled;
30
29
  // We never want to ask for a plugin when the kind isn't set yet, so disable those queries automatically
31
30
  options = {
32
31
  ...options,
33
- enabled: ((_options_enabled = options === null || options === void 0 ? void 0 : options.enabled) !== null && _options_enabled !== void 0 ? _options_enabled : true) && kind !== ''
32
+ enabled: (options?.enabled ?? true) && pluginType !== undefined && kind !== ''
34
33
  };
35
- const { getPlugin } = usePluginRegistry();
36
- return useQuery([
37
- 'getPlugin',
38
- pluginType,
39
- kind
40
- ], ()=>getPlugin(pluginType, kind), options);
34
+ const { getPlugin } = usePluginRegistry();
35
+ return useQuery({
36
+ queryKey: [
37
+ 'getPlugin',
38
+ pluginType,
39
+ kind
40
+ ],
41
+ queryFn: ()=>getPlugin(pluginType, kind),
42
+ ...options
43
+ });
41
44
  }
42
45
  /**
43
46
  * Loads a list of plugins and returns the plugin implementation, along with loading/error state.
44
47
  */ export function usePlugins(pluginType, plugins) {
45
- const { getPlugin } = usePluginRegistry();
48
+ const { getPlugin } = usePluginRegistry();
46
49
  return useQueries({
47
50
  queries: plugins.map((p)=>{
48
51
  return {
@@ -58,28 +61,37 @@ export const PluginRegistryContext = createContext(undefined);
58
61
  }
59
62
  /**
60
63
  * Gets a list of plugin metadata for the specified plugin type and returns it, along with loading/error state.
61
- */ export function useListPluginMetadata(pluginType, options) {
62
- const { listPluginMetadata } = usePluginRegistry();
63
- return useQuery([
64
- 'listPluginMetadata',
65
- pluginType
66
- ], ()=>listPluginMetadata(pluginType), options);
64
+ */ export function useListPluginMetadata(pluginTypes, options) {
65
+ const { listPluginMetadata } = usePluginRegistry();
66
+ return useQuery({
67
+ queryKey: [
68
+ 'listPluginMetadata',
69
+ pluginTypes
70
+ ],
71
+ queryFn: ()=>listPluginMetadata(pluginTypes),
72
+ ...options
73
+ });
67
74
  }
68
75
  export function usePluginBuiltinVariableDefinitions() {
69
- const { getPlugin , listPluginMetadata } = usePluginRegistry();
70
- return useQuery([
71
- 'usePluginBuiltinVariableDefinitions'
72
- ], async ()=>{
73
- const datasources = await listPluginMetadata('Datasource');
74
- const datasourceKinds = new Set(datasources.map((datasource)=>datasource.kind));
75
- const result = [];
76
- for (const kind of datasourceKinds){
77
- const plugin = await getPlugin('Datasource', kind);
78
- if (plugin.getBuiltinVariableDefinitions) {
79
- plugin.getBuiltinVariableDefinitions().forEach((definition)=>result.push(definition));
76
+ const { getPlugin, listPluginMetadata } = usePluginRegistry();
77
+ return useQuery({
78
+ queryKey: [
79
+ 'usePluginBuiltinVariableDefinitions'
80
+ ],
81
+ queryFn: async ()=>{
82
+ const datasources = await listPluginMetadata([
83
+ 'Datasource'
84
+ ]);
85
+ const datasourceNames = new Set(datasources.map((datasource)=>datasource.spec.name));
86
+ const result = [];
87
+ for (const name of datasourceNames){
88
+ const plugin = await getPlugin('Datasource', name);
89
+ if (plugin.getBuiltinVariableDefinitions) {
90
+ plugin.getBuiltinVariableDefinitions().forEach((definition)=>result.push(definition));
91
+ }
80
92
  }
93
+ return result;
81
94
  }
82
- return result;
83
95
  });
84
96
  }
85
97
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/runtime/plugin-registry.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { createContext, useContext } from 'react';\nimport { useQuery, useQueries, UseQueryOptions } from '@tanstack/react-query';\nimport { BuiltinVariableDefinition } from '@perses-dev/core';\nimport { DefaultPluginKinds, PluginImplementation, PluginMetadata, PluginType } from '../model';\n\nexport interface PluginRegistryContextType {\n getPlugin<T extends PluginType>(pluginType: T, kind: string): Promise<PluginImplementation<T>>;\n listPluginMetadata(pluginType: PluginType): Promise<PluginMetadata[]>;\n defaultPluginKinds: DefaultPluginKinds;\n}\n\nexport const PluginRegistryContext = createContext<PluginRegistryContextType | undefined>(undefined);\n\n/**\n * Use the PluginRegistry context directly. This is meant as an escape hatch for custom async flows. You should probably\n * be using `usePlugin` or `useListPluginMetadata` instead.\n */\nexport function usePluginRegistry() {\n const ctx = useContext(PluginRegistryContext);\n if (ctx === undefined) {\n throw new Error('PluginRegistryContext not found. Did you forget a provider?');\n }\n return ctx;\n}\n\n// Allows consumers to pass useQuery options from react-query when loading a plugin\ntype UsePluginOptions<T extends PluginType> = Omit<\n UseQueryOptions<PluginImplementation<T>, Error, PluginImplementation<T>, [string, PluginType, string]>,\n 'queryKey' | 'queryFn'\n>;\n\n/**\n * Loads a plugin and returns the plugin implementation, along with loading/error state.\n */\nexport function usePlugin<T extends PluginType>(pluginType: T, kind: string, options?: UsePluginOptions<T>) {\n // We never want to ask for a plugin when the kind isn't set yet, so disable those queries automatically\n options = {\n ...options,\n enabled: (options?.enabled ?? true) && kind !== '',\n };\n const { getPlugin } = usePluginRegistry();\n return useQuery(['getPlugin', pluginType, kind], () => getPlugin(pluginType, kind), options);\n}\n\n/**\n * Loads a list of plugins and returns the plugin implementation, along with loading/error state.\n */\nexport function usePlugins<T extends PluginType>(pluginType: T, plugins: Array<{ kind: string }>) {\n const { getPlugin } = usePluginRegistry();\n return useQueries({\n queries: plugins.map((p) => {\n return {\n queryKey: ['getPlugin', pluginType, p.kind],\n queryFn: () => getPlugin(pluginType, p.kind),\n };\n }),\n });\n}\n\n// Allow consumers to pass useQuery options from react-query when listing metadata\ntype UseListPluginMetadataOptions = Omit<\n UseQueryOptions<PluginMetadata[], Error, PluginMetadata[], [string, PluginType]>,\n 'queryKey' | 'queryFn'\n>;\n\n/**\n * Gets a list of plugin metadata for the specified plugin type and returns it, along with loading/error state.\n */\nexport function useListPluginMetadata(pluginType: PluginType, options?: UseListPluginMetadataOptions) {\n const { listPluginMetadata } = usePluginRegistry();\n return useQuery(['listPluginMetadata', pluginType], () => listPluginMetadata(pluginType), options);\n}\n\nexport function usePluginBuiltinVariableDefinitions() {\n const { getPlugin, listPluginMetadata } = usePluginRegistry();\n\n return useQuery(['usePluginBuiltinVariableDefinitions'], async () => {\n const datasources = await listPluginMetadata('Datasource');\n const datasourceKinds = new Set(datasources.map((datasource) => datasource.kind));\n const result: BuiltinVariableDefinition[] = [];\n for (const kind of datasourceKinds) {\n const plugin = await getPlugin('Datasource', kind);\n if (plugin.getBuiltinVariableDefinitions) {\n plugin.getBuiltinVariableDefinitions().forEach((definition) => result.push(definition));\n }\n }\n return result;\n });\n}\n"],"names":["createContext","useContext","useQuery","useQueries","PluginRegistryContext","undefined","usePluginRegistry","ctx","Error","usePlugin","pluginType","kind","options","enabled","getPlugin","usePlugins","plugins","queries","map","p","queryKey","queryFn","useListPluginMetadata","listPluginMetadata","usePluginBuiltinVariableDefinitions","datasources","datasourceKinds","Set","datasource","result","plugin","getBuiltinVariableDefinitions","forEach","definition","push"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,aAAa,EAAEC,UAAU,QAAQ,QAAQ;AAClD,SAASC,QAAQ,EAAEC,UAAU,QAAyB,wBAAwB;AAU9E,OAAO,MAAMC,wBAAwBJ,cAAqDK,WAAW;AAErG;;;CAGC,GACD,OAAO,SAASC;IACd,MAAMC,MAAMN,WAAWG;IACvB,IAAIG,QAAQF,WAAW;QACrB,MAAM,IAAIG,MAAM;IAClB;IACA,OAAOD;AACT;AAQA;;CAEC,GACD,OAAO,SAASE,UAAgCC,UAAa,EAAEC,IAAY,EAAEC,OAA6B;QAI5FA;IAHZ,wGAAwG;IACxGA,UAAU;QACR,GAAGA,OAAO;QACVC,SAAS,AAACD,CAAAA,CAAAA,mBAAAA,oBAAAA,qBAAAA,KAAAA,IAAAA,QAASC,qBAATD,8BAAAA,mBAAoB,IAAG,KAAMD,SAAS;IAClD;IACA,MAAM,EAAEG,UAAS,EAAE,GAAGR;IACtB,OAAOJ,SAAS;QAAC;QAAaQ;QAAYC;KAAK,EAAE,IAAMG,UAAUJ,YAAYC,OAAOC;AACtF;AAEA;;CAEC,GACD,OAAO,SAASG,WAAiCL,UAAa,EAAEM,OAAgC;IAC9F,MAAM,EAAEF,UAAS,EAAE,GAAGR;IACtB,OAAOH,WAAW;QAChBc,SAASD,QAAQE,IAAI,CAACC;YACpB,OAAO;gBACLC,UAAU;oBAAC;oBAAaV;oBAAYS,EAAER;iBAAK;gBAC3CU,SAAS,IAAMP,UAAUJ,YAAYS,EAAER;YACzC;QACF;IACF;AACF;AAQA;;CAEC,GACD,OAAO,SAASW,sBAAsBZ,UAAsB,EAAEE,OAAsC;IAClG,MAAM,EAAEW,mBAAkB,EAAE,GAAGjB;IAC/B,OAAOJ,SAAS;QAAC;QAAsBQ;KAAW,EAAE,IAAMa,mBAAmBb,aAAaE;AAC5F;AAEA,OAAO,SAASY;IACd,MAAM,EAAEV,UAAS,EAAES,mBAAkB,EAAE,GAAGjB;IAE1C,OAAOJ,SAAS;QAAC;KAAsC,EAAE;QACvD,MAAMuB,cAAc,MAAMF,mBAAmB;QAC7C,MAAMG,kBAAkB,IAAIC,IAAIF,YAAYP,IAAI,CAACU,aAAeA,WAAWjB;QAC3E,MAAMkB,SAAsC,EAAE;QAC9C,KAAK,MAAMlB,QAAQe,gBAAiB;YAClC,MAAMI,SAAS,MAAMhB,UAAU,cAAcH;YAC7C,IAAImB,OAAOC,+BAA+B;gBACxCD,OAAOC,gCAAgCC,QAAQ,CAACC,aAAeJ,OAAOK,KAAKD;YAC7E;QACF;QACA,OAAOJ;IACT;AACF"}
1
+ {"version":3,"sources":["../../src/runtime/plugin-registry.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { BuiltinVariableDefinition } from '@perses-dev/core';\nimport { useQueries, useQuery, UseQueryOptions, UseQueryResult } from '@tanstack/react-query';\nimport { createContext, useContext } from 'react';\nimport { DefaultPluginKinds, PluginImplementation, PluginMetadataWithModule, PluginType } from '../model';\n\nexport interface PluginRegistryContextType {\n getPlugin<T extends PluginType>(kind: T, name: string): Promise<PluginImplementation<T>>;\n listPluginMetadata(pluginTypes: string[]): Promise<PluginMetadataWithModule[]>;\n defaultPluginKinds?: DefaultPluginKinds;\n}\n\nexport const PluginRegistryContext = createContext<PluginRegistryContextType | undefined>(undefined);\n\n/**\n * Use the PluginRegistry context directly. This is meant as an escape hatch for custom async flows. You should probably\n * be using `usePlugin` or `useListPluginMetadata` instead.\n */\nexport function usePluginRegistry(): PluginRegistryContextType {\n const ctx = useContext(PluginRegistryContext);\n if (ctx === undefined) {\n throw new Error('PluginRegistryContext not found. Did you forget a provider?');\n }\n return ctx;\n}\n\n// Allows consumers to pass useQuery options from react-query when loading a plugin\ntype UsePluginOptions<T extends PluginType> = Omit<\n UseQueryOptions<PluginImplementation<T>, Error, PluginImplementation<T>, [string, PluginType | undefined, string]>,\n 'queryKey' | 'queryFn'\n>;\n\n/**\n * Loads a plugin and returns the plugin implementation, along with loading/error state.\n */\nexport function usePlugin<T extends PluginType>(\n pluginType: T | undefined,\n kind: string,\n options?: UsePluginOptions<T>\n): UseQueryResult<PluginImplementation<T>, Error> {\n // We never want to ask for a plugin when the kind isn't set yet, so disable those queries automatically\n options = {\n ...options,\n enabled: (options?.enabled ?? true) && pluginType !== undefined && kind !== '',\n };\n const { getPlugin } = usePluginRegistry();\n return useQuery({\n queryKey: ['getPlugin', pluginType, kind],\n queryFn: () => getPlugin(pluginType!, kind),\n ...options,\n });\n}\n\n/**\n * Loads a list of plugins and returns the plugin implementation, along with loading/error state.\n */\nexport function usePlugins<T extends PluginType>(\n pluginType: T,\n plugins: Array<{ kind: string }>\n): Array<UseQueryResult<PluginImplementation<T>>> {\n const { getPlugin } = usePluginRegistry();\n return useQueries({\n queries: plugins.map((p) => {\n return {\n queryKey: ['getPlugin', pluginType, p.kind],\n queryFn: () => getPlugin(pluginType, p.kind),\n };\n }),\n });\n}\n\n// Allow consumers to pass useQuery options from react-query when listing metadata\ntype UseListPluginMetadataOptions = Omit<\n UseQueryOptions<PluginMetadataWithModule[], Error, PluginMetadataWithModule[], [string, string[]]>,\n 'queryKey' | 'queryFn'\n>;\n\n/**\n * Gets a list of plugin metadata for the specified plugin type and returns it, along with loading/error state.\n */\nexport function useListPluginMetadata(\n pluginTypes: string[],\n options?: UseListPluginMetadataOptions\n): UseQueryResult<PluginMetadataWithModule[]> {\n const { listPluginMetadata } = usePluginRegistry();\n return useQuery({\n queryKey: ['listPluginMetadata', pluginTypes],\n queryFn: () => listPluginMetadata(pluginTypes),\n ...options,\n });\n}\n\nexport function usePluginBuiltinVariableDefinitions(): UseQueryResult<BuiltinVariableDefinition[]> {\n const { getPlugin, listPluginMetadata } = usePluginRegistry();\n\n return useQuery({\n queryKey: ['usePluginBuiltinVariableDefinitions'],\n queryFn: async () => {\n const datasources = await listPluginMetadata(['Datasource']);\n const datasourceNames = new Set(datasources.map((datasource) => datasource.spec.name));\n const result: BuiltinVariableDefinition[] = [];\n for (const name of datasourceNames) {\n const plugin = await getPlugin('Datasource', name);\n if (plugin.getBuiltinVariableDefinitions) {\n plugin.getBuiltinVariableDefinitions().forEach((definition) => result.push(definition));\n }\n }\n return result;\n },\n });\n}\n"],"names":["useQueries","useQuery","createContext","useContext","PluginRegistryContext","undefined","usePluginRegistry","ctx","Error","usePlugin","pluginType","kind","options","enabled","getPlugin","queryKey","queryFn","usePlugins","plugins","queries","map","p","useListPluginMetadata","pluginTypes","listPluginMetadata","usePluginBuiltinVariableDefinitions","datasources","datasourceNames","Set","datasource","spec","name","result","plugin","getBuiltinVariableDefinitions","forEach","definition","push"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAASA,UAAU,EAAEC,QAAQ,QAAyC,wBAAwB;AAC9F,SAASC,aAAa,EAAEC,UAAU,QAAQ,QAAQ;AASlD,OAAO,MAAMC,wBAAwBF,cAAqDG,WAAW;AAErG;;;CAGC,GACD,OAAO,SAASC;IACd,MAAMC,MAAMJ,WAAWC;IACvB,IAAIG,QAAQF,WAAW;QACrB,MAAM,I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QJ,gBAAiB;gBAClC,MAAMM,SAAS,MAAMnB,UAAU,cAAciB;gBAC7C,IAAIE,OAAOC,6BAA6B,EAAE;oBACxCD,OAAOC,6BAA6B,GAAGC,OAAO,CAAC,CAACC,aAAeJ,OAAOK,IAAI,CAACD;gBAC7E;YACF;YACA,OAAOJ;QACT;IACF;AACF"}
@@ -1,18 +1,19 @@
1
- import { QueryCache, QueryObserverOptions } from '@tanstack/react-query';
1
+ import { QueryCache, QueryObserverOptions, UseQueryResult } from '@tanstack/react-query';
2
2
  import { TimeSeriesQueryDefinition, TimeSeriesData } from '@perses-dev/core';
3
- import { TimeSeriesDataQuery } from '../model';
3
+ import { TimeSeriesDataQuery, TimeSeriesQueryMode } from '../model';
4
4
  export interface UseTimeSeriesQueryOptions {
5
5
  suggestedStepMs?: number;
6
+ mode?: TimeSeriesQueryMode;
6
7
  }
7
8
  export declare const TIME_SERIES_QUERY_KEY = "TimeSeriesQuery";
8
9
  /**
9
10
  * Runs a time series query using a plugin and returns the results.
10
11
  */
11
- export declare const useTimeSeriesQuery: (definition: TimeSeriesQueryDefinition, options?: UseTimeSeriesQueryOptions, queryOptions?: QueryObserverOptions) => import("@tanstack/react-query").UseQueryResult<TimeSeriesData, unknown>;
12
+ export declare const useTimeSeriesQuery: (definition: TimeSeriesQueryDefinition, options?: UseTimeSeriesQueryOptions, queryOptions?: QueryObserverOptions<TimeSeriesData>) => UseQueryResult<TimeSeriesData>;
12
13
  /**
13
14
  * Runs multiple time series queries using plugins and returns the results.
14
15
  */
15
- export declare function useTimeSeriesQueries(definitions: TimeSeriesQueryDefinition[], options?: UseTimeSeriesQueryOptions, queryOptions?: QueryObserverOptions): import("@tanstack/react-query").UseQueryResult<TimeSeriesData, unknown>[];
16
+ export declare function useTimeSeriesQueries(definitions: TimeSeriesQueryDefinition[], options?: UseTimeSeriesQueryOptions, queryOptions?: Omit<QueryObserverOptions, 'queryKey'>): Array<UseQueryResult<TimeSeriesData>>;
16
17
  /**
17
18
  * Get active time series queries for query results summary
18
19
  */
@@ -1 +1 @@
1
- {"version":3,"file":"time-series-queries.d.ts","sourceRoot":"","sources":["../../src/runtime/time-series-queries.ts"],"names":[],"mappings":"AAaA,OAAO,EAKL,UAAU,EAEV,oBAAoB,EACrB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,yBAAyB,EAAe,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC1F,OAAO,EAAE,mBAAmB,EAAiD,MAAM,UAAU,CAAC;AAM9F,MAAM,WAAW,yBAAyB;IACxC,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,eAAO,MAAM,qBAAqB,oBAAoB,CAAC;AAmDvD;;GAEG;AACH,eAAO,MAAM,kBAAkB,eACjB,yBAAyB,YAC3B,yBAAyB,iBACpB,oBAAoB,4EAoBpC,CAAC;AAEF;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,yBAAyB,EAAE,EACxC,OAAO,CAAC,EAAE,yBAAyB,EACnC,YAAY,CAAC,EAAE,oBAAoB,6EA4BpC;AAmBD;;GAEG;AACH,wBAAgB,0BAA0B,0BAIzC;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,UAAU,yBAW3D"}
1
+ {"version":3,"file":"time-series-queries.d.ts","sourceRoot":"","sources":["../../src/runtime/time-series-queries.ts"],"names":[],"mappings":"AAaA,OAAO,EAKL,UAAU,EAEV,oBAAoB,EACpB,cAAc,EACf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,yBAAyB,EAAe,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC1F,OAAO,EAAE,mBAAmB,EAA0B,mBAAmB,EAAyB,MAAM,UAAU,CAAC;AAMnH,MAAM,WAAW,yBAAyB;IACxC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,IAAI,CAAC,EAAE,mBAAmB,CAAC;CAC5B;AAED,eAAO,MAAM,qBAAqB,oBAAoB,CAAC;AA8DvD;;GAEG;AACH,eAAO,MAAM,kBAAkB,eACjB,yBAAyB,YAC3B,yBAAyB,iBACpB,qBAAqB,cAAc,CAAC,KAClD,eAAe,cAAc,CAkB/B,CAAC;AAEF;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,yBAAyB,EAAE,EACxC,OAAO,CAAC,EAAE,yBAAyB,EACnC,YAAY,CAAC,EAAE,IAAI,CAAC,oBAAoB,EAAE,UAAU,CAAC,GACpD,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC,CAiCvC;AAkBD;;GAEG;AACH,wBAAgB,0BAA0B,IAAI,mBAAmB,EAAE,CAIlE;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,UAAU,GAAG,mBAAmB,EAAE,CAWnF"}
@@ -1,4 +1,4 @@
1
- // Copyright 2023 The Perses Authors
1
+ // Copyright 2024 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -11,7 +11,7 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
  import { useQuery, useQueries, useQueryClient } from '@tanstack/react-query';
14
- import { useVariableValues } from './template-variables';
14
+ import { useAllVariableValues } from './variables';
15
15
  import { useTimeRange } from './TimeRangeProvider';
16
16
  import { useDatasourceStore } from './datasources';
17
17
  import { usePlugin, usePluginRegistry, usePlugins } from './plugin-registry';
@@ -27,10 +27,10 @@ function filterVariableStateMap(v, names) {
27
27
  }
28
28
  return Object.fromEntries(Object.entries(v).filter(([name])=>names.includes(name)));
29
29
  }
30
- function getQueryOptions({ plugin , definition , context }) {
31
- const { timeRange , datasourceStore , suggestedStepMs , variableState , refreshKey } = context;
32
- const dependencies = (plugin === null || plugin === void 0 ? void 0 : plugin.dependsOn) ? plugin.dependsOn(definition.spec.plugin.spec, context) : {};
33
- const variableDependencies = dependencies === null || dependencies === void 0 ? void 0 : dependencies.variables;
30
+ function getQueryOptions({ plugin, definition, context }) {
31
+ const { timeRange, datasourceStore, suggestedStepMs, mode, variableState, refreshKey } = context;
32
+ const dependencies = plugin?.dependsOn ? plugin.dependsOn(definition.spec.plugin.spec, context) : {};
33
+ const variableDependencies = dependencies?.variables;
34
34
  // Determine queryKey
35
35
  const filteredVariabledState = filterVariableStateMap(variableState, variableDependencies);
36
36
  const variablesValueKey = getVariableValuesKey(filteredVariabledState);
@@ -39,16 +39,14 @@ function getQueryOptions({ plugin , definition , context }) {
39
39
  timeRange,
40
40
  datasourceStore,
41
41
  suggestedStepMs,
42
+ mode,
42
43
  variablesValueKey,
43
44
  refreshKey
44
45
  ];
45
46
  // Determine queryEnabled
46
47
  let waitToLoad = false;
47
48
  if (variableDependencies) {
48
- waitToLoad = variableDependencies.some((v)=>{
49
- var _variableState_v;
50
- return (_variableState_v = variableState[v]) === null || _variableState_v === void 0 ? void 0 : _variableState_v.loading;
51
- });
49
+ waitToLoad = variableDependencies.some((v)=>variableState[v]?.loading);
52
50
  }
53
51
  const queryEnabled = plugin !== undefined && !waitToLoad;
54
52
  return {
@@ -59,18 +57,16 @@ function getQueryOptions({ plugin , definition , context }) {
59
57
  /**
60
58
  * Runs a time series query using a plugin and returns the results.
61
59
  */ export const useTimeSeriesQuery = (definition, options, queryOptions)=>{
62
- const { data: plugin } = usePlugin(TIME_SERIES_QUERY_KEY, definition.spec.plugin.kind);
60
+ const { data: plugin } = usePlugin(TIME_SERIES_QUERY_KEY, definition.spec.plugin.kind);
63
61
  const context = useTimeSeriesQueryContext();
64
- const { queryEnabled , queryKey } = getQueryOptions({
62
+ const { queryEnabled, queryKey } = getQueryOptions({
65
63
  plugin,
66
64
  definition,
67
65
  context
68
66
  });
69
- var _queryOptions_enabled;
70
67
  return useQuery({
71
- enabled: ((_queryOptions_enabled = queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.enabled) !== null && _queryOptions_enabled !== void 0 ? _queryOptions_enabled : true) || queryEnabled,
68
+ enabled: (queryOptions?.enabled ?? true) || queryEnabled,
72
69
  queryKey: queryKey,
73
- refetchInterval: context.refreshIntervalInMs > 0 ? context.refreshIntervalInMs : false,
74
70
  queryFn: ()=>{
75
71
  // The 'enabled' option should prevent this from happening, but make TypeScript happy by checking
76
72
  if (plugin === undefined) {
@@ -79,7 +75,7 @@ function getQueryOptions({ plugin , definition , context }) {
79
75
  // Keep options out of query key so we don't re-run queries because suggested step changes
80
76
  const ctx = {
81
77
  ...context,
82
- suggestedStepMs: options === null || options === void 0 ? void 0 : options.suggestedStepMs
78
+ suggestedStepMs: options?.suggestedStepMs
83
79
  };
84
80
  return plugin.getTimeSeriesData(definition.spec.plugin.spec, ctx);
85
81
  }
@@ -88,30 +84,31 @@ function getQueryOptions({ plugin , definition , context }) {
88
84
  /**
89
85
  * Runs multiple time series queries using plugins and returns the results.
90
86
  */ export function useTimeSeriesQueries(definitions, options, queryOptions) {
91
- const { getPlugin } = usePluginRegistry();
92
- const context = useTimeSeriesQueryContext();
87
+ const { getPlugin } = usePluginRegistry();
88
+ const context = {
89
+ ...useTimeSeriesQueryContext(),
90
+ // We need mode to be part query key because this drives the type of query done (instant VS range query)
91
+ mode: options?.mode
92
+ };
93
93
  const pluginLoaderResponse = usePlugins(TIME_SERIES_QUERY_KEY, definitions.map((d)=>({
94
94
  kind: d.spec.plugin.kind
95
95
  })));
96
96
  return useQueries({
97
97
  queries: definitions.map((definition, idx)=>{
98
- var _pluginLoaderResponse_idx;
99
- const plugin = (_pluginLoaderResponse_idx = pluginLoaderResponse[idx]) === null || _pluginLoaderResponse_idx === void 0 ? void 0 : _pluginLoaderResponse_idx.data;
100
- const { queryEnabled , queryKey } = getQueryOptions({
98
+ const plugin = pluginLoaderResponse[idx]?.data;
99
+ const { queryEnabled, queryKey } = getQueryOptions({
101
100
  plugin,
102
101
  definition,
103
102
  context
104
103
  });
105
- var _queryOptions_enabled;
106
104
  return {
107
- enabled: ((_queryOptions_enabled = queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.enabled) !== null && _queryOptions_enabled !== void 0 ? _queryOptions_enabled : true) && queryEnabled,
105
+ enabled: (queryOptions?.enabled ?? true) && queryEnabled,
108
106
  queryKey: queryKey,
109
- refetchInterval: context.refreshIntervalInMs > 0 ? context.refreshIntervalInMs : undefined,
110
107
  queryFn: async ()=>{
111
- // Keep options out of query key so we don't re-run queries because suggested step changes
112
108
  const ctx = {
113
109
  ...context,
114
- suggestedStepMs: options === null || options === void 0 ? void 0 : options.suggestedStepMs
110
+ // Keep suggested step changes out of the query key, so we don´t have to run again query when it changes
111
+ suggestedStepMs: options?.suggestedStepMs
115
112
  };
116
113
  const plugin = await getPlugin(TIME_SERIES_QUERY_KEY, definition.spec.plugin.kind);
117
114
  const data = await plugin.getTimeSeriesData(definition.spec.plugin.spec, ctx);
@@ -124,15 +121,14 @@ function getQueryOptions({ plugin , definition , context }) {
124
121
  /**
125
122
  * Build the time series query context object from data available at runtime
126
123
  */ function useTimeSeriesQueryContext() {
127
- const { absoluteTimeRange , refreshKey , refreshIntervalInMs } = useTimeRange();
128
- const variableState = useVariableValues();
124
+ const { absoluteTimeRange, refreshKey } = useTimeRange();
125
+ const variableState = useAllVariableValues();
129
126
  const datasourceStore = useDatasourceStore();
130
127
  return {
131
128
  timeRange: absoluteTimeRange,
132
129
  variableState,
133
130
  datasourceStore,
134
- refreshKey,
135
- refreshIntervalInMs: refreshIntervalInMs
131
+ refreshKey
136
132
  };
137
133
  }
138
134
  /**
@@ -149,9 +145,8 @@ function getQueryOptions({ plugin , definition , context }) {
149
145
  for (const query of cache.findAll({
150
146
  type: 'active'
151
147
  })){
152
- var _query_queryKey;
153
- const firstPart = (_query_queryKey = query.queryKey) === null || _query_queryKey === void 0 ? void 0 : _query_queryKey[0];
154
- if ((firstPart === null || firstPart === void 0 ? void 0 : firstPart.kind) && firstPart.kind.startsWith(TIME_SERIES_QUERY_KEY)) {
148
+ const firstPart = query.queryKey?.[0];
149
+ if (firstPart?.kind && firstPart.kind.startsWith(TIME_SERIES_QUERY_KEY)) {
155
150
  queries.push(query);
156
151
  }
157
152
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/runtime/time-series-queries.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport {\n useQuery,\n useQueries,\n useQueryClient,\n Query,\n QueryCache,\n QueryKey,\n QueryObserverOptions,\n} from '@tanstack/react-query';\nimport { TimeSeriesQueryDefinition, UnknownSpec, TimeSeriesData } from '@perses-dev/core';\nimport { TimeSeriesDataQuery, TimeSeriesQueryContext, TimeSeriesQueryPlugin } from '../model';\nimport { VariableStateMap, useVariableValues } from './template-variables';\nimport { useTimeRange } from './TimeRangeProvider';\nimport { useDatasourceStore } from './datasources';\nimport { usePlugin, usePluginRegistry, usePlugins } from './plugin-registry';\n\nexport interface UseTimeSeriesQueryOptions {\n suggestedStepMs?: number;\n}\n\nexport const TIME_SERIES_QUERY_KEY = 'TimeSeriesQuery';\n\n/**\n * Returns a serialized string of the current state of variable values.\n */\nfunction getVariableValuesKey(v: VariableStateMap) {\n return Object.values(v)\n .map((v) => JSON.stringify(v.value))\n .join(',');\n}\n\nfunction filterVariableStateMap(v: VariableStateMap, names?: string[]) {\n if (!names) {\n return v;\n }\n return Object.fromEntries(Object.entries(v).filter(([name]) => names.includes(name)));\n}\n\nfunction getQueryOptions({\n plugin,\n definition,\n context,\n}: {\n plugin?: TimeSeriesQueryPlugin;\n definition: TimeSeriesQueryDefinition;\n context: TimeSeriesQueryContext;\n}) {\n const { timeRange, datasourceStore, suggestedStepMs, variableState, refreshKey } = context;\n\n const dependencies = plugin?.dependsOn ? plugin.dependsOn(definition.spec.plugin.spec, context) : {};\n const variableDependencies = dependencies?.variables;\n\n // Determine queryKey\n const filteredVariabledState = filterVariableStateMap(variableState, variableDependencies);\n const variablesValueKey = getVariableValuesKey(filteredVariabledState);\n const queryKey = [definition, timeRange, datasourceStore, suggestedStepMs, variablesValueKey, refreshKey] as const;\n\n // Determine queryEnabled\n let waitToLoad = false;\n if (variableDependencies) {\n waitToLoad = variableDependencies.some((v) => variableState[v]?.loading);\n }\n\n const queryEnabled = plugin !== undefined && !waitToLoad;\n\n return {\n queryKey,\n queryEnabled,\n };\n}\n\n/**\n * Runs a time series query using a plugin and returns the results.\n */\nexport const useTimeSeriesQuery = (\n definition: TimeSeriesQueryDefinition,\n options?: UseTimeSeriesQueryOptions,\n queryOptions?: QueryObserverOptions\n) => {\n const { data: plugin } = usePlugin(TIME_SERIES_QUERY_KEY, definition.spec.plugin.kind);\n const context = useTimeSeriesQueryContext();\n\n const { queryEnabled, queryKey } = getQueryOptions({ plugin, definition, context });\n return useQuery({\n enabled: (queryOptions?.enabled ?? true) || queryEnabled,\n queryKey: queryKey,\n refetchInterval: context.refreshIntervalInMs > 0 ? context.refreshIntervalInMs : false,\n queryFn: () => {\n // The 'enabled' option should prevent this from happening, but make TypeScript happy by checking\n if (plugin === undefined) {\n throw new Error('Expected plugin to be loaded');\n }\n // Keep options out of query key so we don't re-run queries because suggested step changes\n const ctx: TimeSeriesQueryContext = { ...context, suggestedStepMs: options?.suggestedStepMs };\n return plugin.getTimeSeriesData(definition.spec.plugin.spec, ctx);\n },\n });\n};\n\n/**\n * Runs multiple time series queries using plugins and returns the results.\n */\nexport function useTimeSeriesQueries(\n definitions: TimeSeriesQueryDefinition[],\n options?: UseTimeSeriesQueryOptions,\n queryOptions?: QueryObserverOptions\n) {\n const { getPlugin } = usePluginRegistry();\n const context = useTimeSeriesQueryContext();\n\n const pluginLoaderResponse = usePlugins(\n TIME_SERIES_QUERY_KEY,\n definitions.map((d) => ({ kind: d.spec.plugin.kind }))\n );\n\n return useQueries({\n queries: definitions.map((definition, idx) => {\n const plugin = pluginLoaderResponse[idx]?.data;\n const { queryEnabled, queryKey } = getQueryOptions({ plugin, definition, context });\n return {\n enabled: (queryOptions?.enabled ?? true) && queryEnabled,\n queryKey: queryKey,\n refetchInterval: context.refreshIntervalInMs > 0 ? context.refreshIntervalInMs : undefined,\n queryFn: async () => {\n // Keep options out of query key so we don't re-run queries because suggested step changes\n const ctx: TimeSeriesQueryContext = { ...context, suggestedStepMs: options?.suggestedStepMs };\n const plugin = await getPlugin(TIME_SERIES_QUERY_KEY, definition.spec.plugin.kind);\n const data = await plugin.getTimeSeriesData(definition.spec.plugin.spec, ctx);\n return data;\n },\n };\n }),\n });\n}\n\n/**\n * Build the time series query context object from data available at runtime\n */\nfunction useTimeSeriesQueryContext(): TimeSeriesQueryContext {\n const { absoluteTimeRange, refreshKey, refreshIntervalInMs } = useTimeRange();\n const variableState = useVariableValues();\n const datasourceStore = useDatasourceStore();\n\n return {\n timeRange: absoluteTimeRange,\n variableState,\n datasourceStore,\n refreshKey,\n refreshIntervalInMs: refreshIntervalInMs,\n };\n}\n\n/**\n * Get active time series queries for query results summary\n */\nexport function useActiveTimeSeriesQueries() {\n const queryClient = useQueryClient();\n const queryCache = queryClient.getQueryCache();\n return getActiveTimeSeriesQueries(queryCache);\n}\n\n/**\n * Filter all cached queries down to only active time series queries\n */\nexport function getActiveTimeSeriesQueries(cache: QueryCache) {\n const queries: TimeSeriesDataQuery[] = [];\n\n for (const query of cache.findAll({ type: 'active' })) {\n const firstPart = query.queryKey?.[0] as UnknownSpec;\n if (firstPart?.kind && (firstPart.kind as string).startsWith(TIME_SERIES_QUERY_KEY)) {\n queries.push(query as Query<TimeSeriesData, unknown, TimeSeriesData, QueryKey>);\n }\n }\n\n return queries;\n}\n"],"names":["useQuery","useQueries","useQueryClient","useVariableValues","useTimeRange","useDatasourceStore","usePlugin","usePluginRegistry","usePlugins","TIME_SERIES_QUERY_KEY","getVariableValuesKey","v","Object","values","map","JSON","stringify","value","join","filterVariableStateMap","names","fromEntries","entries","filter","name","includes","getQueryOptions","plugin","definition","context","timeRange","datasourceStore","suggestedStepMs","variableState","refreshKey","dependencies","dependsOn","spec","variableDependencies","variables","filteredVariabledState","variablesValueKey","queryKey","waitToLoad","some","loading","queryEnabled","undefined","useTimeSeriesQuery","options","queryOptions","data","kind","useTimeSeriesQueryContext","enabled","refetchInterval","refreshIntervalInMs","queryFn","Error","ctx","getTimeSeriesData","useTimeSeriesQueries","definitions","getPlugin","pluginLoaderResponse","d","queries","idx","absoluteTimeRange","useActiveTimeSeriesQueries","queryClient","queryCache","getQueryCache","getActiveTimeSeriesQueries","cache","query","findAll","type","firstPart","startsWith","push"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SACEA,QAAQ,EACRC,UAAU,EACVC,cAAc,QAKT,wBAAwB;AAG/B,SAA2BC,iBAAiB,QAAQ,uBAAuB;AAC3E,SAASC,YAAY,QAAQ,sBAAsB;AACnD,SAASC,kBAAkB,QAAQ,gBAAgB;AACnD,SAASC,SAAS,EAAEC,iBAAiB,EAAEC,UAAU,QAAQ,oBAAoB;AAM7E,OAAO,MAAMC,wBAAwB,kBAAkB;AAEvD;;CAEC,GACD,SAASC,qBAAqBC,CAAmB;IAC/C,OAAOC,OAAOC,OAAOF,GAClBG,IAAI,CAACH,IAAMI,KAAKC,UAAUL,EAAEM,QAC5BC,KAAK;AACV;AAEA,SAASC,uBAAuBR,CAAmB,EAAES,KAAgB;IACnE,IAAI,CAACA,OAAO;QACV,OAAOT;IACT;IACA,OAAOC,OAAOS,YAAYT,OAAOU,QAAQX,GAAGY,OAAO,CAAC,CAACC,KAAK,GAAKJ,MAAMK,SAASD;AAChF;AAEA,SAASE,gB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;oBAAgB;oBAC5F,MAAML,SAAS,MAAMoC,UAAUtD,uBAAuBmB,WAAWS,KAAKV,OAAOyB;oBAC7E,MAAMD,OAAO,MAAMxB,OAAOiC,kBAAkBhC,WAAWS,KAAKV,OAAOU,MAAMsB;oBACzE,OAAOR;gBACT;YACF;QACF;IACF;AACF;AAEA;;CAEC,GACD,SAASE;IACP,MAAM,EAAEe,kBAAiB,EAAElC,WAAU,EAAEsB,oBAAmB,EAAE,GAAGpD;IAC/D,MAAM6B,gBAAgB9B;IACtB,MAAM4B,kBAAkB1B;IAExB,OAAO;QACLyB,WAAWsC;QACXnC;QACAF;QACAG;QACAsB,qBAAqBA;IACvB;AACF;AAEA;;CAEC,GACD,OAAO,SAASa;IACd,MAAMC,cAAcpE;IACpB,MAAMqE,aAAaD,YAAYE;IAC/B,OAAOC,2BAA2BF;AACpC;AAEA;;CAEC,GACD,OAAO,SAASE,2BAA2BC,KAAiB;IAC1D,MAAMR,UAAiC,EAAE;IAEzC,KAAK,MAAMS,SAASD,MAAME,QAAQ;QAAEC,MAAM;IAAS,GAAI;YACnCF;QAAlB,MAAMG,YAAYH,CAAAA,kBAAAA,MAAMjC,sBAANiC,6BAAAA,KAAAA,IAAAA,eAAgB,CAAC,EAAE;QACrC,IAAIG,CAAAA,sBAAAA,uBAAAA,KAAAA,IAAAA,UAAW1B,IAAG,KAAK,AAAC0B,UAAU1B,KAAgB2B,WAAWtE,wBAAwB;YACnFyD,QAAQc,KAAKL;QACf;IACF;IAEA,OAAOT;AACT"}
1
+ {"version":3,"sources":["../../src/runtime/time-series-queries.ts"],"sourcesContent":["// Copyright 2024 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport {\n useQuery,\n useQueries,\n useQueryClient,\n Query,\n QueryCache,\n QueryKey,\n QueryObserverOptions,\n UseQueryResult,\n} from '@tanstack/react-query';\nimport { TimeSeriesQueryDefinition, UnknownSpec, TimeSeriesData } from '@perses-dev/core';\nimport { TimeSeriesDataQuery, TimeSeriesQueryContext, TimeSeriesQueryMode, TimeSeriesQueryPlugin } from '../model';\nimport { VariableStateMap, useAllVariableValues } from './variables';\nimport { useTimeRange } from './TimeRangeProvider';\nimport { useDatasourceStore } from './datasources';\nimport { usePlugin, usePluginRegistry, usePlugins } from './plugin-registry';\n\nexport interface UseTimeSeriesQueryOptions {\n suggestedStepMs?: number;\n mode?: TimeSeriesQueryMode;\n}\n\nexport const TIME_SERIES_QUERY_KEY = 'TimeSeriesQuery';\n\n/**\n * Returns a serialized string of the current state of variable values.\n */\nfunction getVariableValuesKey(v: VariableStateMap): string {\n return Object.values(v)\n .map((v) => JSON.stringify(v.value))\n .join(',');\n}\n\nfunction filterVariableStateMap(v: VariableStateMap, names?: string[]): VariableStateMap {\n if (!names) {\n return v;\n }\n return Object.fromEntries(Object.entries(v).filter(([name]) => names.includes(name)));\n}\n\nfunction getQueryOptions({\n plugin,\n definition,\n context,\n}: {\n plugin?: TimeSeriesQueryPlugin;\n definition: TimeSeriesQueryDefinition;\n context: TimeSeriesQueryContext;\n}): {\n queryKey: QueryKey;\n queryEnabled: boolean;\n} {\n const { timeRange, datasourceStore, suggestedStepMs, mode, variableState, refreshKey } = context;\n\n const dependencies = plugin?.dependsOn ? plugin.dependsOn(definition.spec.plugin.spec, context) : {};\n const variableDependencies = dependencies?.variables;\n\n // Determine queryKey\n const filteredVariabledState = filterVariableStateMap(variableState, variableDependencies);\n const variablesValueKey = getVariableValuesKey(filteredVariabledState);\n const queryKey = [\n definition,\n timeRange,\n datasourceStore,\n suggestedStepMs,\n mode,\n variablesValueKey,\n refreshKey,\n ] as const;\n\n // Determine queryEnabled\n let waitToLoad = false;\n if (variableDependencies) {\n waitToLoad = variableDependencies.some((v) => variableState[v]?.loading);\n }\n\n const queryEnabled = plugin !== undefined && !waitToLoad;\n\n return {\n queryKey,\n queryEnabled,\n };\n}\n\n/**\n * Runs a time series query using a plugin and returns the results.\n */\nexport const useTimeSeriesQuery = (\n definition: TimeSeriesQueryDefinition,\n options?: UseTimeSeriesQueryOptions,\n queryOptions?: QueryObserverOptions<TimeSeriesData>\n): UseQueryResult<TimeSeriesData> => {\n const { data: plugin } = usePlugin(TIME_SERIES_QUERY_KEY, definition.spec.plugin.kind);\n const context = useTimeSeriesQueryContext();\n\n const { queryEnabled, queryKey } = getQueryOptions({ plugin, definition, context });\n return useQuery({\n enabled: (queryOptions?.enabled ?? true) || queryEnabled,\n queryKey: queryKey,\n queryFn: () => {\n // The 'enabled' option should prevent this from happening, but make TypeScript happy by checking\n if (plugin === undefined) {\n throw new Error('Expected plugin to be loaded');\n }\n // Keep options out of query key so we don't re-run queries because suggested step changes\n const ctx: TimeSeriesQueryContext = { ...context, suggestedStepMs: options?.suggestedStepMs };\n return plugin.getTimeSeriesData(definition.spec.plugin.spec, ctx);\n },\n });\n};\n\n/**\n * Runs multiple time series queries using plugins and returns the results.\n */\nexport function useTimeSeriesQueries(\n definitions: TimeSeriesQueryDefinition[],\n options?: UseTimeSeriesQueryOptions,\n queryOptions?: Omit<QueryObserverOptions, 'queryKey'>\n): Array<UseQueryResult<TimeSeriesData>> {\n const { getPlugin } = usePluginRegistry();\n const context = {\n ...useTimeSeriesQueryContext(),\n // We need mode to be part query key because this drives the type of query done (instant VS range query)\n mode: options?.mode,\n };\n\n const pluginLoaderResponse = usePlugins(\n TIME_SERIES_QUERY_KEY,\n definitions.map((d) => ({ kind: d.spec.plugin.kind }))\n );\n\n return useQueries({\n queries: definitions.map((definition, idx) => {\n const plugin = pluginLoaderResponse[idx]?.data;\n const { queryEnabled, queryKey } = getQueryOptions({ plugin, definition, context });\n return {\n enabled: (queryOptions?.enabled ?? true) && queryEnabled,\n queryKey: queryKey,\n queryFn: async (): Promise<TimeSeriesData> => {\n const ctx: TimeSeriesQueryContext = {\n ...context,\n // Keep suggested step changes out of the query key, so we don´t have to run again query when it changes\n suggestedStepMs: options?.suggestedStepMs,\n };\n const plugin = await getPlugin(TIME_SERIES_QUERY_KEY, definition.spec.plugin.kind);\n const data = await plugin.getTimeSeriesData(definition.spec.plugin.spec, ctx);\n return data;\n },\n };\n }),\n });\n}\n\n/**\n * Build the time series query context object from data available at runtime\n */\nfunction useTimeSeriesQueryContext(): TimeSeriesQueryContext {\n const { absoluteTimeRange, refreshKey } = useTimeRange();\n const variableState = useAllVariableValues();\n const datasourceStore = useDatasourceStore();\n\n return {\n timeRange: absoluteTimeRange,\n variableState,\n datasourceStore,\n refreshKey,\n };\n}\n\n/**\n * Get active time series queries for query results summary\n */\nexport function useActiveTimeSeriesQueries(): TimeSeriesDataQuery[] {\n const queryClient = useQueryClient();\n const queryCache = queryClient.getQueryCache();\n return getActiveTimeSeriesQueries(queryCache);\n}\n\n/**\n * Filter all cached queries down to only active time series queries\n */\nexport function getActiveTimeSeriesQueries(cache: QueryCache): TimeSeriesDataQuery[] {\n const queries: TimeSeriesDataQuery[] = [];\n\n for (const query of cache.findAll({ type: 'active' })) {\n const firstPart = query.queryKey?.[0] as UnknownSpec;\n if (firstPart?.kind && (firstPart.kind as string).startsWith(TIME_SERIES_QUERY_KEY)) {\n queries.push(query as Query<TimeSeriesData, unknown, TimeSeriesData, QueryKey>);\n }\n }\n\n return queries;\n}\n"],"names":["useQuery","useQueries","useQueryClient","useAllVariableValues","useTimeRange","useDatasourceStore","usePlugin","usePluginRegistry","usePlugins","TIME_SERIES_QUERY_KEY","getVariableValuesKey","v","Object","values","map","JSON","stringify","value","join","filterVariableStateMap","names","fromEntries","entries","filter","name","includes","getQueryOptions","plugin","definition","context","timeRange","datasourceStore","suggestedStepMs","mode","variableState","refreshKey","dependencies","dependsOn","spec","variableDependencies","variables","filteredVariabledState","variablesValueKey","queryKey","waitToLoad","some","loading","queryEnabled","undefined","useTimeSeriesQuery","options","queryOptions","data","kind","useTimeSeriesQueryContext","enabled","queryFn","Error","ctx","getTimeSeriesData","useTimeSeriesQueries","definitions","getPlugin","pluginLoaderResponse","d","queries","idx","absoluteTimeRange","useActiveTimeSeriesQueries","queryClient","queryCache","getQueryCache","getActiveTimeSeriesQueries","cache","query","findAll","type","firstPart","startsWith","push"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SACEA,QAAQ,EACRC,UAAU,EACVC,cAAc,QAMT,wBAAwB;AAG/B,SAA2BC,oBAAoB,QAAQ,cAAc;AACrE,SAASC,YAAY,QAAQ,sBAAsB;AACnD,SAASC,kBAAkB,QAAQ,gBAAgB;AACnD,SAASC,SAAS,EAAEC,iBAAiB,EAAEC,UAAU,QAAQ,oBAAoB;AAO7E,OAAO,MAAMC,wBAAwB,kBAAkB;AAEvD;;CAEC,GACD,SAASC,qBAAqBC,CAAmB;IAC/C,OAAOC,OAAOC,MAAM,CAACF,GAClBG,GAAG,CAAC,CAACH,IAAMI,KAAKC,SAAS,CAACL,EAAEM,KAAK,GACjCC,IAAI,CAAC;AACV;AAEA,SAASC,uBAAuBR,CAAmB,EAAES,KAAgB;IACnE,IAAI,CAACA,OAAO;QACV,OAAOT;IACT;IACA,OAAOC,OAAOS,WAAW,CAACT,OAAOU,OAAO,CAACX,GAAGY,MAAM,CAAC,CAAC,CAACC,KAAK,GAAKJ,MAAMK,QAAQ,CAACD;AAChF;AAEA,SAASE,gBAAgB,EACvBC,MAAM,EACNC,UAAU,EACVC,OAAO,EAKR;IAIC,MAAM,EAAEC,SAAS,EAAEC,eAAe,EAAEC,eAAe,EAAEC,IAAI,EAAEC,aAAa,EAAEC,UAA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BF;AACpC;AAEA;;CAEC,GACD,OAAO,SAASE,2BAA2BC,KAAiB;IAC1D,MAAMR,UAAiC,EAAE;IAEzC,KAAK,MAAMS,SAASD,MAAME,OAAO,CAAC;QAAEC,MAAM;IAAS,GAAI;QACrD,MAAMC,YAAYH,MAAM/B,QAAQ,EAAE,CAAC,EAAE;QACrC,IAAIkC,WAAWxB,QAAQ,AAACwB,UAAUxB,IAAI,CAAYyB,UAAU,CAACrE,wBAAwB;YACnFwD,QAAQc,IAAI,CAACL;QACf;IACF;IAEA,OAAOT;AACT"}
@@ -1,5 +1,6 @@
1
- import { QueryDefinition, UnknownSpec, AbsoluteTimeRange } from '@perses-dev/core';
2
- export declare type TraceQueryDefinition<PluginSpec = UnknownSpec> = QueryDefinition<'TraceQuery', PluginSpec>;
1
+ import { QueryDefinition, UnknownSpec, AbsoluteTimeRange, TraceData } from '@perses-dev/core';
2
+ import { UseQueryResult } from '@tanstack/react-query';
3
+ export type TraceQueryDefinition<PluginSpec = UnknownSpec> = QueryDefinition<'TraceQuery', PluginSpec>;
3
4
  export declare const TRACE_QUERY_KEY = "TraceQuery";
4
5
  export declare function getUnixTimeRange(timeRange: AbsoluteTimeRange): {
5
6
  start: number;
@@ -7,8 +8,8 @@ export declare function getUnixTimeRange(timeRange: AbsoluteTimeRange): {
7
8
  };
8
9
  /**
9
10
  * Run a trace query using a TraceQuery plugin and return the results
10
- * @param definition: dashboard defintion for a trace query, written in Trace Query Language (TraceQL)
11
+ * @param definitions: dashboard defintion for a trace query, written in Trace Query Language (TraceQL)
11
12
  * Documentation for TraceQL: https://grafana.com/docs/tempo/latest/traceql/
12
13
  */
13
- export declare function useTraceQueries(definitions: TraceQueryDefinition[]): import("@tanstack/react-query").UseQueryResult<import("@perses-dev/core").TraceData, unknown>[];
14
+ export declare function useTraceQueries(definitions: TraceQueryDefinition[]): Array<UseQueryResult<TraceData>>;
14
15
  //# sourceMappingURL=trace-queries.d.ts.map