@perses-dev/plugin-system 0.54.0-beta.1 → 0.54.0-beta.10

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 (261) hide show
  1. package/dist/cjs/components/Annotations/AnnotationEditorForm/AnnotationEditorForm.js +283 -0
  2. package/dist/cjs/components/Annotations/AnnotationEditorForm/AnnotationPreview.js +197 -0
  3. package/dist/cjs/components/Annotations/AnnotationEditorForm/index.js +30 -0
  4. package/dist/cjs/components/Annotations/constants.js +23 -0
  5. package/dist/cjs/components/Annotations/index.js +31 -0
  6. package/dist/cjs/components/MultiQueryEditor/QueryEditorContainer.js +97 -12
  7. package/dist/cjs/components/MultiQueryEditor/index.js +1 -0
  8. package/dist/cjs/components/MultiQueryEditor/utils.js +36 -0
  9. package/dist/cjs/components/PanelSpecEditor/PanelSpecEditor.js +3 -6
  10. package/dist/cjs/components/PluginRegistry/PluginRegistry.js +11 -15
  11. package/dist/cjs/components/PluginRegistry/getPluginSearchHelper.js +92 -0
  12. package/dist/cjs/components/PluginRegistry/plugin-indexes.js +16 -13
  13. package/dist/cjs/components/Variables/variable-model.js +115 -29
  14. package/dist/cjs/components/index.js +1 -0
  15. package/dist/cjs/context/ValidationProvider.js +10 -4
  16. package/dist/cjs/model/alerts-queries.js +16 -0
  17. package/dist/cjs/model/annotations.js +16 -0
  18. package/dist/cjs/model/index.js +3 -0
  19. package/dist/cjs/model/log-volume-utils.js +10 -10
  20. package/dist/cjs/model/plugin-loading.js +24 -8
  21. package/dist/cjs/model/plugins.js +10 -0
  22. package/dist/cjs/model/silences-queries.js +16 -0
  23. package/dist/cjs/remote/PluginRuntime.js +46 -10
  24. package/dist/cjs/remote/remotePluginLoader.js +28 -5
  25. package/dist/cjs/runtime/DataQueriesProvider/DataQueriesProvider.js +33 -24
  26. package/dist/cjs/runtime/DataQueriesProvider/model.js +3 -93
  27. package/dist/cjs/runtime/UsageMetricsProvider.js +2 -2
  28. package/dist/cjs/runtime/alerts-queries.js +101 -0
  29. package/dist/cjs/runtime/annotations.js +148 -0
  30. package/dist/cjs/runtime/index.js +3 -1
  31. package/dist/cjs/runtime/item-actions.js +3 -3
  32. package/dist/cjs/runtime/log-queries.js +4 -1
  33. package/dist/cjs/runtime/plugin-registry.js +12 -3
  34. package/dist/cjs/runtime/profile-queries.js +4 -1
  35. package/dist/cjs/runtime/silences-queries.js +101 -0
  36. package/dist/cjs/runtime/time-series-queries.js +4 -1
  37. package/dist/cjs/runtime/trace-queries.js +4 -1
  38. package/dist/cjs/test/mock-data.js +51 -0
  39. package/dist/cjs/test/test-plugins/bert/index.js +9 -12
  40. package/dist/cjs/test/test-plugins/ernie/index.js +9 -12
  41. package/dist/cjs/test/test-plugins/index.js +2 -2
  42. package/dist/cjs/test-utils/mock-plugin-registry.js +8 -2
  43. package/dist/components/Annotations/AnnotationEditorForm/AnnotationEditorForm.d.ts +16 -0
  44. package/dist/components/Annotations/AnnotationEditorForm/AnnotationEditorForm.d.ts.map +1 -0
  45. package/dist/components/Annotations/AnnotationEditorForm/AnnotationEditorForm.js +270 -0
  46. package/dist/components/Annotations/AnnotationEditorForm/AnnotationEditorForm.js.map +1 -0
  47. package/dist/components/Annotations/AnnotationEditorForm/AnnotationPreview.d.ts +8 -0
  48. package/dist/components/Annotations/AnnotationEditorForm/AnnotationPreview.d.ts.map +1 -0
  49. package/dist/components/Annotations/AnnotationEditorForm/AnnotationPreview.js +184 -0
  50. package/dist/components/Annotations/AnnotationEditorForm/AnnotationPreview.js.map +1 -0
  51. package/dist/components/Annotations/AnnotationEditorForm/index.d.ts +2 -0
  52. package/dist/components/Annotations/AnnotationEditorForm/index.d.ts.map +1 -0
  53. package/dist/{runtime/QueryCountProvider.js → components/Annotations/AnnotationEditorForm/index.js} +2 -13
  54. package/dist/components/Annotations/AnnotationEditorForm/index.js.map +1 -0
  55. package/dist/components/Annotations/constants.d.ts +2 -0
  56. package/dist/components/Annotations/constants.d.ts.map +1 -0
  57. package/dist/components/Annotations/constants.js +15 -0
  58. package/dist/components/Annotations/constants.js.map +1 -0
  59. package/dist/components/Annotations/index.d.ts +3 -0
  60. package/dist/components/Annotations/index.d.ts.map +1 -0
  61. package/dist/components/Annotations/index.js +16 -0
  62. package/dist/components/Annotations/index.js.map +1 -0
  63. package/dist/components/CalculationSelector/CalculationSelector.js +1 -1
  64. package/dist/components/CalculationSelector/CalculationSelector.js.map +1 -1
  65. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts +1 -2
  66. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts.map +1 -1
  67. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js +1 -1
  68. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js.map +1 -1
  69. package/dist/components/DatasourceSelect/DatasourceSelect.js +2 -2
  70. package/dist/components/DatasourceSelect/DatasourceSelect.js.map +1 -1
  71. package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.d.ts +1 -1
  72. package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.d.ts.map +1 -1
  73. package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.js +2 -2
  74. package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.js.map +1 -1
  75. package/dist/components/ItemSelectionActionsOptionsEditor/ItemSelectionActionsOptionsEditor.js +1 -1
  76. package/dist/components/ItemSelectionActionsOptionsEditor/ItemSelectionActionsOptionsEditor.js.map +1 -1
  77. package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js +1 -1
  78. package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js.map +1 -1
  79. package/dist/components/MetricLabelInput/MetricLabelInput.js +1 -1
  80. package/dist/components/MetricLabelInput/MetricLabelInput.js.map +1 -1
  81. package/dist/components/MultiQueryEditor/MultiQueryEditor.js +1 -1
  82. package/dist/components/MultiQueryEditor/MultiQueryEditor.js.map +1 -1
  83. package/dist/components/MultiQueryEditor/QueryEditorContainer.d.ts.map +1 -1
  84. package/dist/components/MultiQueryEditor/QueryEditorContainer.js +100 -15
  85. package/dist/components/MultiQueryEditor/QueryEditorContainer.js.map +1 -1
  86. package/dist/components/MultiQueryEditor/index.d.ts +1 -0
  87. package/dist/components/MultiQueryEditor/index.d.ts.map +1 -1
  88. package/dist/components/MultiQueryEditor/index.js +1 -0
  89. package/dist/components/MultiQueryEditor/index.js.map +1 -1
  90. package/dist/components/MultiQueryEditor/utils.d.ts +8 -0
  91. package/dist/components/MultiQueryEditor/utils.d.ts.map +1 -0
  92. package/dist/components/MultiQueryEditor/utils.js +23 -0
  93. package/dist/components/MultiQueryEditor/utils.js.map +1 -0
  94. package/dist/components/OptionsEditorRadios/OptionsEditorRadios.js +1 -1
  95. package/dist/components/OptionsEditorRadios/OptionsEditorRadios.js.map +1 -1
  96. package/dist/components/OptionsEditorTabPanel/OptionsEditorTabPanel.js +1 -1
  97. package/dist/components/OptionsEditorTabPanel/OptionsEditorTabPanel.js.map +1 -1
  98. package/dist/components/OptionsEditorTabs/OptionsEditorTabs.js +1 -1
  99. package/dist/components/OptionsEditorTabs/OptionsEditorTabs.js.map +1 -1
  100. package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts.map +1 -1
  101. package/dist/components/PanelSpecEditor/PanelSpecEditor.js +5 -8
  102. package/dist/components/PanelSpecEditor/PanelSpecEditor.js.map +1 -1
  103. package/dist/components/PluginEditor/PluginEditor.js +1 -1
  104. package/dist/components/PluginEditor/PluginEditor.js.map +1 -1
  105. package/dist/components/PluginKindSelect/PluginKindSelect.js +1 -1
  106. package/dist/components/PluginKindSelect/PluginKindSelect.js.map +1 -1
  107. package/dist/components/PluginRegistry/PluginRegistry.d.ts.map +1 -1
  108. package/dist/components/PluginRegistry/PluginRegistry.js +12 -16
  109. package/dist/components/PluginRegistry/PluginRegistry.js.map +1 -1
  110. package/dist/components/PluginRegistry/getPluginSearchHelper.d.ts +12 -0
  111. package/dist/components/PluginRegistry/getPluginSearchHelper.d.ts.map +1 -0
  112. package/dist/components/PluginRegistry/getPluginSearchHelper.js +88 -0
  113. package/dist/components/PluginRegistry/getPluginSearchHelper.js.map +1 -0
  114. package/dist/components/PluginRegistry/plugin-indexes.d.ts +4 -6
  115. package/dist/components/PluginRegistry/plugin-indexes.d.ts.map +1 -1
  116. package/dist/components/PluginRegistry/plugin-indexes.js +15 -13
  117. package/dist/components/PluginRegistry/plugin-indexes.js.map +1 -1
  118. package/dist/components/PluginSpecEditor/PluginSpecEditor.d.ts.map +1 -1
  119. package/dist/components/PluginSpecEditor/PluginSpecEditor.js +1 -1
  120. package/dist/components/PluginSpecEditor/PluginSpecEditor.js.map +1 -1
  121. package/dist/components/SelectionOptionsEditor/SelectionOptionsEditor.js +1 -1
  122. package/dist/components/SelectionOptionsEditor/SelectionOptionsEditor.js.map +1 -1
  123. package/dist/components/TimeRangeControls/TimeRangeControls.js +1 -1
  124. package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
  125. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts +1 -1
  126. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
  127. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +1 -1
  128. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
  129. package/dist/components/Variables/VariableEditorForm/VariablePreview.js +1 -1
  130. package/dist/components/Variables/VariableEditorForm/VariablePreview.js.map +1 -1
  131. package/dist/components/Variables/variable-model.d.ts +9 -1
  132. package/dist/components/Variables/variable-model.d.ts.map +1 -1
  133. package/dist/components/Variables/variable-model.js +117 -31
  134. package/dist/components/Variables/variable-model.js.map +1 -1
  135. package/dist/components/index.d.ts +1 -0
  136. package/dist/components/index.d.ts.map +1 -1
  137. package/dist/components/index.js +1 -0
  138. package/dist/components/index.js.map +1 -1
  139. package/dist/context/ValidationProvider.d.ts +4 -2
  140. package/dist/context/ValidationProvider.d.ts.map +1 -1
  141. package/dist/context/ValidationProvider.js +10 -4
  142. package/dist/context/ValidationProvider.js.map +1 -1
  143. package/dist/model/alerts-queries.d.ts +33 -0
  144. package/dist/model/alerts-queries.d.ts.map +1 -0
  145. package/dist/model/alerts-queries.js +15 -0
  146. package/dist/model/alerts-queries.js.map +1 -0
  147. package/dist/model/annotations.d.ts +28 -0
  148. package/dist/model/annotations.d.ts.map +1 -0
  149. package/dist/model/annotations.js +17 -0
  150. package/dist/model/annotations.js.map +1 -0
  151. package/dist/model/datasource.d.ts +1 -8
  152. package/dist/model/datasource.d.ts.map +1 -1
  153. package/dist/model/datasource.js +1 -1
  154. package/dist/model/datasource.js.map +1 -1
  155. package/dist/model/index.d.ts +3 -0
  156. package/dist/model/index.d.ts.map +1 -1
  157. package/dist/model/index.js +3 -0
  158. package/dist/model/index.js.map +1 -1
  159. package/dist/model/log-queries.d.ts +2 -1
  160. package/dist/model/log-queries.d.ts.map +1 -1
  161. package/dist/model/log-queries.js.map +1 -1
  162. package/dist/model/plugin-loading.d.ts.map +1 -1
  163. package/dist/model/plugin-loading.js +24 -8
  164. package/dist/model/plugin-loading.js.map +1 -1
  165. package/dist/model/plugins.d.ts +23 -0
  166. package/dist/model/plugins.d.ts.map +1 -1
  167. package/dist/model/plugins.js +4 -1
  168. package/dist/model/plugins.js.map +1 -1
  169. package/dist/model/silences-queries.d.ts +33 -0
  170. package/dist/model/silences-queries.d.ts.map +1 -0
  171. package/dist/model/silences-queries.js +15 -0
  172. package/dist/model/silences-queries.js.map +1 -0
  173. package/dist/model/trace-queries.d.ts +2 -3
  174. package/dist/model/trace-queries.d.ts.map +1 -1
  175. package/dist/model/trace-queries.js.map +1 -1
  176. package/dist/remote/PersesPlugin.types.d.ts +2 -0
  177. package/dist/remote/PersesPlugin.types.d.ts.map +1 -1
  178. package/dist/remote/PersesPlugin.types.js.map +1 -1
  179. package/dist/remote/PluginLoaderComponent.js +1 -1
  180. package/dist/remote/PluginLoaderComponent.js.map +1 -1
  181. package/dist/remote/PluginRuntime.d.ts +7 -1
  182. package/dist/remote/PluginRuntime.d.ts.map +1 -1
  183. package/dist/remote/PluginRuntime.js +46 -10
  184. package/dist/remote/PluginRuntime.js.map +1 -1
  185. package/dist/remote/remotePluginLoader.d.ts.map +1 -1
  186. package/dist/remote/remotePluginLoader.js +28 -5
  187. package/dist/remote/remotePluginLoader.js.map +1 -1
  188. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.d.ts.map +1 -1
  189. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js +35 -26
  190. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js.map +1 -1
  191. package/dist/runtime/DataQueriesProvider/model.d.ts +4 -4
  192. package/dist/runtime/DataQueriesProvider/model.d.ts.map +1 -1
  193. package/dist/runtime/DataQueriesProvider/model.js +0 -82
  194. package/dist/runtime/DataQueriesProvider/model.js.map +1 -1
  195. package/dist/runtime/RouterProvider.js +1 -1
  196. package/dist/runtime/RouterProvider.js.map +1 -1
  197. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js +1 -1
  198. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js.map +1 -1
  199. package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.js +1 -1
  200. package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.js.map +1 -1
  201. package/dist/runtime/UsageMetricsProvider.js +2 -2
  202. package/dist/runtime/UsageMetricsProvider.js.map +1 -1
  203. package/dist/runtime/alerts-queries.d.ts +11 -0
  204. package/dist/runtime/alerts-queries.d.ts.map +1 -0
  205. package/dist/runtime/alerts-queries.js +89 -0
  206. package/dist/runtime/alerts-queries.js.map +1 -0
  207. package/dist/runtime/annotations.d.ts +6 -0
  208. package/dist/runtime/annotations.d.ts.map +1 -0
  209. package/dist/runtime/annotations.js +129 -0
  210. package/dist/runtime/annotations.js.map +1 -0
  211. package/dist/runtime/datasources.d.ts +6 -0
  212. package/dist/runtime/datasources.d.ts.map +1 -1
  213. package/dist/runtime/datasources.js.map +1 -1
  214. package/dist/runtime/index.d.ts +3 -1
  215. package/dist/runtime/index.d.ts.map +1 -1
  216. package/dist/runtime/index.js +3 -1
  217. package/dist/runtime/index.js.map +1 -1
  218. package/dist/runtime/item-actions.js +1 -1
  219. package/dist/runtime/item-actions.js.map +1 -1
  220. package/dist/runtime/log-queries.js +4 -1
  221. package/dist/runtime/log-queries.js.map +1 -1
  222. package/dist/runtime/plugin-registry.d.ts +2 -2
  223. package/dist/runtime/plugin-registry.d.ts.map +1 -1
  224. package/dist/runtime/plugin-registry.js +12 -3
  225. package/dist/runtime/plugin-registry.js.map +1 -1
  226. package/dist/runtime/profile-queries.js +4 -1
  227. package/dist/runtime/profile-queries.js.map +1 -1
  228. package/dist/runtime/silences-queries.d.ts +11 -0
  229. package/dist/runtime/silences-queries.d.ts.map +1 -0
  230. package/dist/runtime/silences-queries.js +89 -0
  231. package/dist/runtime/silences-queries.js.map +1 -0
  232. package/dist/runtime/time-series-queries.js +4 -1
  233. package/dist/runtime/time-series-queries.js.map +1 -1
  234. package/dist/runtime/trace-queries.js +4 -1
  235. package/dist/runtime/trace-queries.js.map +1 -1
  236. package/dist/test/mock-data.d.ts +3 -1
  237. package/dist/test/mock-data.d.ts.map +1 -1
  238. package/dist/test/mock-data.js +45 -0
  239. package/dist/test/mock-data.js.map +1 -1
  240. package/dist/test/render.js +1 -1
  241. package/dist/test/render.js.map +1 -1
  242. package/dist/test/test-plugins/bert/index.d.ts +12 -6
  243. package/dist/test/test-plugins/bert/index.d.ts.map +1 -1
  244. package/dist/test/test-plugins/bert/index.js +6 -2
  245. package/dist/test/test-plugins/bert/index.js.map +1 -1
  246. package/dist/test/test-plugins/ernie/index.d.ts +8 -6
  247. package/dist/test/test-plugins/ernie/index.d.ts.map +1 -1
  248. package/dist/test/test-plugins/ernie/index.js +6 -2
  249. package/dist/test/test-plugins/ernie/index.js.map +1 -1
  250. package/dist/test/test-plugins/index.js +2 -2
  251. package/dist/test/test-plugins/index.js.map +1 -1
  252. package/dist/test/utils.js +1 -1
  253. package/dist/test/utils.js.map +1 -1
  254. package/dist/test-utils/mock-plugin-registry.d.ts.map +1 -1
  255. package/dist/test-utils/mock-plugin-registry.js +8 -2
  256. package/dist/test-utils/mock-plugin-registry.js.map +1 -1
  257. package/package.json +7 -6
  258. package/dist/cjs/runtime/QueryCountProvider.js +0 -83
  259. package/dist/runtime/QueryCountProvider.d.ts +0 -9
  260. package/dist/runtime/QueryCountProvider.d.ts.map +0 -1
  261. package/dist/runtime/QueryCountProvider.js.map +0 -1
@@ -1,3 +1,4 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
1
2
  // Copyright The Perses Authors
2
3
  // Licensed under the Apache License, Version 2.0 (the \"License\");
3
4
  // you may not use this file except in compliance with the License.
@@ -22,7 +23,6 @@
22
23
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23
24
  // See the License for the specific language governing permissions and
24
25
  // limitations under the License.
25
- import { jsx as _jsx } from "react/jsx-runtime";
26
26
  import { useEffect, useRef, useState } from 'react';
27
27
  import { usePluginRuntime } from './PluginRuntime';
28
28
  function PluginContainer({ pluginFn, props }) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/remote/PluginLoaderComponent.tsx"],"sourcesContent":["// Copyright 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\n/* eslint-disable @typescript-eslint/ban-ts-comment */\n// Copyright 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 { useEffect, useRef, useState } from 'react';\nimport { PersesPlugin, RemotePluginModule } from './PersesPlugin.types';\nimport { usePluginRuntime } from './PluginRuntime';\n\ninterface PluginLoaderProps<P> {\n plugin: PersesPlugin;\n props?: P;\n field?: string;\n}\n\nfunction PluginContainer<P>({\n pluginFn,\n props,\n}: {\n pluginFn: (props: P | undefined) => JSX.Element;\n props: P | undefined;\n}): JSX.Element {\n return pluginFn(props);\n}\n\nexport function PluginLoaderComponent<P>({ plugin, props, field }: PluginLoaderProps<P>): JSX.Element | null {\n const { loadPlugin } = usePluginRuntime({ plugin });\n const [pluginModule, setPluginModule] = useState<RemotePluginModule | null>(null);\n const [error, setError] = useState<Error | null>(null);\n\n const name = `${plugin.moduleName}-${plugin.name}`;\n const previousPluginName = useRef<string>(name);\n\n useEffect(() => {\n previousPluginName.current = name;\n setError(null);\n\n loadPlugin()\n .then((module) => {\n setPluginModule(module);\n })\n .catch((error) => {\n setPluginModule(null);\n console.error(\n `PluginLoaderComponent: Error loading plugin ${plugin.name} from module ${plugin.moduleName}:`,\n error\n );\n setError(\n new Error(`PluginLoaderComponent: Error loading plugin ${plugin.name} from module ${plugin.moduleName}`)\n );\n });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [name]);\n\n if (error) {\n throw error;\n }\n\n if (!pluginModule) {\n return null;\n }\n\n let pluginFunction = pluginModule[plugin.name];\n\n if (field && pluginFunction && typeof pluginFunction === 'object' && field in pluginFunction) {\n pluginFunction = (pluginFunction as Record<string, unknown>)[field];\n }\n\n if (!pluginFunction) {\n throw new Error(`PluginLoaderComponent: Plugin module ${plugin.moduleName} does not have a ${plugin.name} export`);\n }\n\n if (typeof pluginFunction !== 'function') {\n throw new Error(`PluginLoaderComponent: Plugin ${plugin.name} export is not a function`);\n }\n\n // make sure to re mount the plugin when changes, to avoid mismatch in hooks ordering when re rendering\n if (previousPluginName.current !== name) {\n return null;\n }\n\n return (\n <PluginContainer key={name} pluginFn={pluginFunction as (props: P | undefined) => JSX.Element} props={props} />\n );\n}\n"],"names":["useEffect","useRef","useState","usePluginRuntime","PluginContainer","pluginFn","props","PluginLoaderComponent","plugin","field","loadPlugin","pluginModule","setPluginModule","error","setError","name","moduleName","previousPluginName","current","then","module","catch","console","Error","pluginFunction"],"mappings":"AAAA,+BAA+B;AAC/B,oEAAoE;AACpE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,sEAAsE;AACtE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,oDAAoD,GACpD,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAEpD,SAASC,gBAAgB,QAAQ,kBAAkB;AAQnD,SAASC,gBAAmB,EAC1BC,QAAQ,EACRC,KAAK,EAIN;IACC,OAAOD,SAASC;AAClB;AAEA,OAAO,SAASC,sBAAyB,EAAEC,MAAM,EAAEF,KAAK,EAAEG,KAAK,EAAwB;IACrF,MAAM,EAAEC,UAAU,EAAE,GAAGP,iBAAiB;QAAEK;IAAO;IACjD,MAAM,CAACG,cAAcC,gBAAgB,GAAGV,SAAoC;IAC5E,MAAM,CAACW,OAAOC,SAAS,GAAGZ,SAAuB;IAEjD,MAAMa,OAAO,GAAGP,OAAOQ,UAAU,CAAC,CAAC,EAAER,OAAOO,IAAI,EAAE;IAClD,MAAME,qBAAqBhB,OAAec;IAE1Cf,UAAU;QACRiB,mBAAmBC,OAAO,GAAGH;QAC7BD,SAAS;QAETJ,aACGS,IAAI,CAAC,CAACC;YACLR,gBAAgBQ;QAClB,GACCC,KAAK,CAAC,CAACR;YACND,gBAAgB;YAChBU,QAAQT,KAAK,CACX,CAAC,4CAA4C,EAAEL,OAAOO,IAAI,CAAC,aAAa,EAAEP,OAAOQ,UAAU,CAAC,CAAC,CAAC,EAC9FH;YAEFC,SACE,IAAIS,MAAM,CAAC,4CAA4C,EAAEf,OAAOO,IAAI,CAAC,aAAa,EAAEP,OAAOQ,UAAU,EAAE;QAE3G;IACF,uDAAuD;IACzD,GAAG;QAACD;KAAK;IAET,IAAIF,OAAO;QACT,MAAMA;IACR;IAEA,IAAI,CAACF,cAAc;QACjB,OAAO;IACT;IAEA,IAAIa,iBAAiBb,YAAY,CAACH,OAAOO,IAAI,CAAC;IAE9C,IAAIN,SAASe,kBAAkB,OAAOA,mBAAmB,YAAYf,SAASe,gBAAgB;QAC5FA,iBAAiB,AAACA,cAA0C,CAACf,MAAM;IACrE;IAEA,IAAI,CAACe,gBAAgB;QACnB,MAAM,IAAID,MAAM,CAAC,qCAAqC,EAAEf,OAAOQ,UAAU,CAAC,iBAAiB,EAAER,OAAOO,IAAI,CAAC,OAAO,CAAC;IACnH;IAEA,IAAI,OAAOS,mBAAmB,YAAY;QACxC,MAAM,IAAID,MAAM,CAAC,8BAA8B,EAAEf,OAAOO,IAAI,CAAC,yBAAyB,CAAC;IACzF;IAEA,uGAAuG;IACvG,IAAIE,mBAAmBC,OAAO,KAAKH,MAAM;QACvC,OAAO;IACT;IAEA,qBACE,KAACX;QAA2BC,UAAUmB;QAAyDlB,OAAOA;OAAhFS;AAE1B"}
1
+ {"version":3,"sources":["../../src/remote/PluginLoaderComponent.tsx"],"sourcesContent":["// Copyright 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\n/* eslint-disable @typescript-eslint/ban-ts-comment */\n// Copyright 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 { useEffect, useRef, useState } from 'react';\nimport { PersesPlugin, RemotePluginModule } from './PersesPlugin.types';\nimport { usePluginRuntime } from './PluginRuntime';\n\ninterface PluginLoaderProps<P> {\n plugin: PersesPlugin;\n props?: P;\n field?: string;\n}\n\nfunction PluginContainer<P>({\n pluginFn,\n props,\n}: {\n pluginFn: (props: P | undefined) => JSX.Element;\n props: P | undefined;\n}): JSX.Element {\n return pluginFn(props);\n}\n\nexport function PluginLoaderComponent<P>({ plugin, props, field }: PluginLoaderProps<P>): JSX.Element | null {\n const { loadPlugin } = usePluginRuntime({ plugin });\n const [pluginModule, setPluginModule] = useState<RemotePluginModule | null>(null);\n const [error, setError] = useState<Error | null>(null);\n\n const name = `${plugin.moduleName}-${plugin.name}`;\n const previousPluginName = useRef<string>(name);\n\n useEffect(() => {\n previousPluginName.current = name;\n setError(null);\n\n loadPlugin()\n .then((module) => {\n setPluginModule(module);\n })\n .catch((error) => {\n setPluginModule(null);\n console.error(\n `PluginLoaderComponent: Error loading plugin ${plugin.name} from module ${plugin.moduleName}:`,\n error\n );\n setError(\n new Error(`PluginLoaderComponent: Error loading plugin ${plugin.name} from module ${plugin.moduleName}`)\n );\n });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [name]);\n\n if (error) {\n throw error;\n }\n\n if (!pluginModule) {\n return null;\n }\n\n let pluginFunction = pluginModule[plugin.name];\n\n if (field && pluginFunction && typeof pluginFunction === 'object' && field in pluginFunction) {\n pluginFunction = (pluginFunction as Record<string, unknown>)[field];\n }\n\n if (!pluginFunction) {\n throw new Error(`PluginLoaderComponent: Plugin module ${plugin.moduleName} does not have a ${plugin.name} export`);\n }\n\n if (typeof pluginFunction !== 'function') {\n throw new Error(`PluginLoaderComponent: Plugin ${plugin.name} export is not a function`);\n }\n\n // make sure to re mount the plugin when changes, to avoid mismatch in hooks ordering when re rendering\n if (previousPluginName.current !== name) {\n return null;\n }\n\n return (\n <PluginContainer key={name} pluginFn={pluginFunction as (props: P | undefined) => JSX.Element} props={props} />\n );\n}\n"],"names":["useEffect","useRef","useState","usePluginRuntime","PluginContainer","pluginFn","props","PluginLoaderComponent","plugin","field","loadPlugin","pluginModule","setPluginModule","error","setError","name","moduleName","previousPluginName","current","then","module","catch","console","Error","pluginFunction"],"mappings":";AAAA,+BAA+B;AAC/B,oEAAoE;AACpE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,sEAAsE;AACtE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,oDAAoD,GACpD,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAEpD,SAASC,gBAAgB,QAAQ,kBAAkB;AAQnD,SAASC,gBAAmB,EAC1BC,QAAQ,EACRC,KAAK,EAIN;IACC,OAAOD,SAASC;AAClB;AAEA,OAAO,SAASC,sBAAyB,EAAEC,MAAM,EAAEF,KAAK,EAAEG,KAAK,EAAwB;IACrF,MAAM,EAAEC,UAAU,EAAE,GAAGP,iBAAiB;QAAEK;IAAO;IACjD,MAAM,CAACG,cAAcC,gBAAgB,GA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"}
@@ -1,6 +1,12 @@
1
1
  import { ModuleFederation } from '@module-federation/enhanced/runtime';
2
2
  import { PersesPlugin, RemotePluginModule } from './PersesPlugin.types';
3
- export declare const loadPlugin: (moduleName: string, pluginName: string, baseURL?: string) => Promise<RemotePluginModule | null>;
3
+ export declare const loadPlugin: (target: {
4
+ moduleName: string;
5
+ pluginName: string;
6
+ registry?: string;
7
+ version?: string;
8
+ baseURL?: string;
9
+ }) => Promise<RemotePluginModule | null>;
4
10
  export declare function usePluginRuntime({ plugin }: {
5
11
  plugin: PersesPlugin;
6
12
  }): {
@@ -1 +1 @@
1
- {"version":3,"file":"PluginRuntime.d.ts","sourceRoot":"","sources":["../../src/remote/PluginRuntime.tsx"],"names":[],"mappings":"AA2BA,OAAO,EAAkB,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAOvF,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAqMxE,eAAO,MAAM,UAAU,eACT,MAAM,cACN,MAAM,YACR,MAAM,KACf,QAAQ,kBAAkB,GAAG,IAAI,CAMnC,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,EAAE,YAAY,CAAA;CAAE,GAAG;IACtE,aAAa,EAAE,gBAAgB,CAAC;IAChC,UAAU,EAAE,MAAM,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAAC;CACtD,CAKA"}
1
+ {"version":3,"file":"PluginRuntime.d.ts","sourceRoot":"","sources":["../../src/remote/PluginRuntime.tsx"],"names":[],"mappings":"AA2BA,OAAO,EAAkB,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAOvF,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AA6NxE,eAAO,MAAM,UAAU,WAAkB;IACvC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,KAAG,QAAQ,kBAAkB,GAAG,IAAI,CAOpC,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,EAAE,YAAY,CAAA;CAAE,GAAG;IACtE,aAAa,EAAE,gBAAgB,CAAC;IAChC,UAAU,EAAE,MAAM,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAAC;CACtD,CAQA"}
@@ -83,7 +83,14 @@ const getPluginRuntime = ()=>{
83
83
  requiredVersion: '^5.5.0'
84
84
  }
85
85
  },
86
- // TODO should we add @perses-dev/spec here ?
86
+ '@perses-dev/spec': {
87
+ version: '0.2.0-beta.2',
88
+ lib: ()=>require('@perses-dev/spec'),
89
+ shareConfig: {
90
+ singleton: true,
91
+ requiredVersion: '^0.2.0-beta.2'
92
+ }
93
+ },
87
94
  '@perses-dev/core': {
88
95
  version: '0.53.1',
89
96
  lib: ()=>require('@perses-dev/core'),
@@ -92,6 +99,14 @@ const getPluginRuntime = ()=>{
92
99
  requiredVersion: '^0.53.1'
93
100
  }
94
101
  },
102
+ '@perses-dev/client': {
103
+ version: '0.54.0-beta.1',
104
+ lib: ()=>require('@perses-dev/client'),
105
+ shareConfig: {
106
+ singleton: true,
107
+ requiredVersion: '^0.54.0-beta.1'
108
+ }
109
+ },
95
110
  '@perses-dev/components': {
96
111
  version: '0.53.1',
97
112
  lib: ()=>require('@perses-dev/components'),
@@ -204,29 +219,50 @@ const getPluginRuntime = ()=>{
204
219
  }
205
220
  return instance;
206
221
  };
207
- const registerRemote = (name, baseURL)=>{
222
+ function getModuleFederationRemoteName(name, registry, version) {
223
+ return `${name}:${registry ?? ''}:${version ?? ''}`;
224
+ }
225
+ const registerRemote = (name, registry, version, baseURL)=>{
208
226
  const pluginRuntime = getPluginRuntime();
209
- const existingRemote = pluginRuntime.options.remotes.find((remote)=>remote.name === name);
227
+ const registryName = getModuleFederationRemoteName(name, registry, version);
228
+ const existingRemote = pluginRuntime.options.remotes.find((remote)=>remote.name === registryName);
210
229
  if (!existingRemote) {
211
- const remoteEntryURL = baseURL ? `${baseURL}/${name}/mf-manifest.json` : `/plugins/${name}/mf-manifest.json`;
230
+ const nameVersionRegistry = [
231
+ name,
232
+ version,
233
+ registry
234
+ ].filter(Boolean).join('~');
235
+ const prefix = baseURL || '/plugins';
236
+ const remoteEntryURL = `${prefix}/${nameVersionRegistry}/mf-manifest.json`;
212
237
  pluginRuntime.registerRemotes([
213
238
  {
214
- name,
239
+ name: registryName,
215
240
  entry: remoteEntryURL,
216
- alias: name
241
+ alias: registryName
217
242
  }
218
243
  ]);
219
244
  }
220
245
  };
221
- export const loadPlugin = async (moduleName, pluginName, baseURL)=>{
222
- registerRemote(moduleName, baseURL);
246
+ export const loadPlugin = async (target)=>{
247
+ const { moduleName, pluginName, registry, version, baseURL } = target;
248
+ registerRemote(moduleName, registry, version, baseURL);
223
249
  const pluginRuntime = getPluginRuntime();
224
- return pluginRuntime.loadRemote(`${moduleName}/${pluginName}`);
250
+ const registryName = getModuleFederationRemoteName(moduleName, registry, version);
251
+ return pluginRuntime.loadRemote(`${registryName}/${pluginName}`);
225
252
  };
226
253
  export function usePluginRuntime({ plugin }) {
227
254
  return {
228
255
  pluginRuntime: getPluginRuntime(),
229
- loadPlugin: ()=>loadPlugin(plugin.moduleName, plugin.name, plugin.baseURL)
256
+ loadPlugin: ()=>{
257
+ const { moduleName, name: pluginName, registry, version, baseURL } = plugin;
258
+ return loadPlugin({
259
+ moduleName,
260
+ pluginName,
261
+ registry,
262
+ version,
263
+ baseURL
264
+ });
265
+ }
230
266
  };
231
267
  }
232
268
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/remote/PluginRuntime.tsx"],"sourcesContent":["// Copyright 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\n/* eslint-disable @typescript-eslint/no-require-imports */\n// Copyright 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 { createInstance, ModuleFederation } from '@module-federation/enhanced/runtime';\n\nimport * as ReactQuery from '@tanstack/react-query';\nimport React from 'react';\nimport ReactDOM from 'react-dom';\nimport * as ReactHookForm from 'react-hook-form';\nimport * as ReactRouterDOM from 'react-router-dom';\nimport { PersesPlugin, RemotePluginModule } from './PersesPlugin.types';\n\nlet instance: ModuleFederation | null = null;\n\nconst getPluginRuntime = (): ModuleFederation => {\n if (instance === null) {\n const pluginRuntime = createInstance({\n name: '@perses/perses-ui-host',\n remotes: [], // all remotes are loaded dynamically\n shared: {\n react: {\n version: React.version,\n lib: () => React,\n shareConfig: {\n singleton: true,\n requiredVersion: `^${React.version}`,\n },\n },\n 'react-dom': {\n version: '18.3.1',\n lib: () => ReactDOM,\n shareConfig: {\n singleton: true,\n requiredVersion: `^18.3.1`,\n },\n },\n 'react-router-dom': {\n version: '6.26.0',\n lib: () => ReactRouterDOM,\n shareConfig: {\n singleton: true,\n requiredVersion: '^6.26.0',\n },\n },\n '@tanstack/react-query': {\n version: '4.39.1',\n lib: () => ReactQuery,\n shareConfig: {\n singleton: true,\n requiredVersion: '^4.39.1',\n },\n },\n 'react-hook-form': {\n version: '7.52.2',\n lib: () => ReactHookForm,\n shareConfig: {\n singleton: true,\n requiredVersion: '^7.52.2',\n },\n },\n echarts: {\n version: '5.5.0',\n lib: () => require('echarts'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^5.5.0',\n },\n },\n // TODO should we add @perses-dev/spec here ?\n '@perses-dev/core': {\n version: '0.53.1',\n lib: () => require('@perses-dev/core'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.53.1',\n },\n },\n '@perses-dev/components': {\n version: '0.53.1',\n lib: () => require('@perses-dev/components'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.53.1',\n },\n },\n '@perses-dev/plugin-system': {\n version: '0.53.1',\n lib: () => require('@perses-dev/plugin-system'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.53.1',\n },\n },\n '@perses-dev/explore': {\n version: '0.53.1',\n lib: () => require('@perses-dev/explore'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.53.1',\n },\n },\n '@perses-dev/dashboards': {\n version: '0.53.1',\n lib: () => require('@perses-dev/dashboards'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.53.1',\n },\n },\n // Below are the shared modules that are used by the plugins, this can be part of the SDK\n 'date-fns': {\n version: '4.1.0',\n lib: () => require('date-fns'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^4.1.0',\n },\n },\n 'date-fns-tz': {\n version: '3.2.0',\n lib: () => require('date-fns-tz'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^3.2.0',\n },\n },\n lodash: {\n version: '4.17.21',\n lib: () => require('lodash'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^4.17.21',\n },\n },\n '@emotion/react': {\n version: '11.11.3',\n lib: () => require('@emotion/react'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^11.11.3',\n },\n },\n '@emotion/styled': {\n version: '11.11.0',\n lib: () => require('@emotion/styled'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^11.11.0',\n },\n },\n '@hookform/resolvers/zod': {\n version: '3.3.4',\n lib: () => require('@hookform/resolvers/zod'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^3.3.4',\n },\n },\n 'use-resize-observer': {\n version: '9.1.0',\n lib: () => require('use-resize-observer'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^9.1.0',\n },\n },\n 'mdi-material-ui': {\n version: '7.4.0',\n lib: () => require('mdi-material-ui'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^7.4.0',\n },\n },\n immer: {\n version: '10.1.1',\n lib: () => require('immer'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^10.1.1',\n },\n },\n },\n });\n\n instance = pluginRuntime;\n\n return instance;\n }\n return instance;\n};\n\nconst registerRemote = (name: string, baseURL?: string): void => {\n const pluginRuntime = getPluginRuntime();\n const existingRemote = pluginRuntime.options.remotes.find((remote) => remote.name === name);\n if (!existingRemote) {\n const remoteEntryURL = baseURL ? `${baseURL}/${name}/mf-manifest.json` : `/plugins/${name}/mf-manifest.json`;\n pluginRuntime.registerRemotes([\n {\n name,\n entry: remoteEntryURL,\n alias: name,\n },\n ]);\n }\n};\n\nexport const loadPlugin = async (\n moduleName: string,\n pluginName: string,\n baseURL?: string\n): Promise<RemotePluginModule | null> => {\n registerRemote(moduleName, baseURL);\n\n const pluginRuntime = getPluginRuntime();\n\n return pluginRuntime.loadRemote<RemotePluginModule>(`${moduleName}/${pluginName}`);\n};\n\nexport function usePluginRuntime({ plugin }: { plugin: PersesPlugin }): {\n pluginRuntime: ModuleFederation;\n loadPlugin: () => Promise<RemotePluginModule | null>;\n} {\n return {\n pluginRuntime: getPluginRuntime(),\n loadPlugin: () => loadPlugin(plugin.moduleName, plugin.name, plugin.baseURL),\n };\n}\n"],"names":["createInstance","ReactQuery","React","ReactDOM","ReactHookForm","ReactRouterDOM","instance","getPluginRuntime","pluginRuntime","name","remotes","shared","react","version","lib","shareConfig","singleton","requiredVersion","echarts","require","lodash","immer","registerRemote","baseURL","existingRemote","options","find","remote","remoteEntryURL","registerRemotes","entry","alias","loadPlugin","moduleName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;AAEF,OAAO,SAASE,iBAAiB,EAAEC,MAAM,EAA4B;IAInE,OAAO;QACL7B,eAAeD;QACfyB,YAAY,IAAMA,WAAWK,OAAOJ,UAAU,EAAEI,OAAO5B,IAAI,EAAE4B,OAAOd,OAAO;IAC7E;AACF"}
1
+ {"version":3,"sources":["../../src/remote/PluginRuntime.tsx"],"sourcesContent":["// Copyright 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\n/* eslint-disable @typescript-eslint/no-require-imports */\n// Copyright 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 { createInstance, ModuleFederation } from '@module-federation/enhanced/runtime';\n\nimport * as ReactQuery from '@tanstack/react-query';\nimport React from 'react';\nimport ReactDOM from 'react-dom';\nimport * as ReactHookForm from 'react-hook-form';\nimport * as ReactRouterDOM from 'react-router-dom';\nimport { PersesPlugin, RemotePluginModule } from './PersesPlugin.types';\n\nlet instance: ModuleFederation | null = null;\n\nconst getPluginRuntime = (): ModuleFederation => {\n if (instance === null) {\n const pluginRuntime = createInstance({\n name: '@perses/perses-ui-host',\n remotes: [], // all remotes are loaded dynamically\n shared: {\n react: {\n version: React.version,\n lib: () => React,\n shareConfig: {\n singleton: true,\n requiredVersion: `^${React.version}`,\n },\n },\n 'react-dom': {\n version: '18.3.1',\n lib: () => ReactDOM,\n shareConfig: {\n singleton: true,\n requiredVersion: `^18.3.1`,\n },\n },\n 'react-router-dom': {\n version: '6.26.0',\n lib: () => ReactRouterDOM,\n shareConfig: {\n singleton: true,\n requiredVersion: '^6.26.0',\n },\n },\n '@tanstack/react-query': {\n version: '4.39.1',\n lib: () => ReactQuery,\n shareConfig: {\n singleton: true,\n requiredVersion: '^4.39.1',\n },\n },\n 'react-hook-form': {\n version: '7.52.2',\n lib: () => ReactHookForm,\n shareConfig: {\n singleton: true,\n requiredVersion: '^7.52.2',\n },\n },\n echarts: {\n version: '5.5.0',\n lib: () => require('echarts'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^5.5.0',\n },\n },\n '@perses-dev/spec': {\n version: '0.2.0-beta.2',\n lib: () => require('@perses-dev/spec'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.2.0-beta.2',\n },\n },\n '@perses-dev/core': {\n version: '0.53.1',\n lib: () => require('@perses-dev/core'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.53.1',\n },\n },\n '@perses-dev/client': {\n version: '0.54.0-beta.1',\n lib: () => require('@perses-dev/client'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.54.0-beta.1',\n },\n },\n '@perses-dev/components': {\n version: '0.53.1',\n lib: () => require('@perses-dev/components'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.53.1',\n },\n },\n '@perses-dev/plugin-system': {\n version: '0.53.1',\n lib: () => require('@perses-dev/plugin-system'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.53.1',\n },\n },\n '@perses-dev/explore': {\n version: '0.53.1',\n lib: () => require('@perses-dev/explore'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.53.1',\n },\n },\n '@perses-dev/dashboards': {\n version: '0.53.1',\n lib: () => require('@perses-dev/dashboards'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.53.1',\n },\n },\n // Below are the shared modules that are used by the plugins, this can be part of the SDK\n 'date-fns': {\n version: '4.1.0',\n lib: () => require('date-fns'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^4.1.0',\n },\n },\n 'date-fns-tz': {\n version: '3.2.0',\n lib: () => require('date-fns-tz'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^3.2.0',\n },\n },\n lodash: {\n version: '4.17.21',\n lib: () => require('lodash'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^4.17.21',\n },\n },\n '@emotion/react': {\n version: '11.11.3',\n lib: () => require('@emotion/react'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^11.11.3',\n },\n },\n '@emotion/styled': {\n version: '11.11.0',\n lib: () => require('@emotion/styled'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^11.11.0',\n },\n },\n '@hookform/resolvers/zod': {\n version: '3.3.4',\n lib: () => require('@hookform/resolvers/zod'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^3.3.4',\n },\n },\n 'use-resize-observer': {\n version: '9.1.0',\n lib: () => require('use-resize-observer'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^9.1.0',\n },\n },\n 'mdi-material-ui': {\n version: '7.4.0',\n lib: () => require('mdi-material-ui'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^7.4.0',\n },\n },\n immer: {\n version: '10.1.1',\n lib: () => require('immer'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^10.1.1',\n },\n },\n },\n });\n\n instance = pluginRuntime;\n\n return instance;\n }\n return instance;\n};\n\nfunction getModuleFederationRemoteName(name: string, registry?: string, version?: string): string {\n return `${name}:${registry ?? ''}:${version ?? ''}`;\n}\n\nconst registerRemote = (name: string, registry?: string, version?: string, baseURL?: string): void => {\n const pluginRuntime = getPluginRuntime();\n const registryName = getModuleFederationRemoteName(name, registry, version);\n\n const existingRemote = pluginRuntime.options.remotes.find((remote) => remote.name === registryName);\n if (!existingRemote) {\n const nameVersionRegistry = [name, version, registry].filter(Boolean).join('~');\n const prefix = baseURL || '/plugins';\n const remoteEntryURL = `${prefix}/${nameVersionRegistry}/mf-manifest.json`;\n\n pluginRuntime.registerRemotes([\n {\n name: registryName,\n entry: remoteEntryURL,\n alias: registryName,\n },\n ]);\n }\n};\n\nexport const loadPlugin = async (target: {\n moduleName: string;\n pluginName: string;\n registry?: string;\n version?: string;\n baseURL?: string;\n}): Promise<RemotePluginModule | null> => {\n const { moduleName, pluginName, registry, version, baseURL } = target;\n registerRemote(moduleName, registry, version, baseURL);\n\n const pluginRuntime = getPluginRuntime();\n const registryName = getModuleFederationRemoteName(moduleName, registry, version);\n return pluginRuntime.loadRemote<RemotePluginModule>(`${registryName}/${pluginName}`);\n};\n\nexport function usePluginRuntime({ plugin }: { plugin: PersesPlugin }): {\n pluginRuntime: ModuleFederation;\n loadPlugin: () => Promise<RemotePluginModule | null>;\n} {\n return {\n pluginRuntime: getPluginRuntime(),\n loadPlugin: (): Promise<RemotePluginModule | null> => {\n const { moduleName, name: pluginName, registry, version, baseURL } = plugin;\n return loadPlugin({ moduleName, pluginName, registry, version, baseURL });\n },\n };\n}\n"],"names":["createInstance","ReactQuery","React","ReactDOM","ReactHookForm","ReactRouterDOM","instance","getPluginRuntime","pluginRuntime","name","remotes","shared","react","version","lib","shareConfig","singleton","requiredVersion","echarts","require","lodash","immer","getModuleFederationRemoteName","registry","registerRemote","baseURL","registryName","existingRemote","options","find","remote","nameVersionRegistry","filter","Boolean","join","prefix","remoteEntryURL","registerRemotes","entry","alias","loadPlugin","target","moduleName","pluginName","loadRemote","usePluginRuntime","plugin"],"mappings":"AAAA,+BAA+B;AAC/B,oEAAoE;AACpE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,sEAAsE;AACtE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,wDAAwD,GACxD,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C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;AACF;AAEA,OAAO,MAAMc,aAAa,OAAOC;IAO/B,MAAM,EAAEC,UAAU,EAAEC,UAAU,EAAEpB,QAAQ,EAAEV,OAAO,EAAEY,OAAO,EAAE,GAAGgB;IAC/DjB,eAAekB,YAAYnB,UAAUV,SAASY;IAE9C,MAAMjB,gBAAgBD;IACtB,MAAMmB,eAAeJ,8BAA8BoB,YAAYnB,UAAUV;IACzE,OAAOL,cAAcoC,UAAU,CAAqB,GAAGlB,aAAa,CAAC,EAAEiB,YAAY;AACrF,EAAE;AAEF,OAAO,SAASE,iBAAiB,EAAEC,MAAM,EAA4B;IAInE,OAAO;QACLtC,eAAeD;QACfiC,YAAY;YACV,MAAM,EAAEE,UAAU,EAAEjC,MAAMkC,UAAU,EAAEpB,QAAQ,EAAEV,OAAO,EAAEY,OAAO,EAAE,GAAGqB;YACrE,OAAON,WAAW;gBAAEE;gBAAYC;gBAAYpB;gBAAUV;gBAASY;YAAQ;QACzE;IACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"remotePluginLoader.d.ts","sourceRoot":"","sources":["../../src/remote/remotePluginLoader.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAwC,MAAM,2BAA2B,CAAC;AA8B/F,KAAK,yBAAyB,GAAG;IAC/B;;;QAGI;IACJ,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;QAGI;IACJ,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAwBF;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,CAAC,EAAE,yBAAyB,GAAG,YAAY,CA0CpF"}
1
+ {"version":3,"file":"remotePluginLoader.d.ts","sourceRoot":"","sources":["../../src/remote/remotePluginLoader.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,YAAY,EAKb,MAAM,2BAA2B,CAAC;AA8BnC,KAAK,yBAAyB,GAAG;IAC/B;;;QAGI;IACJ,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;QAGI;IACJ,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAwBF;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,CAAC,EAAE,yBAAyB,GAAG,YAAY,CAyDpF"}
@@ -10,6 +10,7 @@
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 { getPluginModuleCompoundKey } from '@perses-dev/plugin-system';
13
14
  import { loadPlugin } from './PluginRuntime';
14
15
  const isPluginMetadata = (plugin)=>{
15
16
  return typeof plugin === 'object' && plugin !== null && 'kind' in plugin && 'spec' in plugin && typeof plugin.spec === 'object' && plugin.spec !== null && 'name' in plugin.spec;
@@ -52,17 +53,39 @@ const paramToOptions = (options)=>{
52
53
  return pluginModules;
53
54
  },
54
55
  importPluginModule: async (resource)=>{
55
- const pluginModuleName = resource.metadata.name;
56
+ const { name: pluginModuleName, version, registry } = resource.metadata;
56
57
  const pluginModule = {};
57
- for (const plugin of resource.spec.plugins){
58
- const remotePluginModule = await loadPlugin(pluginModuleName, plugin.spec.name, pluginsAssetsPath);
58
+ const loadPromises = resource.spec.plugins.map(async (plugin)=>{
59
+ const remotePluginModule = await loadPlugin({
60
+ moduleName: pluginModuleName,
61
+ pluginName: plugin.spec.name,
62
+ registry,
63
+ version,
64
+ baseURL: pluginsAssetsPath
65
+ });
59
66
  const remotePlugin = remotePluginModule?.[plugin.spec.name];
60
67
  if (remotePlugin) {
61
- pluginModule[plugin.spec.name] = remotePlugin;
68
+ return {
69
+ kind: plugin.kind,
70
+ name: plugin.spec.name,
71
+ remotePlugin
72
+ };
62
73
  } else {
63
74
  console.error(`RemotePluginLoader: Error loading plugin ${plugin.spec.name}`);
75
+ return null;
64
76
  }
65
- }
77
+ });
78
+ const loadedPlugins = await Promise.all(loadPromises);
79
+ loadedPlugins.forEach((item)=>{
80
+ if (item?.remotePlugin) {
81
+ pluginModule[getPluginModuleCompoundKey({
82
+ kind: item.kind,
83
+ name: item.name,
84
+ registry,
85
+ version
86
+ })] = item.remotePlugin;
87
+ }
88
+ });
66
89
  return pluginModule;
67
90
  }
68
91
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/remote/remotePluginLoader.ts"],"sourcesContent":["// Copyright 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 { PluginLoader, PluginMetadata, PluginModuleResource } from '@perses-dev/plugin-system';\nimport { RemotePluginModule } from './PersesPlugin.types';\nimport { loadPlugin } from './PluginRuntime';\n\nconst isPluginMetadata = (plugin: unknown): plugin is PluginMetadata => {\n return (\n typeof plugin === 'object' &&\n plugin !== null &&\n 'kind' in plugin &&\n 'spec' in plugin &&\n typeof plugin.spec === 'object' &&\n plugin.spec !== null &&\n 'name' in plugin.spec\n );\n};\n\nconst isPluginModuleResource = (pluginModule: unknown): pluginModule is PluginModuleResource => {\n return (\n typeof pluginModule === 'object' &&\n pluginModule !== null &&\n 'metadata' in pluginModule &&\n 'spec' in pluginModule &&\n typeof pluginModule.spec === 'object' &&\n pluginModule.spec !== null &&\n 'plugins' in pluginModule.spec &&\n Array.isArray(pluginModule.spec.plugins) &&\n pluginModule.spec.plugins.every(isPluginMetadata)\n );\n};\n\ntype RemotePluginLoaderOptions = {\n /**\n * The API path for fetching available Perses plugins. Used to construct the full URL to the `/api/v1/plugins` endpoint.\n * @default ''\n **/\n apiPrefix?: string;\n /**\n * The base URL for loading plugin assets (e.g., JavaScript files). Used to construct the full URL to the `/plugins` directory\n * @default ''\n **/\n baseURL?: string;\n};\n\ntype ParsedPluginOptions = {\n pluginsApiPath: string;\n pluginsAssetsPath: string;\n};\n\nconst DEFAULT_PLUGINS_API_PATH = '/api/v1/plugins';\nconst DEFAULT_PLUGINS_ASSETS_PATH = '/plugins';\n\nconst paramToOptions = (options?: RemotePluginLoaderOptions): ParsedPluginOptions => {\n if (options === undefined) {\n return {\n pluginsApiPath: DEFAULT_PLUGINS_API_PATH,\n pluginsAssetsPath: DEFAULT_PLUGINS_ASSETS_PATH,\n };\n }\n\n return {\n pluginsApiPath: `${options?.apiPrefix ?? ''}${DEFAULT_PLUGINS_API_PATH}`,\n pluginsAssetsPath: `${options?.baseURL ?? ''}${DEFAULT_PLUGINS_ASSETS_PATH}`,\n };\n};\n\n/**\n * Get a PluginLoader that fetches the list of installed plugins from a remote server and loads them as needed.\n * @param options - Optional configuration options for the remote plugin loader.\n */\nexport function remotePluginLoader(options?: RemotePluginLoaderOptions): PluginLoader {\n const { pluginsApiPath, pluginsAssetsPath } = paramToOptions(options);\n\n return {\n getInstalledPlugins: async (): Promise<PluginModuleResource[]> => {\n const pluginsResponse = await fetch(pluginsApiPath);\n\n const plugins = await pluginsResponse.json();\n\n let pluginModules: PluginModuleResource[] = [];\n\n if (Array.isArray(plugins)) {\n pluginModules = plugins.filter(isPluginModuleResource);\n } else {\n console.error('RemotePluginLoader: Error loading plugins, response is not an array');\n }\n\n if (!pluginModules.length) {\n console.error('RemotePluginLoader: No valid plugins found');\n }\n\n return pluginModules;\n },\n importPluginModule: async (resource): Promise<RemotePluginModule> => {\n const pluginModuleName = resource.metadata.name;\n\n const pluginModule: RemotePluginModule = {};\n\n for (const plugin of resource.spec.plugins) {\n const remotePluginModule = await loadPlugin(pluginModuleName, plugin.spec.name, pluginsAssetsPath);\n\n const remotePlugin = remotePluginModule?.[plugin.spec.name];\n if (remotePlugin) {\n pluginModule[plugin.spec.name] = remotePlugin;\n } else {\n console.error(`RemotePluginLoader: Error loading plugin ${plugin.spec.name}`);\n }\n }\n\n return pluginModule;\n },\n };\n}\n"],"names":["loadPlugin","isPluginMetadata","plugin","spec","isPluginModuleResource","pluginModule","Array","isArray","plugins","every","DEFAULT_PLUGINS_API_PATH","DEFAULT_PLUGINS_ASSETS_PATH","paramToOptions","options","undefined","pluginsApiPath","pluginsAssetsPath","apiPrefix","baseURL","remotePluginLoader","getInstalledPlugins","pluginsResponse","fetch","json","pluginModules","filter","console","error","length","importPluginModule","resource","pluginModuleName","metadata","name","remotePluginModule","remotePlugin"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,SAASA,UAAU,QAAQ,kBAAkB;AAE7C,MAAMC,mBAAmB,CAACC;IACxB,OACE,OAAOA,WAAW,YAClBA,WAAW,QACX,UAAUA,UACV,UAAUA,UACV,OAAOA,OAAOC,IAAI,KAAK,YACvBD,OAAOC,IAAI,KAAK,QAChB,UAAUD,OAAOC,IAAI;AAEzB;AAEA,MAAMC,yBAAyB,CAACC;IAC9B,OACE,OAAOA,iBAAiB,YACxBA,iBAAiB,QACjB,cAAcA,gBACd,UAAUA,gBACV,OAAOA,aAAaF,IAAI,KAAK,YAC7BE,aAAaF,IAAI,KAAK,QACtB,aAAaE,aAAaF,IAAI,IAC9BG,MAAMC,OAAO,CAACF,aAAaF,IAAI,CAACK,OAAO,KACvCH,aAAaF,IAAI,CAACK,OAAO,CAACC,KAAK,CAACR;AAEpC;AAoBA,MAAMS,2BAA2B;AACjC,MAAMC,8BAA8B;AAEpC,MAAMC,iBAAiB,CAACC;IACtB,IAAIA,YAAYC,WAAW;QACzB,OAAO;YACLC,gBAAgBL;YAChBM,mBAAmBL;QACrB;IACF;IAEA,OAAO;QACLI,gBAAgB,GAAGF,SAASI,aAAa,KAAKP,0BAA0B;QACxEM,mBAAmB,GAAGH,SAASK,WAAW,KAAKP,6BAA6B;IAC9E;AACF;AAEA;;;CAGC,GACD,OAAO,SAASQ,mBAAmBN,OAAmC;IACpE,MAAM,EAAEE,cAAc,EAAEC,iBAAiB,EAAE,GAAGJ,eAAeC;IAE7D,OAAO;QACLO,qBAAqB;YACnB,MAAMC,kBAAkB,MAAMC,MAAMP;YAEpC,MAAMP,UAAU,MAAMa,gBAAgBE,IAAI;YAE1C,IAAIC,gBAAwC,EAAE;YAE9C,IAAIlB,MAAMC,OAAO,CAACC,UAAU;gBAC1BgB,gBAAgBhB,QAAQiB,MAAM,CAACrB;YACjC,OAAO;gBACLsB,QAAQC,KAAK,CAAC;YAChB;YAEA,IAAI,CAACH,cAAcI,MAAM,EAAE;gBACzBF,QAAQC,KAAK,CAAC;YAChB;YAEA,OAAOH;QACT;QACAK,oBAAoB,OAAOC;YACzB,MAAMC,mBAAmBD,SAASE,QAAQ,CAACC,IAAI;YAE/C,MAAM5B,eAAmC,CAAC;YAE1C,KAAK,MAAMH,UAAU4B,SAAS3B,IAAI,CAACK,OAAO,CAAE;gBAC1C,MAAM0B,qBAAqB,MAAMlC,WAAW+B,kBAAkB7B,OAAOC,IAAI,CAAC8B,IAAI,EAAEjB;gBAEhF,MAAMmB,eAAeD,oBAAoB,CAAChC,OAAOC,IAAI,CAAC8B,IAAI,CAAC;gBAC3D,IAAIE,cAAc;oBAChB9B,YAAY,CAACH,OAAOC,IAAI,CAAC8B,IAAI,CAAC,GAAGE;gBACnC,OAAO;oBACLT,QAAQC,KAAK,CAAC,CAAC,yCAAyC,EAAEzB,OAAOC,IAAI,CAAC8B,IAAI,EAAE;gBAC9E;YACF;YAEA,OAAO5B;QACT;IACF;AACF"}
1
+ {"version":3,"sources":["../../src/remote/remotePluginLoader.ts"],"sourcesContent":["// Copyright 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 PluginLoader,\n PluginMetadata,\n PluginModuleResource,\n PluginType,\n getPluginModuleCompoundKey,\n} from '@perses-dev/plugin-system';\nimport { RemotePluginModule } from './PersesPlugin.types';\nimport { loadPlugin } from './PluginRuntime';\n\nconst isPluginMetadata = (plugin: unknown): plugin is PluginMetadata => {\n return (\n typeof plugin === 'object' &&\n plugin !== null &&\n 'kind' in plugin &&\n 'spec' in plugin &&\n typeof plugin.spec === 'object' &&\n plugin.spec !== null &&\n 'name' in plugin.spec\n );\n};\n\nconst isPluginModuleResource = (pluginModule: unknown): pluginModule is PluginModuleResource => {\n return (\n typeof pluginModule === 'object' &&\n pluginModule !== null &&\n 'metadata' in pluginModule &&\n 'spec' in pluginModule &&\n typeof pluginModule.spec === 'object' &&\n pluginModule.spec !== null &&\n 'plugins' in pluginModule.spec &&\n Array.isArray(pluginModule.spec.plugins) &&\n pluginModule.spec.plugins.every(isPluginMetadata)\n );\n};\n\ntype RemotePluginLoaderOptions = {\n /**\n * The API path for fetching available Perses plugins. Used to construct the full URL to the `/api/v1/plugins` endpoint.\n * @default ''\n **/\n apiPrefix?: string;\n /**\n * The base URL for loading plugin assets (e.g., JavaScript files). Used to construct the full URL to the `/plugins` directory\n * @default ''\n **/\n baseURL?: string;\n};\n\ntype ParsedPluginOptions = {\n pluginsApiPath: string;\n pluginsAssetsPath: string;\n};\n\nconst DEFAULT_PLUGINS_API_PATH = '/api/v1/plugins';\nconst DEFAULT_PLUGINS_ASSETS_PATH = '/plugins';\n\nconst paramToOptions = (options?: RemotePluginLoaderOptions): ParsedPluginOptions => {\n if (options === undefined) {\n return {\n pluginsApiPath: DEFAULT_PLUGINS_API_PATH,\n pluginsAssetsPath: DEFAULT_PLUGINS_ASSETS_PATH,\n };\n }\n\n return {\n pluginsApiPath: `${options?.apiPrefix ?? ''}${DEFAULT_PLUGINS_API_PATH}`,\n pluginsAssetsPath: `${options?.baseURL ?? ''}${DEFAULT_PLUGINS_ASSETS_PATH}`,\n };\n};\n\n/**\n * Get a PluginLoader that fetches the list of installed plugins from a remote server and loads them as needed.\n * @param options - Optional configuration options for the remote plugin loader.\n */\nexport function remotePluginLoader(options?: RemotePluginLoaderOptions): PluginLoader {\n const { pluginsApiPath, pluginsAssetsPath } = paramToOptions(options);\n\n return {\n getInstalledPlugins: async (): Promise<PluginModuleResource[]> => {\n const pluginsResponse = await fetch(pluginsApiPath);\n\n const plugins = await pluginsResponse.json();\n let pluginModules: PluginModuleResource[] = [];\n\n if (Array.isArray(plugins)) {\n pluginModules = plugins.filter(isPluginModuleResource);\n } else {\n console.error('RemotePluginLoader: Error loading plugins, response is not an array');\n }\n\n if (!pluginModules.length) {\n console.error('RemotePluginLoader: No valid plugins found');\n }\n\n return pluginModules;\n },\n importPluginModule: async (resource): Promise<RemotePluginModule> => {\n const { name: pluginModuleName, version, registry } = resource.metadata;\n\n const pluginModule: RemotePluginModule = {};\n\n const loadPromises = resource.spec.plugins.map(async (plugin) => {\n const remotePluginModule = await loadPlugin({\n moduleName: pluginModuleName,\n pluginName: plugin.spec.name,\n registry,\n version,\n baseURL: pluginsAssetsPath,\n });\n\n const remotePlugin = remotePluginModule?.[plugin.spec.name];\n if (remotePlugin) {\n return { kind: plugin.kind as PluginType, name: plugin.spec.name, remotePlugin };\n } else {\n console.error(`RemotePluginLoader: Error loading plugin ${plugin.spec.name}`);\n return null;\n }\n });\n\n const loadedPlugins = await Promise.all(loadPromises);\n\n loadedPlugins.forEach((item) => {\n if (item?.remotePlugin) {\n pluginModule[getPluginModuleCompoundKey({ kind: item.kind, name: item.name, registry, version })] =\n item.remotePlugin;\n }\n });\n\n return pluginModule;\n },\n };\n}\n"],"names":["getPluginModuleCompoundKey","loadPlugin","isPluginMetadata","plugin","spec","isPluginModuleResource","pluginModule","Array","isArray","plugins","every","DEFAULT_PLUGINS_API_PATH","DEFAULT_PLUGINS_ASSETS_PATH","paramToOptions","options","undefined","pluginsApiPath","pluginsAssetsPath","apiPrefix","baseURL","remotePluginLoader","getInstalledPlugins","pluginsResponse","fetch","json","pluginModules","filter","console","error","length","importPluginModule","resource","name","pluginModuleName","version","registry","metadata","loadPromises","map","remotePluginModule","moduleName","pluginName","remotePlugin","kind","loadedPlugins","Promise","all","forEach","item"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAKEA,0BAA0B,QACrB,4BAA4B;AAEnC,SAASC,UAAU,QAAQ,kBAAkB;AAE7C,MAAMC,mBAAmB,CAACC;IACxB,OACE,OAAOA,WAAW,YAClBA,WAAW,QACX,UAAUA,UACV,UAAUA,UACV,OAAOA,OAAOC,IAAI,KAAK,YACvBD,OAAOC,IAAI,KAAK,QAChB,UAAUD,OAAOC,IAAI;AAEzB;AAEA,MAAMC,yBAAyB,CAACC;IAC9B,OACE,OAAOA,iBAAiB,YACxBA,iBAAiB,QACjB,cAAcA,gBACd,UAAUA,gBACV,OAAOA,aAAaF,IAAI,KAAK,YAC7BE,aAAaF,IAAI,KAAK,QACtB,aAAaE,aAAaF,IAAI,IAC9BG,MAAMC,OAAO,CAACF,aAAaF,IAAI,CAACK,OAAO,KACvCH,aAAaF,IAAI,CAACK,OAAO,CAACC,KAAK,CAACR;AAEpC;AAoBA,MAAMS,2BAA2B;AACjC,MAAMC,8BAA8B;AAEpC,MAAMC,iBAAiB,CAACC;IACtB,IAAIA,YAAYC,WAAW;QACzB,OAAO;YACLC,gBAAgBL;YAChBM,mBAAmBL;QACrB;IACF;IAEA,OAAO;QACLI,gBAAgB,GAAGF,SAASI,aAAa,KAAKP,0BAA0B;QACxEM,mBAAmB,GAAGH,SAASK,WAAW,KAAKP,6BAA6B;IAC9E;AACF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,IAAIA,MAAMN,cAAc;oBACtBpC,YAAY,CAACN,2BAA2B;wBAAE2C,MAAMK,KAAKL,IAAI;wBAAEX,MAAMgB,KAAKhB,IAAI;wBAAEG;wBAAUD;oBAAQ,GAAG,GAC/Fc,KAAKN,YAAY;gBACrB;YACF;YAEA,OAAOpC;QACT;IACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"DataQueriesProvider.d.ts","sourceRoot":"","sources":["../../../src/runtime/DataQueriesProvider/DataQueriesProvider.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAiB,YAAY,EAAoC,MAAM,OAAO,CAAC;AACtF,OAAO,EAAE,SAAS,EAA6B,MAAM,kBAAkB,CAAC;AAOxE,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EAEnB,sBAAsB,EAGvB,MAAM,SAAS,CAAC;AAEjB,eAAO,MAAM,kBAAkB,6DAA+D,CAAC;AAE/F,wBAAgB,qBAAqB,IAAI,sBAAsB,CAM9D;AAED,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,SAAS,EAAE,SAAS,EAAE,CAAC,GAAG,mBAAmB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAqBzG;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,GAAG,YAAY,CAsFjF"}
1
+ {"version":3,"file":"DataQueriesProvider.d.ts","sourceRoot":"","sources":["../../../src/runtime/DataQueriesProvider/DataQueriesProvider.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAiB,YAAY,EAAoC,MAAM,OAAO,CAAC;AACtF,OAAO,EAAE,SAAS,EAA6B,MAAM,kBAAkB,CAAC;AASxE,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EAEnB,sBAAsB,EAEvB,MAAM,SAAS,CAAC;AAEjB,eAAO,MAAM,kBAAkB,6DAA+D,CAAC;AAE/F,wBAAgB,qBAAqB,IAAI,sBAAsB,CAM9D;AAED,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,SAAS,EAAE,SAAS,EAAE,CAAC,GAAG,mBAAmB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAuBzG;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,GAAG,YAAY,CA2FjF"}
@@ -1,3 +1,4 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
1
2
  // Copyright The Perses Authors
2
3
  // Licensed under the Apache License, Version 2.0 (the "License");
3
4
  // you may not use this file except in compliance with the License.
@@ -10,14 +11,15 @@
10
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
12
  // See the License for the specific language governing permissions and
12
13
  // limitations under the License.
13
- import { jsx as _jsx } from "react/jsx-runtime";
14
14
  import { createContext, useCallback, useContext, useMemo } from 'react';
15
15
  import { useTimeSeriesQueries } from '../time-series-queries';
16
16
  import { useTraceQueries } from '../trace-queries';
17
17
  import { useProfileQueries } from '../profile-queries';
18
+ import { useAlertsQueries } from '../alerts-queries';
19
+ import { useSilencesQueries } from '../silences-queries';
18
20
  import { useUsageMetrics } from '../UsageMetricsProvider';
19
21
  import { useLogQueries } from '../log-queries';
20
- import { transformQueryResults, useQueryType } from './model';
22
+ import { transformQueryResults } from './model';
21
23
  export const DataQueriesContext = /*#__PURE__*/ createContext(undefined);
22
24
  export function useDataQueriesContext() {
23
25
  const ctx = useContext(DataQueriesContext);
@@ -28,60 +30,61 @@ export function useDataQueriesContext() {
28
30
  }
29
31
  export function useDataQueries(queryType) {
30
32
  const ctx = useDataQueriesContext();
33
+ // Filter query definitions based on the specified query type
34
+ const filteredQueryDefinitions = ctx.queryDefinitions.filter((definition)=>definition.kind === queryType);
31
35
  // Filter the query results based on the specified query type
32
36
  const filteredQueryResults = ctx.queryResults.filter((queryResult)=>queryResult?.definition?.kind === queryType);
33
37
  // Filter the errors based on the specified query type
34
38
  const filteredErrors = ctx.errors.filter((errors, index)=>ctx.queryResults[index]?.definition?.kind === queryType);
35
39
  // Create a new context object with the filtered results and errors
36
- const filteredCtx = {
40
+ return {
41
+ queryDefinitions: filteredQueryDefinitions,
37
42
  queryResults: filteredQueryResults,
38
43
  isFetching: filteredQueryResults.some((result)=>result.isFetching),
39
44
  isLoading: filteredQueryResults.some((result)=>result.isLoading),
40
45
  refetchAll: ctx.refetchAll,
41
46
  errors: filteredErrors
42
47
  };
43
- return filteredCtx;
44
48
  }
45
49
  export function DataQueriesProvider(props) {
46
50
  const { definitions, options, children, queryOptions } = props;
47
- // Returns a query kind, for example "TimeSeriesQuery" = getQueryType("PrometheusTimeSeriesQuery")
48
- const getQueryType = useQueryType();
49
- const queryDefinitions = definitions.map((definition)=>{
50
- const type = getQueryType(definition.kind);
51
- return {
52
- kind: type,
53
- spec: {
54
- plugin: definition
55
- }
56
- };
57
- });
58
51
  const usageMetrics = useUsageMetrics();
59
52
  // Filter definitions for time series query and other future query plugins
60
- const timeSeriesQueries = queryDefinitions.filter((definition)=>definition.kind === 'TimeSeriesQuery');
53
+ const timeSeriesQueries = definitions.filter((definition)=>definition.kind === 'TimeSeriesQuery');
61
54
  const timeSeriesResults = useTimeSeriesQueries(timeSeriesQueries, options, queryOptions);
62
- const traceQueries = queryDefinitions.filter((definition)=>definition.kind === 'TraceQuery');
55
+ const traceQueries = definitions.filter((definition)=>definition.kind === 'TraceQuery');
63
56
  const traceResults = useTraceQueries(traceQueries);
64
- const profileQueries = queryDefinitions.filter((definition)=>definition.kind === 'ProfileQuery');
57
+ const profileQueries = definitions.filter((definition)=>definition.kind === 'ProfileQuery');
65
58
  const profileResults = useProfileQueries(profileQueries);
66
- const logQueries = queryDefinitions.filter((definition)=>definition.kind === 'LogQuery');
59
+ const logQueries = definitions.filter((definition)=>definition.kind === 'LogQuery');
67
60
  const logResults = useLogQueries(logQueries);
61
+ const alertsQueries = definitions.filter((definition)=>definition.kind === 'AlertsQuery');
62
+ const alertsResults = useAlertsQueries(alertsQueries);
63
+ const silencesQueries = definitions.filter((definition)=>definition.kind === 'SilencesQuery');
64
+ const silencesResults = useSilencesQueries(silencesQueries);
68
65
  const refetchAll = useCallback(()=>{
69
66
  timeSeriesResults.forEach((result)=>result.refetch());
70
67
  traceResults.forEach((result)=>result.refetch());
71
68
  profileResults.forEach((result)=>result.refetch());
72
69
  logResults.forEach((result)=>result.refetch());
70
+ alertsResults.forEach((result)=>result.refetch());
71
+ silencesResults.forEach((result)=>result.refetch());
73
72
  }, [
74
73
  timeSeriesResults,
75
74
  traceResults,
76
75
  profileResults,
77
- logResults
76
+ logResults,
77
+ alertsResults,
78
+ silencesResults
78
79
  ]);
79
80
  const ctx = useMemo(()=>{
80
81
  const mergedQueryResults = [
81
82
  ...transformQueryResults(timeSeriesResults, timeSeriesQueries),
82
83
  ...transformQueryResults(traceResults, traceQueries),
83
84
  ...transformQueryResults(profileResults, profileQueries),
84
- ...transformQueryResults(logResults, logQueries)
85
+ ...transformQueryResults(logResults, logQueries),
86
+ ...transformQueryResults(alertsResults, alertsQueries),
87
+ ...transformQueryResults(silencesResults, silencesQueries)
85
88
  ];
86
89
  if (queryOptions?.enabled) {
87
90
  for (const result of mergedQueryResults){
@@ -95,6 +98,7 @@ export function DataQueriesProvider(props) {
95
98
  }
96
99
  }
97
100
  return {
101
+ queryDefinitions: definitions,
98
102
  queryResults: mergedQueryResults,
99
103
  isFetching: mergedQueryResults.some((result)=>result.isFetching),
100
104
  isLoading: mergedQueryResults.some((result)=>result.isLoading),
@@ -102,16 +106,21 @@ export function DataQueriesProvider(props) {
102
106
  errors: mergedQueryResults.map((result)=>result.error)
103
107
  };
104
108
  }, [
109
+ alertsQueries,
110
+ alertsResults,
111
+ logQueries,
112
+ logResults,
113
+ profileQueries,
114
+ profileResults,
115
+ silencesQueries,
116
+ silencesResults,
105
117
  timeSeriesQueries,
106
118
  timeSeriesResults,
107
119
  traceQueries,
108
120
  traceResults,
109
- profileQueries,
110
- profileResults,
111
- logQueries,
112
- logResults,
113
- refetchAll,
121
+ definitions,
114
122
  queryOptions?.enabled,
123
+ refetchAll,
115
124
  usageMetrics
116
125
  ]);
117
126
  return /*#__PURE__*/ _jsx(DataQueriesContext.Provider, {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/runtime/DataQueriesProvider/DataQueriesProvider.tsx"],"sourcesContent":["// Copyright 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, ReactElement, useCallback, useContext, useMemo } from 'react';\nimport { QueryType, TimeSeriesQueryDefinition } from '@perses-dev/spec';\nimport { useTimeSeriesQueries } from '../time-series-queries';\nimport { useTraceQueries, TraceQueryDefinition } from '../trace-queries';\nimport { useProfileQueries, ProfileQueryDefinition } from '../profile-queries';\n\nimport { useUsageMetrics } from '../UsageMetricsProvider';\nimport { LogQueryDefinition, useLogQueries } from '../log-queries';\nimport {\n DataQueriesProviderProps,\n UseDataQueryResults,\n transformQueryResults,\n DataQueriesContextType,\n QueryData,\n useQueryType,\n} from './model';\n\nexport const DataQueriesContext = createContext<DataQueriesContextType | undefined>(undefined);\n\nexport function useDataQueriesContext(): DataQueriesContextType {\n const ctx = useContext(DataQueriesContext);\n if (ctx === undefined) {\n throw new Error('No DataQueriesContext found. Did you forget a Provider?');\n }\n return ctx;\n}\n\nexport function useDataQueries<T extends keyof QueryType>(queryType: T): UseDataQueryResults<QueryType[T]> {\n const ctx = useDataQueriesContext();\n\n // Filter the query results based on the specified query type\n const filteredQueryResults = ctx.queryResults.filter(\n (queryResult) => queryResult?.definition?.kind === queryType\n ) as Array<QueryData<QueryType[T]>>;\n\n // Filter the errors based on the specified query type\n const filteredErrors = ctx.errors.filter((errors, index) => ctx.queryResults[index]?.definition?.kind === queryType);\n\n // Create a new context object with the filtered results and errors\n const filteredCtx = {\n queryResults: filteredQueryResults,\n isFetching: filteredQueryResults.some((result) => result.isFetching),\n isLoading: filteredQueryResults.some((result) => result.isLoading),\n refetchAll: ctx.refetchAll,\n errors: filteredErrors,\n };\n\n return filteredCtx;\n}\n\nexport function DataQueriesProvider(props: DataQueriesProviderProps): ReactElement {\n const { definitions, options, children, queryOptions } = props;\n\n // Returns a query kind, for example \"TimeSeriesQuery\" = getQueryType(\"PrometheusTimeSeriesQuery\")\n const getQueryType = useQueryType();\n\n const queryDefinitions = definitions.map((definition) => {\n const type = getQueryType(definition.kind);\n return {\n kind: type,\n spec: {\n plugin: definition,\n },\n };\n });\n\n const usageMetrics = useUsageMetrics();\n\n // Filter definitions for time series query and other future query plugins\n const timeSeriesQueries = queryDefinitions.filter(\n (definition) => definition.kind === 'TimeSeriesQuery'\n ) as TimeSeriesQueryDefinition[];\n const timeSeriesResults = useTimeSeriesQueries(timeSeriesQueries, options, queryOptions);\n\n const traceQueries = queryDefinitions.filter(\n (definition) => definition.kind === 'TraceQuery'\n ) as TraceQueryDefinition[];\n const traceResults = useTraceQueries(traceQueries);\n\n const profileQueries = queryDefinitions.filter(\n (definition) => definition.kind === 'ProfileQuery'\n ) as ProfileQueryDefinition[];\n const profileResults = useProfileQueries(profileQueries);\n\n const logQueries = queryDefinitions.filter((definition) => definition.kind === 'LogQuery') as LogQueryDefinition[];\n const logResults = useLogQueries(logQueries);\n\n const refetchAll = useCallback(() => {\n timeSeriesResults.forEach((result) => result.refetch());\n traceResults.forEach((result) => result.refetch());\n profileResults.forEach((result) => result.refetch());\n logResults.forEach((result) => result.refetch());\n }, [timeSeriesResults, traceResults, profileResults, logResults]);\n\n const ctx = useMemo(() => {\n const mergedQueryResults = [\n ...transformQueryResults(timeSeriesResults, timeSeriesQueries),\n ...transformQueryResults(traceResults, traceQueries),\n ...transformQueryResults(profileResults, profileQueries),\n ...transformQueryResults(logResults, logQueries),\n ];\n\n if (queryOptions?.enabled) {\n for (const result of mergedQueryResults) {\n if (!result.isLoading && !result.isFetching && !result.error) {\n usageMetrics.markQuery(result.definition, 'success');\n } else if (result.error) {\n usageMetrics.markQuery(result.definition, 'error');\n } else {\n usageMetrics.markQuery(result.definition, 'pending');\n }\n }\n }\n\n return {\n queryResults: mergedQueryResults,\n isFetching: mergedQueryResults.some((result) => result.isFetching),\n isLoading: mergedQueryResults.some((result) => result.isLoading),\n refetchAll,\n errors: mergedQueryResults.map((result) => result.error),\n };\n }, [\n timeSeriesQueries,\n timeSeriesResults,\n traceQueries,\n traceResults,\n profileQueries,\n profileResults,\n logQueries,\n logResults,\n refetchAll,\n queryOptions?.enabled,\n usageMetrics,\n ]);\n\n return <DataQueriesContext.Provider value={ctx}>{children}</DataQueriesContext.Provider>;\n}\n"],"names":["createContext","useCallback","useContext","useMemo","useTimeSeriesQueries","useTraceQueries","useProfileQueries","useUsageMetrics","useLogQueries","transformQueryResults","useQueryType","DataQueriesContext","undefined","useDataQueriesContext","ctx","Error","useDataQueries","queryType","filteredQueryResults","queryResults","filter","queryResult","definition","kind","filteredErrors","errors","index","filteredCtx","isFetching","some","result","isLoading","refetchAll","DataQueriesProvider","props","definitions","options","children","queryOptions","getQueryType","queryDefinitions","map","type","spec","plugin","usageMetrics","timeSeriesQueries","timeSeriesResults","traceQueries","traceResults","profileQueries","profileResults","logQueries","logResults","forEach","refetch","mergedQueryResults","enabled","error","markQuery","Provider","value"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,aAAa,EAAgBC,WAAW,EAAEC,UAAU,EAAEC,OAAO,QAAQ,QAAQ;AAEtF,SAASC,oBAAoB,QAAQ,yBAAyB;AAC9D,SAASC,eAAe,QAA8B,mBAAmB;AACzE,SAASC,iBAAiB,QAAgC,qBAAqB;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,OAAOR,UAAU,EAAE;gBAC5C;YACF;QACF;QAEA,OAAO;YACLH,cAAcqC;YACd5B,YAAY4B,mBAAmB3B,IAAI,CAAC,CAACC,SAAWA,OAAOF,UAAU;YACjEG,WAAWyB,mBAAmB3B,IAAI,CAAC,CAACC,SAAWA,OAAOC,SAAS;YAC/DC;YACAP,QAAQ+B,mBAAmBf,GAAG,CAAC,CAACX,SAAWA,OAAO4B,KAAK;QACzD;IACF,GAAG;QACDZ;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACArB;QACAM,cAAcmB;QACdZ;KACD;IAED,qBAAO,KAAClC,mBAAmBiD,QAAQ;QAACC,OAAO/C;kBAAMuB;;AACnD"}
1
+ {"version":3,"sources":["../../../src/runtime/DataQueriesProvider/DataQueriesProvider.tsx"],"sourcesContent":["// Copyright 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, ReactElement, useCallback, useContext, useMemo } from 'react';\nimport { QueryType, TimeSeriesQueryDefinition } from '@perses-dev/spec';\nimport { useTimeSeriesQueries } from '../time-series-queries';\nimport { useTraceQueries, TraceQueryDefinition } from '../trace-queries';\nimport { useProfileQueries, ProfileQueryDefinition } from '../profile-queries';\nimport { useAlertsQueries, AlertsQueryDefinition } from '../alerts-queries';\nimport { useSilencesQueries, SilencesQueryDefinition } from '../silences-queries';\n\nimport { useUsageMetrics } from '../UsageMetricsProvider';\nimport { LogQueryDefinition, useLogQueries } from '../log-queries';\nimport {\n DataQueriesProviderProps,\n UseDataQueryResults,\n transformQueryResults,\n DataQueriesContextType,\n QueryData,\n} from './model';\n\nexport const DataQueriesContext = createContext<DataQueriesContextType | undefined>(undefined);\n\nexport function useDataQueriesContext(): DataQueriesContextType {\n const ctx = useContext(DataQueriesContext);\n if (ctx === undefined) {\n throw new Error('No DataQueriesContext found. Did you forget a Provider?');\n }\n return ctx;\n}\n\nexport function useDataQueries<T extends keyof QueryType>(queryType: T): UseDataQueryResults<QueryType[T]> {\n const ctx = useDataQueriesContext();\n\n // Filter query definitions based on the specified query type\n const filteredQueryDefinitions = ctx.queryDefinitions.filter((definition) => definition.kind === queryType);\n\n // Filter the query results based on the specified query type\n const filteredQueryResults = ctx.queryResults.filter(\n (queryResult) => queryResult?.definition?.kind === queryType\n ) as Array<QueryData<QueryType[T]>>;\n\n // Filter the errors based on the specified query type\n const filteredErrors = ctx.errors.filter((errors, index) => ctx.queryResults[index]?.definition?.kind === queryType);\n\n // Create a new context object with the filtered results and errors\n return {\n queryDefinitions: filteredQueryDefinitions,\n queryResults: filteredQueryResults,\n isFetching: filteredQueryResults.some((result) => result.isFetching),\n isLoading: filteredQueryResults.some((result) => result.isLoading),\n refetchAll: ctx.refetchAll,\n errors: filteredErrors,\n };\n}\n\nexport function DataQueriesProvider(props: DataQueriesProviderProps): ReactElement {\n const { definitions, options, children, queryOptions } = props;\n\n const usageMetrics = useUsageMetrics();\n\n // Filter definitions for time series query and other future query plugins\n const timeSeriesQueries = definitions.filter(\n (definition) => definition.kind === 'TimeSeriesQuery'\n ) as TimeSeriesQueryDefinition[];\n const timeSeriesResults = useTimeSeriesQueries(timeSeriesQueries, options, queryOptions);\n\n const traceQueries = definitions.filter((definition) => definition.kind === 'TraceQuery') as TraceQueryDefinition[];\n const traceResults = useTraceQueries(traceQueries);\n\n const profileQueries = definitions.filter(\n (definition) => definition.kind === 'ProfileQuery'\n ) as ProfileQueryDefinition[];\n const profileResults = useProfileQueries(profileQueries);\n\n const logQueries = definitions.filter((definition) => definition.kind === 'LogQuery') as LogQueryDefinition[];\n const logResults = useLogQueries(logQueries);\n\n const alertsQueries = definitions.filter(\n (definition) => definition.kind === 'AlertsQuery'\n ) as AlertsQueryDefinition[];\n const alertsResults = useAlertsQueries(alertsQueries);\n\n const silencesQueries = definitions.filter(\n (definition) => definition.kind === 'SilencesQuery'\n ) as SilencesQueryDefinition[];\n const silencesResults = useSilencesQueries(silencesQueries);\n\n const refetchAll = useCallback(() => {\n timeSeriesResults.forEach((result) => result.refetch());\n traceResults.forEach((result) => result.refetch());\n profileResults.forEach((result) => result.refetch());\n logResults.forEach((result) => result.refetch());\n alertsResults.forEach((result) => result.refetch());\n silencesResults.forEach((result) => result.refetch());\n }, [timeSeriesResults, traceResults, profileResults, logResults, alertsResults, silencesResults]);\n\n const ctx = useMemo(() => {\n const mergedQueryResults = [\n ...transformQueryResults(timeSeriesResults, timeSeriesQueries),\n ...transformQueryResults(traceResults, traceQueries),\n ...transformQueryResults(profileResults, profileQueries),\n ...transformQueryResults(logResults, logQueries),\n ...transformQueryResults(alertsResults, alertsQueries),\n ...transformQueryResults(silencesResults, silencesQueries),\n ];\n\n if (queryOptions?.enabled) {\n for (const result of mergedQueryResults) {\n if (!result.isLoading && !result.isFetching && !result.error) {\n usageMetrics.markQuery(result.definition, 'success');\n } else if (result.error) {\n usageMetrics.markQuery(result.definition, 'error');\n } else {\n usageMetrics.markQuery(result.definition, 'pending');\n }\n }\n }\n\n return {\n queryDefinitions: definitions,\n queryResults: mergedQueryResults,\n isFetching: mergedQueryResults.some((result) => result.isFetching),\n isLoading: mergedQueryResults.some((result) => result.isLoading),\n refetchAll,\n errors: mergedQueryResults.map((result) => result.error),\n };\n }, [\n alertsQueries,\n alertsResults,\n logQueries,\n logResults,\n profileQueries,\n profileResults,\n silencesQueries,\n silencesResults,\n timeSeriesQueries,\n timeSeriesResults,\n traceQueries,\n traceResults,\n definitions,\n queryOptions?.enabled,\n refetchAll,\n usageMetrics,\n ]);\n\n return <DataQueriesContext.Provider value={ctx}>{children}</DataQueriesContext.Provider>;\n}\n"],"names":["createContext","useCallback","useContext","useMemo","useTimeSeriesQueries","useTraceQueries","useProfileQueries","useAlertsQueries","useSilencesQueries","useUsageMetrics","useLogQueries","transformQueryResults","DataQueriesContext","undefined","useDataQueriesContext","ctx","Error","useDataQueries","queryType","filteredQueryDefinitions","queryDefinitions","filter","definition","kind","filteredQueryResults","queryResults","queryResult","filteredErrors","errors","index","isFetching","some","result","isLoading","refetchAll","DataQueriesProvider","props","definitions","options","children","queryOptions","usageMetrics","timeSeriesQueries","timeSeriesResults","traceQueries","traceResults","profileQueries","profileResults","logQueries","logResults","alertsQueries","alertsResults","silencesQueries","silencesResults","forEach","refetch","mergedQueryResults","enabled","error","markQuery","map","Provider","value"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,aAAa,EAAgBC,WAAW,EAAEC,UAAU,EAAEC,OAAO,QAAQ,QAAQ;AAEtF,SAASC,oBAAoB,QAAQ,yBAAyB;AAC9D,SAASC,eAAe,QAA8B,mBAAmB;AACzE,SAASC,iBAAiB,QAAgC,qBAAqB;AAC/E,SAASC,gBAAgB,QAA+B,oBAAoB;AAC5E,SAASC,kBAAkB,QAAiC,sBAAsB;AAElF,SAASC,eAAe,QAAQ,0BAA0B;AAC1D,SAA6BC,aAAa,QAAQ,iBAAiB;AACnE,SAGEC,qBAAqB,QAGhB,UAAU;AAEjB,OAAO,MAAMC,mCAAqBZ,cAAkDa,WAAW;AAE/F,OAAO,SAASC;IACd,MAAMC,MAAMb,WAAWU;IACvB,IAAIG,QAAQF,WAAW;QACrB,MAAM,IAAIG,MAAM;IAClB;IACA,OAAOD;AACT;AAEA,OAAO,SAASE,eAA0CC,SAAY;IACpE,MAAMH,MAAMD;IAEZ,6DAA6D;IAC7D,MAAMK,2BAA2BJ,IAAIK,gBAAgB,CAACC,MAAM,CAAC,CAACC,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IAAI,CAAC,CAACC,SAAWA,OAAOF,UAAU;YACjEG,WAAWuB,mBAAmBzB,IAAI,CAAC,CAACC,SAAWA,OAAOC,SAAS;YAC/DC;YACAN,QAAQ4B,mBAAmBI,GAAG,CAAC,CAAC5B,SAAWA,OAAO0B,KAAK;QACzD;IACF,GAAG;QACDR;QACAC;QACAH;QACAC;QACAH;QACAC;QACAK;QACAC;QACAX;QACAC;QACAC;QACAC;QACAR;QACAG,cAAciB;QACdvB;QACAO;KACD;IAED,qBAAO,KAAC7B,mBAAmBiD,QAAQ;QAACC,OAAO/C;kBAAMwB;;AACnD"}
@@ -1,14 +1,15 @@
1
- import { Definition, QueryDefinition, UnknownSpec, QueryDataType } from '@perses-dev/spec';
1
+ import { QueryDefinition, UnknownSpec, QueryDataType } from '@perses-dev/spec';
2
2
  import { QueryObserverOptions, UseQueryResult } from '@tanstack/react-query';
3
3
  import { ReactNode } from 'react';
4
4
  export type QueryOptions = Record<string, unknown>;
5
- export interface DataQueriesProviderProps<QueryPluginSpec = UnknownSpec> {
6
- definitions: Array<Definition<QueryPluginSpec>>;
5
+ export interface DataQueriesProviderProps<Kind = unknown, PluginSpec = UnknownSpec> {
6
+ definitions: Array<QueryDefinition<Kind, PluginSpec>>;
7
7
  children?: ReactNode;
8
8
  options?: QueryOptions;
9
9
  queryOptions?: Omit<QueryObserverOptions, 'queryKey'>;
10
10
  }
11
11
  export interface DataQueriesContextType {
12
+ queryDefinitions: QueryDefinition[];
12
13
  queryResults: QueryData[];
13
14
  refetchAll: () => void;
14
15
  isFetching: boolean;
@@ -27,5 +28,4 @@ export type QueryData<T = QueryDataType> = {
27
28
  refetch?: () => void;
28
29
  };
29
30
  export declare function transformQueryResults(results: UseQueryResult[], definitions: QueryDefinition[]): QueryData[];
30
- export declare function useQueryType(): (pluginKind: string) => string | undefined;
31
31
  //# sourceMappingURL=model.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/runtime/DataQue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