@perses-dev/plugin-system 0.50.0 → 0.51.0-beta.0

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 (180) hide show
  1. package/dist/cjs/components/DatasourceEditorForm/DatasourceEditorForm.js +17 -71
  2. package/dist/cjs/components/DatasourceSelect.js +8 -13
  3. package/dist/cjs/components/HTTPSettingsEditor/HTTPSettingsEditor.js +534 -0
  4. package/dist/cjs/components/HTTPSettingsEditor/index.js +30 -0
  5. package/dist/cjs/components/LegendOptionsEditor/LegendOptionsEditor.js +4 -4
  6. package/dist/cjs/components/MetricLabelInput/MetricLabelInput.js +41 -0
  7. package/dist/cjs/components/MetricLabelInput/index.js +30 -0
  8. package/dist/cjs/components/MultiQueryEditor/MultiQueryEditor.js +15 -14
  9. package/dist/cjs/components/PanelSpecEditor/PanelSpecEditor.js +7 -11
  10. package/dist/cjs/components/PluginEditor/PluginEditor.js +10 -6
  11. package/dist/cjs/components/PluginEditor/plugin-editor-api.js +4 -5
  12. package/dist/cjs/components/PluginKindSelect/PluginKindSelect.js +7 -8
  13. package/dist/cjs/components/PluginRegistry/PluginRegistry.js +7 -10
  14. package/dist/cjs/components/PluginRegistry/plugin-indexes.js +17 -14
  15. package/dist/cjs/components/ProjectSelect.js +2 -3
  16. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +46 -92
  17. package/dist/cjs/components/Variables/VariableEditorForm/VariablePreview.js +6 -6
  18. package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +6 -11
  19. package/dist/cjs/components/Variables/variable-model.js +4 -7
  20. package/dist/cjs/components/index.js +2 -0
  21. package/dist/cjs/index.js +1 -0
  22. package/dist/cjs/model/explore.js +16 -0
  23. package/dist/cjs/remote/PersesPlugin.types.js +16 -0
  24. package/dist/cjs/remote/PluginLoaderComponent.js +75 -0
  25. package/dist/cjs/remote/PluginRuntime.js +267 -0
  26. package/dist/cjs/remote/index.js +31 -0
  27. package/dist/cjs/remote/remotePluginLoader.js +61 -0
  28. package/dist/cjs/runtime/DataQueriesProvider/DataQueriesProvider.js +4 -10
  29. package/dist/cjs/runtime/DataQueriesProvider/model.js +4 -7
  30. package/dist/cjs/runtime/TimeRangeProvider/TimeRangeProvider.js +2 -2
  31. package/dist/cjs/runtime/builtin-variables.js +1 -1
  32. package/dist/cjs/runtime/datasources.js +3 -3
  33. package/dist/cjs/runtime/plugin-registry.js +5 -6
  34. package/dist/cjs/runtime/time-series-queries.js +11 -18
  35. package/dist/cjs/runtime/trace-queries.js +1 -2
  36. package/dist/cjs/runtime/variables.js +10 -28
  37. package/dist/cjs/stories/shared-utils/decorators/WithDataQueries.js +1 -1
  38. package/dist/cjs/stories/shared-utils/decorators/WithPluginRegistry.js +1 -67
  39. package/dist/cjs/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.js +1 -1
  40. package/dist/cjs/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.js +4 -4
  41. package/dist/cjs/stories/shared-utils/decorators/WithPluginSystemVariables.js +1 -1
  42. package/dist/cjs/stories/shared-utils/decorators/WithTimeRange.js +1 -1
  43. package/dist/cjs/test/render.js +1 -2
  44. package/dist/cjs/test-utils/mock-plugin-registry.js +10 -10
  45. package/dist/cjs/utils/variables.js +1 -1
  46. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts.map +1 -1
  47. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js +17 -30
  48. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js.map +1 -1
  49. package/dist/components/DatasourceSelect.d.ts +2 -2
  50. package/dist/components/DatasourceSelect.d.ts.map +1 -1
  51. package/dist/components/DatasourceSelect.js +8 -13
  52. package/dist/components/DatasourceSelect.js.map +1 -1
  53. package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.d.ts +11 -0
  54. package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.d.ts.map +1 -0
  55. package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.js +480 -0
  56. package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.js.map +1 -0
  57. package/dist/components/HTTPSettingsEditor/index.d.ts +2 -0
  58. package/dist/components/HTTPSettingsEditor/index.d.ts.map +1 -0
  59. package/dist/components/HTTPSettingsEditor/index.js +15 -0
  60. package/dist/components/HTTPSettingsEditor/index.js.map +1 -0
  61. package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js +4 -4
  62. package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js.map +1 -1
  63. package/dist/components/MetricLabelInput/MetricLabelInput.d.ts +7 -0
  64. package/dist/components/MetricLabelInput/MetricLabelInput.d.ts.map +1 -0
  65. package/dist/components/MetricLabelInput/MetricLabelInput.js +33 -0
  66. package/dist/components/MetricLabelInput/MetricLabelInput.js.map +1 -0
  67. package/dist/components/MetricLabelInput/index.d.ts +2 -0
  68. package/dist/components/MetricLabelInput/index.d.ts.map +1 -0
  69. package/dist/components/MetricLabelInput/index.js +15 -0
  70. package/dist/components/MetricLabelInput/index.js.map +1 -0
  71. package/dist/components/MultiQueryEditor/MultiQueryEditor.d.ts.map +1 -1
  72. package/dist/components/MultiQueryEditor/MultiQueryEditor.js +15 -14
  73. package/dist/components/MultiQueryEditor/MultiQueryEditor.js.map +1 -1
  74. package/dist/components/PanelSpecEditor/PanelSpecEditor.js +7 -11
  75. package/dist/components/PanelSpecEditor/PanelSpecEditor.js.map +1 -1
  76. package/dist/components/PluginEditor/PluginEditor.d.ts.map +1 -1
  77. package/dist/components/PluginEditor/PluginEditor.js +10 -6
  78. package/dist/components/PluginEditor/PluginEditor.js.map +1 -1
  79. package/dist/components/PluginEditor/plugin-editor-api.js +4 -5
  80. package/dist/components/PluginEditor/plugin-editor-api.js.map +1 -1
  81. package/dist/components/PluginKindSelect/PluginKindSelect.js +7 -8
  82. package/dist/components/PluginKindSelect/PluginKindSelect.js.map +1 -1
  83. package/dist/components/PluginRegistry/PluginRegistry.js +7 -10
  84. package/dist/components/PluginRegistry/PluginRegistry.js.map +1 -1
  85. package/dist/components/PluginRegistry/plugin-indexes.d.ts +4 -4
  86. package/dist/components/PluginRegistry/plugin-indexes.d.ts.map +1 -1
  87. package/dist/components/PluginRegistry/plugin-indexes.js +17 -14
  88. package/dist/components/PluginRegistry/plugin-indexes.js.map +1 -1
  89. package/dist/components/ProjectSelect.js +2 -3
  90. package/dist/components/ProjectSelect.js.map +1 -1
  91. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +46 -92
  92. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
  93. package/dist/components/Variables/VariableEditorForm/VariablePreview.js +6 -6
  94. package/dist/components/Variables/VariableEditorForm/VariablePreview.js.map +1 -1
  95. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +6 -11
  96. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -1
  97. package/dist/components/Variables/variable-model.js +4 -7
  98. package/dist/components/Variables/variable-model.js.map +1 -1
  99. package/dist/components/index.d.ts +2 -0
  100. package/dist/components/index.d.ts.map +1 -1
  101. package/dist/components/index.js +2 -0
  102. package/dist/components/index.js.map +1 -1
  103. package/dist/index.d.ts +1 -0
  104. package/dist/index.d.ts.map +1 -1
  105. package/dist/index.js +1 -0
  106. package/dist/index.js.map +1 -1
  107. package/dist/model/explore.d.ts +13 -0
  108. package/dist/model/explore.d.ts.map +1 -0
  109. package/dist/model/explore.js +17 -0
  110. package/dist/model/explore.js.map +1 -0
  111. package/dist/model/panels.d.ts +13 -3
  112. package/dist/model/panels.d.ts.map +1 -1
  113. package/dist/model/panels.js.map +1 -1
  114. package/dist/model/plugins.d.ts +31 -17
  115. package/dist/model/plugins.d.ts.map +1 -1
  116. package/dist/model/plugins.js.map +1 -1
  117. package/dist/remote/PersesPlugin.types.d.ts +7 -0
  118. package/dist/remote/PersesPlugin.types.d.ts.map +1 -0
  119. package/dist/remote/PersesPlugin.types.js +15 -0
  120. package/dist/remote/PersesPlugin.types.js.map +1 -0
  121. package/dist/remote/PluginLoaderComponent.d.ts +10 -0
  122. package/dist/remote/PluginLoaderComponent.d.ts.map +1 -0
  123. package/dist/remote/PluginLoaderComponent.js +67 -0
  124. package/dist/remote/PluginLoaderComponent.js.map +1 -0
  125. package/dist/remote/PluginRuntime.d.ts +11 -0
  126. package/dist/remote/PluginRuntime.d.ts.map +1 -0
  127. package/dist/remote/PluginRuntime.js +202 -0
  128. package/dist/remote/PluginRuntime.js.map +1 -0
  129. package/dist/remote/index.d.ts +3 -0
  130. package/dist/remote/index.d.ts.map +1 -0
  131. package/dist/remote/index.js +16 -0
  132. package/dist/remote/index.js.map +1 -0
  133. package/dist/remote/remotePluginLoader.d.ts +3 -0
  134. package/dist/remote/remotePluginLoader.d.ts.map +1 -0
  135. package/dist/remote/remotePluginLoader.js +53 -0
  136. package/dist/remote/remotePluginLoader.js.map +1 -0
  137. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js +4 -10
  138. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js.map +1 -1
  139. package/dist/runtime/DataQueriesProvider/model.d.ts.map +1 -1
  140. package/dist/runtime/DataQueriesProvider/model.js +4 -7
  141. package/dist/runtime/DataQueriesProvider/model.js.map +1 -1
  142. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js +2 -2
  143. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js.map +1 -1
  144. package/dist/runtime/builtin-variables.js +1 -1
  145. package/dist/runtime/builtin-variables.js.map +1 -1
  146. package/dist/runtime/datasources.d.ts +2 -2
  147. package/dist/runtime/datasources.js +3 -3
  148. package/dist/runtime/datasources.js.map +1 -1
  149. package/dist/runtime/plugin-registry.d.ts +6 -6
  150. package/dist/runtime/plugin-registry.d.ts.map +1 -1
  151. package/dist/runtime/plugin-registry.js +5 -6
  152. package/dist/runtime/plugin-registry.js.map +1 -1
  153. package/dist/runtime/time-series-queries.js +11 -18
  154. package/dist/runtime/time-series-queries.js.map +1 -1
  155. package/dist/runtime/trace-queries.js +1 -2
  156. package/dist/runtime/trace-queries.js.map +1 -1
  157. package/dist/runtime/variables.js +10 -28
  158. package/dist/runtime/variables.js.map +1 -1
  159. package/dist/stories/shared-utils/decorators/WithDataQueries.js +1 -1
  160. package/dist/stories/shared-utils/decorators/WithDataQueries.js.map +1 -1
  161. package/dist/stories/shared-utils/decorators/WithPluginRegistry.d.ts.map +1 -1
  162. package/dist/stories/shared-utils/decorators/WithPluginRegistry.js +2 -22
  163. package/dist/stories/shared-utils/decorators/WithPluginRegistry.js.map +1 -1
  164. package/dist/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.js +1 -1
  165. package/dist/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.js.map +1 -1
  166. package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.js +4 -4
  167. package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.js.map +1 -1
  168. package/dist/stories/shared-utils/decorators/WithPluginSystemVariables.js +1 -1
  169. package/dist/stories/shared-utils/decorators/WithPluginSystemVariables.js.map +1 -1
  170. package/dist/stories/shared-utils/decorators/WithTimeRange.js +1 -1
  171. package/dist/stories/shared-utils/decorators/WithTimeRange.js.map +1 -1
  172. package/dist/test/render.js +1 -2
  173. package/dist/test/render.js.map +1 -1
  174. package/dist/test-utils/mock-plugin-registry.d.ts +5 -3
  175. package/dist/test-utils/mock-plugin-registry.d.ts.map +1 -1
  176. package/dist/test-utils/mock-plugin-registry.js +10 -10
  177. package/dist/test-utils/mock-plugin-registry.js.map +1 -1
  178. package/dist/utils/variables.js +1 -1
  179. package/dist/utils/variables.js.map +1 -1
  180. package/package.json +6 -5
@@ -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, 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(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(): 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 datasourcePluginKind: string,\n project?: string\n): UseQueryResult<DatasourceSelectItemGroup[]> {\n const { listDatasourceSelectItems } = useDatasourceStore();\n return useQuery<DatasourceSelectItemGroup[]>({\n queryKey: ['listDatasourceSelectItems', datasourcePluginKind, project],\n queryFn: () => 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): 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","datasourcePluginKind","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
+ {"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,10 +1,10 @@
1
1
  /// <reference types="react" />
2
- import { UseQueryOptions, UseQueryResult } 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(pluginTypes: PluginType[]): Promise<PluginMetadata[]>;
6
+ getPlugin<T extends PluginType>(kind: T, name: string): Promise<PluginImplementation<T>>;
7
+ listPluginMetadata(pluginTypes: string[]): Promise<PluginMetadataWithModule[]>;
8
8
  defaultPluginKinds?: DefaultPluginKinds;
9
9
  }
10
10
  export declare const PluginRegistryContext: import("react").Context<PluginRegistryContextType | undefined>;
@@ -24,11 +24,11 @@ export declare function usePlugin<T extends PluginType>(pluginType: T | undefine
24
24
  export declare function usePlugins<T extends PluginType>(pluginType: T, plugins: Array<{
25
25
  kind: string;
26
26
  }>): Array<UseQueryResult<PluginImplementation<T>>>;
27
- type UseListPluginMetadataOptions = Omit<UseQueryOptions<PluginMetadata[], Error, PluginMetadata[], [string, PluginType[]]>, 'queryKey' | 'queryFn'>;
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(pluginTypes: PluginType[], options?: UseListPluginMetadataOptions): UseQueryResult<PluginMetadata[]>;
31
+ export declare function useListPluginMetadata(pluginTypes: string[], options?: UseListPluginMetadataOptions): UseQueryResult<PluginMetadataWithModule[]>;
32
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,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC9F,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,WAAW,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;IACzE,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;CACzC;AAED,eAAO,MAAM,qBAAqB,gEAAkE,CAAC;AAErG;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,yBAAyB,CAM7D;AAGD,KAAK,gBAAgB,CAAC,CAAC,SAAS,UAAU,IAAI,IAAI,CAChD,eAAe,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,GAAG,SAAS,EAAE,MAAM,CAAC,CAAC,EAClH,UAAU,GAAG,SAAS,CACvB,CAAC;AAEF;;GAEG;AACH,wBAAgB,SAAS,C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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,11 +26,10 @@ 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) && pluginType !== undefined && kind !== ''
32
+ enabled: (options?.enabled ?? true) && pluginType !== undefined && kind !== ''
34
33
  };
35
34
  const { getPlugin } = usePluginRegistry();
36
35
  return useQuery({
@@ -83,10 +82,10 @@ export function usePluginBuiltinVariableDefinitions() {
83
82
  const datasources = await listPluginMetadata([
84
83
  'Datasource'
85
84
  ]);
86
- const datasourceKinds = new Set(datasources.map((datasource)=>datasource.kind));
85
+ const datasourceNames = new Set(datasources.map((datasource)=>datasource.spec.name));
87
86
  const result = [];
88
- for (const kind of datasourceKinds){
89
- const plugin = await getPlugin('Datasource', kind);
87
+ for (const name of datasourceNames){
88
+ const plugin = await getPlugin('Datasource', name);
90
89
  if (plugin.getBuiltinVariableDefinitions) {
91
90
  plugin.getBuiltinVariableDefinitions().forEach((definition)=>result.push(definition));
92
91
  }
@@ -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, UseQueryResult } 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(pluginTypes: 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(): 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<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(\n pluginTypes: PluginType[],\n options?: UseListPluginMetadataOptions\n): UseQueryResult<PluginMetadata[]> {\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 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}\n"],"names":["createContext","useContext","useQuery","useQueries","PluginRegistryContext","undefined","usePluginRegistry","ctx","Error","usePlugin","pluginType","kind","options","enabled","getPlugin","queryKey","queryFn","usePlugins","plugins","queries","map","p","useListPluginMetadata","pluginTypes","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,QAAyC,wBAAwB;AAU9F,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,UACdC,UAAyB,EACzBC,IAAY,EACZC,OAA6B;QAKjBA;IAHZ,wGAAwG;IACxGA,UAAU;QACR,GAAGA,OAAO;QACVC,SAAS,AAACD,CAAAA,CAAAA,mBAAAA,oBAAAA,8BAAAA,QAASC,OAAO,cAAhBD,8BAAAA,mBAAoB,IAAG,KAAMF,eAAeL,aAAaM,SAAS;IAC9E;IACA,MAAM,EAAEG,SAAS,EAAE,GAAGR;IACtB,OAAOJ,SAAS;QACda,UAAU;YAAC;YAAaL;YAAYC;SAAK;QACzCK,SAAS,IAAMF,UAAUJ,YAAaC;QACtC,GAAGC,OAAO;IACZ;AACF;AAEA;;CAEC,GACD,OAAO,SAASK,WACdP,UAAa,EACbQ,OAAgC;IAEhC,MAAM,EAAEJ,SAAS,EAAE,GAAGR;IACtB,OAAOH,WAAW;QAChBgB,SAASD,QAAQE,GAAG,CAAC,CAACC;YACpB,OAAO;gBACLN,UAAU;oBAAC;oBAAaL;oBAAYW,EAAEV,IAAI;iBAAC;gBAC3CK,SAAS,IAAMF,UAAUJ,YAAYW,EAAEV,IAAI;YAC7C;QACF;IACF;AACF;AAQA;;CAEC,GACD,OAAO,SAASW,sBACdC,WAAyB,EACzBX,OAAsC;IAEtC,MAAM,EAAEY,kBAAkB,EAAE,GAAGlB;IAC/B,OAAOJ,SAAS;QACda,UAAU;YAAC;YAAsBQ;SAAY;QAC7CP,SAAS,IAAMQ,mBAAmBD;QAClC,GAAGX,OAAO;IACZ;AACF;AAEA,OAAO,SAASa;IACd,MAAM,EAAEX,SAAS,EAAEU,kBAAkB,EAAE,GAAGlB;IAE1C,OAAOJ,SAAS;QACda,UAAU;YAAC;SAAsC;QACjDC,SAAS;YACP,MAAMU,cAAc,MAAMF,mBAAmB;gBAAC;aAAa;YAC3D,MAAMG,kBAAkB,IAAIC,IAAIF,YAAYN,GAAG,CAAC,CAACS,aAAeA,WAAWlB,IAAI;YAC/E,MAAMmB,SAAsC,EAAE;YAC9C,KAAK,MAAMnB,QAAQgB,gBAAiB;gBAClC,MAAMI,SAAS,MAAMjB,UAAU,cAAcH;gBAC7C,IAAIoB,OAAOC,6BAA6B,EAAE;oBACxCD,OAAOC,6BAA6B,GAAGC,OAAO,CAAC,CAACC,aAAeJ,OAAOK,IAAI,CAACD;gBAC7E;YACF;YACA,OAAOJ;QACT;IACF;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"],"m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AAU;YAAC;YAAsBQ;SAAY;QAC7CP,SAAS,IAAMQ,mBAAmBD;QAClC,GAAGX,OAAO;IACZ;AACF;AAEA,OAAO,SAASa;IACd,MAAM,EAAEX,SAAS,EAAEU,kBAAkB,EAAE,GAAGlB;IAE1C,OAAOL,SAAS;QACdc,UAAU;YAAC;SAAsC;QACjDC,SAAS;YACP,MAAMU,cAAc,MAAMF,mBAAmB;gBAAC;aAAa;YAC3D,MAAMG,kBAAkB,IAAIC,IAAIF,YAAYN,GAAG,CAAC,CAACS,aAAeA,WAAWC,IAAI,CAACC,IAAI;YACpF,MAAMC,SAAsC,EAAE;YAC9C,KAAK,MAAMD,QAAQJ,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"}
@@ -29,8 +29,8 @@ function filterVariableStateMap(v, names) {
29
29
  }
30
30
  function getQueryOptions({ plugin, definition, context }) {
31
31
  const { timeRange, datasourceStore, suggestedStepMs, mode, 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;
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);
@@ -46,10 +46,7 @@ function getQueryOptions({ plugin, definition, context }) {
46
46
  // Determine queryEnabled
47
47
  let waitToLoad = false;
48
48
  if (variableDependencies) {
49
- waitToLoad = variableDependencies.some((v)=>{
50
- var _variableState_v;
51
- return (_variableState_v = variableState[v]) === null || _variableState_v === void 0 ? void 0 : _variableState_v.loading;
52
- });
49
+ waitToLoad = variableDependencies.some((v)=>variableState[v]?.loading);
53
50
  }
54
51
  const queryEnabled = plugin !== undefined && !waitToLoad;
55
52
  return {
@@ -67,9 +64,8 @@ function getQueryOptions({ plugin, definition, context }) {
67
64
  definition,
68
65
  context
69
66
  });
70
- var _queryOptions_enabled;
71
67
  return useQuery({
72
- 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,
73
69
  queryKey: queryKey,
74
70
  queryFn: ()=>{
75
71
  // The 'enabled' option should prevent this from happening, but make TypeScript happy by checking
@@ -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
  }
@@ -92,29 +88,27 @@ function getQueryOptions({ plugin, definition, context }) {
92
88
  const context = {
93
89
  ...useTimeSeriesQueryContext(),
94
90
  // We need mode to be part query key because this drives the type of query done (instant VS range query)
95
- mode: options === null || options === void 0 ? void 0 : options.mode
91
+ mode: options?.mode
96
92
  };
97
93
  const pluginLoaderResponse = usePlugins(TIME_SERIES_QUERY_KEY, definitions.map((d)=>({
98
94
  kind: d.spec.plugin.kind
99
95
  })));
100
96
  return useQueries({
101
97
  queries: definitions.map((definition, idx)=>{
102
- var _pluginLoaderResponse_idx;
103
- const plugin = (_pluginLoaderResponse_idx = pluginLoaderResponse[idx]) === null || _pluginLoaderResponse_idx === void 0 ? void 0 : _pluginLoaderResponse_idx.data;
98
+ const plugin = pluginLoaderResponse[idx]?.data;
104
99
  const { queryEnabled, queryKey } = getQueryOptions({
105
100
  plugin,
106
101
  definition,
107
102
  context
108
103
  });
109
- var _queryOptions_enabled;
110
104
  return {
111
- 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,
112
106
  queryKey: queryKey,
113
107
  queryFn: async ()=>{
114
108
  const ctx = {
115
109
  ...context,
116
110
  // Keep suggested step changes out of the query key, so we don´t have to run again query when it changes
117
- suggestedStepMs: options === null || options === void 0 ? void 0 : options.suggestedStepMs
111
+ suggestedStepMs: options?.suggestedStepMs
118
112
  };
119
113
  const plugin = await getPlugin(TIME_SERIES_QUERY_KEY, definition.spec.plugin.kind);
120
114
  const data = await plugin.getTimeSeriesData(definition.spec.plugin.spec, ctx);
@@ -151,9 +145,8 @@ function getQueryOptions({ plugin, definition, context }) {
151
145
  for (const query of cache.findAll({
152
146
  type: 'active'
153
147
  })){
154
- var _query_queryKey;
155
- const firstPart = (_query_queryKey = query.queryKey) === null || _query_queryKey === void 0 ? void 0 : _query_queryKey[0];
156
- 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)) {
157
150
  queries.push(query);
158
151
  }
159
152
  }
@@ -1 +1 @@
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,eA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iBAAiB,CAAC/B,WAAWU,IAAI,CAACX,MAAM,CAACW,IAAI,EAAEoB;oBACzE,OAAON;gBACT;YACF;QACF;IACF;AACF;AAEA;;CAEC,GACD,SAASE;IACP,MAAM,EAAEa,iBAAiB,EAAEhC,UAAU,EAAE,GAAG/B;IAC1C,MAAM8B,gBAAgB/B;IACtB,MAAM4B,kBAAkB1B;IAExB,OAAO;QACLyB,WAAWqC;QACXjC;QACAH;QACAI;IACF;AACF;AAEA;;CAEC,GACD,OAAO,SAASiC;IACd,MAAMC,cAAcnE;IACpB,MAAMoE,aAAaD,YAAYE,aAAa;IAC5C,OAAOC,2BAA2BF;AACpC;AAEA;;CAEC,GACD,OAAO,SAASE,2BAA2BC,KAAiB;IAC1D,MAAMR,UAAiC,EAAE;IAEzC,KAAK,MAAMS,SAASD,MAAME,OAAO,CAAC;QAAEC,MAAM;IAAS,GAAI;YACnCF;QAAlB,MAAMG,aAAYH,kBAAAA,MAAM/B,QAAQ,cAAd+B,sCAAAA,eAAgB,CAAC,EAAE;QACrC,IAAIG,CAAAA,sBAAAA,gCAAAA,UAAWxB,IAAI,KAAI,AAACwB,UAAUxB,IAAI,CAAYyB,UAAU,CAACrE,wBAAwB;YACnFwD,QAAQc,IAAI,CAACL;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,UAAU,EAAE,GAAGN;IAEzF,MAAMO,eAAeT,QAAQU,YAAYV,OAAOU,SAAS,CAACT,WAAWU,IAAI,CAACX,MAAM,CAACW,IAAI,EAAET,WAAW,CAAC;IACnG,MAA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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"}
@@ -39,13 +39,12 @@ export function getUnixTimeRange(timeRange) {
39
39
  // https://tanstack.com/query/v4/docs/react/reference/useQuery
40
40
  return useQueries({
41
41
  queries: definitions.map((definition)=>{
42
- var _definition_spec_plugin, _definition_spec;
43
42
  const queryKey = [
44
43
  definition,
45
44
  datasourceStore,
46
45
  absoluteTimeRange
47
46
  ]; // `queryKey` watches and reruns `queryFn` if keys in the array change
48
- const traceQueryKind = definition === null || definition === void 0 ? void 0 : (_definition_spec = definition.spec) === null || _definition_spec === void 0 ? void 0 : (_definition_spec_plugin = _definition_spec.plugin) === null || _definition_spec_plugin === void 0 ? void 0 : _definition_spec_plugin.kind;
47
+ const traceQueryKind = definition?.spec?.plugin?.kind;
49
48
  return {
50
49
  queryKey: queryKey,
51
50
  queryFn: async ()=>{
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/runtime/trace-queries.tsx"],"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 { getUnixTime } from 'date-fns';\nimport { QueryDefinition, UnknownSpec, AbsoluteTimeRange, TraceData } from '@perses-dev/core';\nimport { useQueries, UseQueryResult } from '@tanstack/react-query';\nimport { useDatasourceStore } from './datasources';\nimport { usePluginRegistry } from './plugin-registry';\nimport { useTimeRange } from './TimeRangeProvider';\nexport type TraceQueryDefinition<PluginSpec = UnknownSpec> = QueryDefinition<'TraceQuery', PluginSpec>;\nexport const TRACE_QUERY_KEY = 'TraceQuery';\n\nexport function getUnixTimeRange(timeRange: AbsoluteTimeRange): { start: number; end: number } {\n const { start, end } = timeRange;\n return {\n start: Math.ceil(getUnixTime(start)),\n end: Math.ceil(getUnixTime(end)),\n };\n}\n\n/**\n * Run a trace query using a TraceQuery plugin and return the results\n * @param definitions: dashboard defintion for a trace query, written in Trace Query Language (TraceQL)\n * Documentation for TraceQL: https://grafana.com/docs/tempo/latest/traceql/\n */\nexport function useTraceQueries(definitions: TraceQueryDefinition[]): Array<UseQueryResult<TraceData>> {\n const { getPlugin } = usePluginRegistry();\n const datasourceStore = useDatasourceStore();\n const { absoluteTimeRange } = useTimeRange();\n\n const context = {\n datasourceStore,\n absoluteTimeRange,\n };\n\n // useQueries() handles data fetching from query plugins (e.g. traceQL queries, promQL queries)\n // https://tanstack.com/query/v4/docs/react/reference/useQuery\n return useQueries({\n queries: definitions.map((definition) => {\n const queryKey = [definition, datasourceStore, absoluteTimeRange] as const; // `queryKey` watches and reruns `queryFn` if keys in the array change\n const traceQueryKind = definition?.spec?.plugin?.kind;\n return {\n queryKey: queryKey,\n queryFn: async (): Promise<TraceData> => {\n const plugin = await getPlugin(TRACE_QUERY_KEY, traceQueryKind);\n const data = await plugin.getTraceData(definition.spec.plugin.spec, context);\n return data;\n },\n\n // The data returned by getTraceData() contains circular dependencies (a span has a reference to the parent span, and the parent span has an array of child spans)\n // Therefore structuralSharing must be turned off, otherwise the query is stuck in the 'fetching' state on re-fetch.\n // Ref: https://github.com/TanStack/query/issues/6954#issuecomment-1962321426\n structuralSharing: false,\n };\n }),\n });\n}\n"],"names":["getUnixTime","useQueries","useDatasourceStore","usePluginRegistry","useTimeRange","TRACE_QUERY_KEY","getUnixTimeRange","timeRange","start","end","Math","ceil","useTraceQueries","definitions","getPlugin","datasourceStore","absoluteTimeRange","context","queries","map","definition","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K,OAAO,MAAMH,OAAOI,YAAY,CAACR,WAAWG,IAAI,CAACC,MAAM,CAACD,IAAI,EAAEN;oBACpE,OAAOU;gBACT;gBAEA,kKAAkK;gBAClK,oHAAoH;gBACpH,6EAA6E;gBAC7EE,mBAAmB;YACrB;QACF;IACF;AACF"}
1
+ {"version":3,"sources":["../../src/runtime/trace-queries.tsx"],"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 { getUnixTime } from 'date-fns';\nimport { QueryDefinition, UnknownSpec, AbsoluteTimeRange, TraceData } from '@perses-dev/core';\nimport { useQueries, UseQueryResult } from '@tanstack/react-query';\nimport { useDatasourceStore } from './datasources';\nimport { usePluginRegistry } from './plugin-registry';\nimport { useTimeRange } from './TimeRangeProvider';\nexport type TraceQueryDefinition<PluginSpec = UnknownSpec> = QueryDefinition<'TraceQuery', PluginSpec>;\nexport const TRACE_QUERY_KEY = 'TraceQuery';\n\nexport function getUnixTimeRange(timeRange: AbsoluteTimeRange): { start: number; end: number } {\n const { start, end } = timeRange;\n return {\n start: Math.ceil(getUnixTime(start)),\n end: Math.ceil(getUnixTime(end)),\n };\n}\n\n/**\n * Run a trace query using a TraceQuery plugin and return the results\n * @param definitions: dashboard defintion for a trace query, written in Trace Query Language (TraceQL)\n * Documentation for TraceQL: https://grafana.com/docs/tempo/latest/traceql/\n */\nexport function useTraceQueries(definitions: TraceQueryDefinition[]): Array<UseQueryResult<TraceData>> {\n const { getPlugin } = usePluginRegistry();\n const datasourceStore = useDatasourceStore();\n const { absoluteTimeRange } = useTimeRange();\n\n const context = {\n datasourceStore,\n absoluteTimeRange,\n };\n\n // useQueries() handles data fetching from query plugins (e.g. traceQL queries, promQL queries)\n // https://tanstack.com/query/v4/docs/react/reference/useQuery\n return useQueries({\n queries: definitions.map((definition) => {\n const queryKey = [definition, datasourceStore, absoluteTimeRange] as const; // `queryKey` watches and reruns `queryFn` if keys in the array change\n const traceQueryKind = definition?.spec?.plugin?.kind;\n return {\n queryKey: queryKey,\n queryFn: async (): Promise<TraceData> => {\n const plugin = await getPlugin(TRACE_QUERY_KEY, traceQueryKind);\n const data = await plugin.getTraceData(definition.spec.plugin.spec, context);\n return data;\n },\n\n // The data returned by getTraceData() contains circular dependencies (a span has a reference to the parent span, and the parent span has an array of child spans)\n // Therefore structuralSharing must be turned off, otherwise the query is stuck in the 'fetching' state on re-fetch.\n // Ref: https://github.com/TanStack/query/issues/6954#issuecomment-1962321426\n structuralSharing: false,\n };\n }),\n });\n}\n"],"names":["getUnixTime","useQueries","useDatasourceStore","usePluginRegistry","useTimeRange","TRACE_QUERY_KEY","getUnixTimeRange","timeRange","start","end","Math","ceil","useTraceQueries","definitions","getPlugin","datasourceStore","absoluteTimeRange","context","queries","map","definition","queryKey","traceQueryKind","spec","plugin","kind","queryFn","data","getTraceData","structuralSharing"],"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,WAAW,QAAQ,WAAW;AAEvC,SAASC,UAAU,QAAwB,wBAAwB;AACnE,SAASC,kBAAkB,QAAQ,gBAAgB;AACnD,SAASC,iBAAiB,QAAQ,oBAAoB;AACtD,SAASC,YAAY,QAAQ,sBAAsB;AAEnD,OAAO,MAAMC,kBAAkB,aAAa;AAE5C,OAAO,SAASC,iBAAiBC,SAA4B;IAC3D,MAAM,EAAEC,KAAK,EAAEC,GAAG,EAAE,GAAGF;IACvB,OAAO;QACLC,OAAOE,KAAKC,IAAI,CAACX,YAAYQ;QAC7BC,KAAKC,KAAKC,IAAI,CAACX,YAAYS;IAC7B;AACF;AAEA;;;;CAIC,GACD,OAAO,SAASG,gBAAgBC,WAAmC;IACjE,MAAM,EAAEC,SAAS,EAAE,GAAGX;IACtB,MAAMY,kBAAkBb;IACxB,MAAM,EAAEc,iBAAiB,EAAE,GAAGZ;IAE9B,MAAMa,UAAU;QACdF;QACAC;IACF;IAEA,+FAA+F;IAC/F,8DAA8D;IAC9D,OAAOf,WAAW;QAChBiB,SAASL,YAAYM,GAAG,CAAC,CAACC;YACxB,MAAMC,WAAW;gBAACD;gBAAYL;gBAAiBC;aAAkB,EAAW,sEAAsE;YAClJ,MAAMM,iBAAiBF,YAAYG,MAAMC,QAAQC;YACjD,OAAO;gBACLJ,UAAUA;gBACVK,SAAS;oBACP,MAAMF,SAAS,MAAMV,UAAUT,iBAAiBiB;oBAChD,MAAMK,OAAO,MAAMH,OAAOI,YAAY,CAACR,WAAWG,IAAI,CAACC,MAAM,CAACD,IAAI,EAAEN;oBACpE,OAAOU;gBACT;gBAEA,kKAAkK;gBAClK,oHAAoH;gBACpH,6EAA6E;gBAC7EE,mBAAmB;YACrB;QACF;IACF;AACF"}
@@ -10,28 +10,20 @@
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
- function _define_property(obj, key, value) {
14
- if (key in obj) {
15
- Object.defineProperty(obj, key, {
16
- value: value,
17
- enumerable: true,
18
- configurable: true,
19
- writable: true
20
- });
21
- } else {
22
- obj[key] = value;
23
- }
24
- return obj;
25
- }
26
13
  import { createContext, useContext, useMemo } from 'react';
27
14
  import { immerable } from 'immer';
28
15
  import { parseVariables, replaceVariables } from '../utils';
29
16
  import { useBuiltinVariableValues } from './builtin-variables';
30
- let _immerable = immerable;
31
17
  /**
32
18
  * A state map with two entry keys, materialized by {@link VariableStateKey} structure.
33
19
  */ export class VariableStoreStateMap {
34
20
  /**
21
+ * "Immerable" is mandatory to be able to use this class in an immer context.
22
+ * Ref: https://docs.pmnd.rs/zustand/integrations/immer-middleware#gotchas
23
+ */ [immerable] = true;
24
+ DEFAULT_LOCAL_SOURCE_NAME = '';
25
+ _state = {};
26
+ /**
35
27
  * Get variable state by key.
36
28
  * @param key
37
29
  */ get(key) {
@@ -59,7 +51,6 @@ let _immerable = immerable;
59
51
  * Delete variable state by key.
60
52
  * @param key
61
53
  */ delete(key) {
62
- var _Object_keys;
63
54
  const result = this.has(key);
64
55
  const sourceName = this._sourceName(key.source);
65
56
  const sourceStates = this._state[sourceName];
@@ -68,25 +59,16 @@ let _immerable = immerable;
68
59
  delete sourceStates[key.name];
69
60
  }
70
61
  // Delete source state from state if empty
71
- if (((_Object_keys = Object.keys(sourceStates !== null && sourceStates !== void 0 ? sourceStates : {})) === null || _Object_keys === void 0 ? void 0 : _Object_keys.length) === 0) {
62
+ if (Object.keys(sourceStates ?? {})?.length === 0) {
72
63
  delete this._state[sourceName];
73
64
  }
74
65
  return result;
75
66
  }
76
67
  _sourceName(source) {
77
- return source !== null && source !== void 0 ? source : this.DEFAULT_LOCAL_SOURCE_NAME;
68
+ return source ?? this.DEFAULT_LOCAL_SOURCE_NAME;
78
69
  }
79
70
  _sourceStatesOrEmpty(source) {
80
- var _this__state_this__sourceName;
81
- return (_this__state_this__sourceName = this._state[this._sourceName(source)]) !== null && _this__state_this__sourceName !== void 0 ? _this__state_this__sourceName : {};
82
- }
83
- constructor(){
84
- /**
85
- * "Immerable" is mandatory to be able to use this class in an immer context.
86
- * Ref: https://docs.pmnd.rs/zustand/integrations/immer-middleware#gotchas
87
- */ _define_property(this, _immerable, true);
88
- _define_property(this, "DEFAULT_LOCAL_SOURCE_NAME", '');
89
- _define_property(this, "_state", {});
71
+ return this._state[this._sourceName(source)] ?? {};
90
72
  }
91
73
  }
92
74
  export const VariableContext = createContext(undefined);
@@ -101,7 +83,7 @@ export function useVariableValues(names) {
101
83
  const { state } = useVariableContext();
102
84
  const values = useMemo(()=>{
103
85
  const values = {};
104
- names === null || names === void 0 ? void 0 : names.forEach((name)=>{
86
+ names?.forEach((name)=>{
105
87
  const s = state[name];
106
88
  if (s) {
107
89
  values[name] = s;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/runtime/variables.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 { createContext, useContext, useMemo } from 'react';\nimport { VariableValue } from '@perses-dev/core';\nimport { immerable } from 'immer';\nimport { VariableOption } from '../model';\nimport { parseVariables, replaceVariables } from '../utils';\nimport { useBuiltinVariableValues } from './builtin-variables';\n\nexport type VariableState = {\n value: VariableValue;\n options?: VariableOption[];\n loading: boolean;\n error?: Error;\n /**\n * If a local variable is overriding an external variable, local var will have the flag ``overriding=true``.\n */\n overriding?: boolean;\n /**\n * If a local variable is overriding an external variable, external var will have the flag ``overridden=true``.\n */\n overridden?: boolean;\n defaultValue?: VariableValue;\n};\n\nexport type VariableStateMap = Record<string, VariableState>;\n\n/**\n * Structure used as key in the {@link VariableStoreStateMap}.\n */\nexport type VariableStateKey = {\n /**\n * name of the variable we want to access in the state.\n */\n name: string;\n /**\n * source of the variable we want to access in the state.\n * Defined only for external variables.\n */\n source?: string;\n};\n\n/**\n * A state map with two entry keys, materialized by {@link VariableStateKey} structure.\n */\nexport class VariableStoreStateMap {\n /**\n * \"Immerable\" is mandatory to be able to use this class in an immer context.\n * Ref: https://docs.pmnd.rs/zustand/integrations/immer-middleware#gotchas\n */\n [immerable] = true;\n\n private readonly DEFAULT_LOCAL_SOURCE_NAME = '';\n private readonly _state: Record<string, Record<string, VariableState>> = {};\n\n /**\n * Get variable state by key.\n * @param key\n */\n get(key: VariableStateKey): VariableState | undefined {\n return this._sourceStatesOrEmpty(key.source)[key.name];\n }\n\n /**\n * Set variable state by key.\n * @param key\n * @param value\n */\n set(key: VariableStateKey, value: VariableState): VariableState | undefined {\n const sourceName = this._sourceName(key.source);\n if (!this._state[sourceName]) {\n this._state[sourceName] = {};\n }\n this._sourceStatesOrEmpty(key.source)[key.name] = value;\n return value;\n }\n\n /**\n * Check presence of variable state by key.\n * @param key\n */\n has(key: VariableStateKey): boolean {\n return this._sourceStatesOrEmpty(key.source)[key.name] !== undefined;\n }\n\n /**\n * Delete variable state by key.\n * @param key\n */\n delete(key: VariableStateKey): boolean {\n const result = this.has(key);\n const sourceName = this._sourceName(key.source);\n const sourceStates = this._state[sourceName];\n\n // Delete var from source state\n if (sourceStates) {\n delete sourceStates[key.name];\n }\n\n // Delete source state from state if empty\n if (Object.keys(sourceStates ?? {})?.length === 0) {\n delete this._state[sourceName];\n }\n return result;\n }\n\n private _sourceName(source: string | undefined): string {\n return source ?? this.DEFAULT_LOCAL_SOURCE_NAME;\n }\n\n private _sourceStatesOrEmpty(source: string | undefined): Record<string, VariableState> {\n return this._state[this._sourceName(source)] ?? {};\n }\n}\n\nexport type VariableSrv = {\n state: VariableStateMap;\n};\n\nexport const VariableContext = createContext<VariableSrv | undefined>(undefined);\n\nfunction useVariableContext(): VariableSrv {\n const ctx = useContext(VariableContext);\n if (ctx === undefined) {\n throw new Error('No VariableContext found. Did you forget a Provider?');\n }\n return ctx;\n}\n\nexport function useVariableValues(names?: string[]): VariableStateMap {\n const { state } = useVariableContext();\n\n const values = useMemo(() => {\n const values: VariableStateMap = {};\n names?.forEach((name) => {\n const s = state[name];\n if (s) {\n values[name] = s;\n }\n });\n return values;\n }, [state, names]);\n\n if (names === undefined) {\n return state;\n }\n\n return values;\n}\n\n// useAllVariableValues wraps user-defined variables with built-in variables\nexport function useAllVariableValues(names?: string[]): VariableStateMap {\n const variableValues = useVariableValues(names);\n const builtinVariableValues = useBuiltinVariableValues(names);\n\n return useMemo(() => {\n return { ...variableValues, ...builtinVariableValues } as VariableStateMap;\n }, [variableValues, builtinVariableValues]);\n}\n\n// Convenience hook for replacing variables in a string\nexport function useReplaceVariablesInString(str: string | undefined): string | undefined {\n const variablesInString = str ? parseVariables(str) : [];\n const variableValues = useAllVariableValues(variablesInString);\n if (!str) return undefined;\n return replaceVariables(str, variableValues);\n}\n"],"names":["createContext","useContext","useMemo","immerable","parseVariables","replaceVariables","useBuiltinVariableValues","VariableStoreStateMap","get","key","_sourceStatesOrEmpty","source","name","set","value","sourceName","_sourceName","_state","has","undefined","delete","Object","result","sourceStates","keys","length","DEFAULT_LOCAL_SOURCE_NAME","VariableContext","useVariableContext","ctx","Error","useVariableValues","names","state","values","forEach","s","useAllVariableValues","variableValues","builtinVariableValues","useReplaceVariablesInString","str","variablesInString"],"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,EAAEC,OAAO,QAAQ,QAAQ;AAE3D,SAASC,SAAS,QAAQ,QAAQ;AAElC,SAASC,cAAc,EAAEC,gBAAgB,QAAQ,WAAW;AAC5D,SAASC,wBAAwB,QAAQ,sBAAsB;IA2C5DH,aAAAA;AARH;;CAEC,GACD,OAAO,MAAMI;IAUX;;;GAGC,GACDC,IAAIC,GAAqB,EAA6B;QACpD,OAAO,IAAI,CAACC,oBAAoB,CAACD,IAAIE,MAAM,CAAC,CAACF,IAAIG,IAAI,CAAC;IACxD;IAEA;;;;GAIC,GACDC,IAAIJ,GAAqB,EAAEK,KAAoB,EAA6B;QAC1E,MAAMC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;AAMA,OAAO,MAAMU,kBAAkB3B,cAAuCmB,WAAW;AAEjF,SAASS;IACP,MAAMC,MAAM5B,WAAW0B;IACvB,IAAIE,QAAQV,WAAW;QACrB,MAAM,IAAIW,MAAM;IAClB;IACA,OAAOD;AACT;AAEA,OAAO,SAASE,kBAAkBC,KAAgB;IAChD,MAAM,EAAEC,KAAK,EAAE,GAAGL;IAElB,MAAMM,SAAShC,QAAQ;QACrB,MAAMgC,SAA2B,CAAC;QAClCF,kBAAAA,4BAAAA,MAAOG,OAAO,CAAC,CAACvB;YACd,MAAMwB,IAAIH,KAAK,CAACrB,KAAK;YACrB,IAAIwB,GAAG;gBACLF,MAAM,CAACtB,KAAK,GAAGwB;YACjB;QACF;QACA,OAAOF;IACT,GAAG;QAACD;QAAOD;KAAM;IAEjB,IAAIA,UAAUb,WAAW;QACvB,OAAOc;IACT;IAEA,OAAOC;AACT;AAEA,4EAA4E;AAC5E,OAAO,SAASG,qBAAqBL,KAAgB;IACnD,MAAMM,iBAAiBP,kBAAkBC;IACzC,MAAMO,wBAAwBjC,yBAAyB0B;IAEvD,OAAO9B,QAAQ;QACb,OAAO;YAAE,GAAGoC,cAAc;YAAE,GAAGC,qBAAqB;QAAC;IACvD,GAAG;QAACD;QAAgBC;KAAsB;AAC5C;AAEA,uDAAuD;AACvD,OAAO,SAASC,4BAA4BC,GAAuB;IACjE,MAAMC,oBAAoBD,MAAMrC,eAAeqC,OAAO,EAAE;IACxD,MAAMH,iBAAiBD,qBAAqBK;IAC5C,IAAI,CAACD,KAAK,OAAOtB;IACjB,OAAOd,iBAAiBoC,KAAKH;AAC/B"}
1
+ {"version":3,"sources":["../../src/runtime/variables.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 { createContext, useContext, useMemo } from 'react';\nimport { VariableValue } from '@perses-dev/core';\nimport { immerable } from 'immer';\nimport { VariableOption } from '../model';\nimport { parseVariables, replaceVariables } from '../utils';\nimport { useBuiltinVariableValues } from './builtin-variables';\n\nexport type VariableState = {\n value: VariableValue;\n options?: VariableOption[];\n loading: boolean;\n error?: Error;\n /**\n * If a local variable is overriding an external variable, local var will have the flag ``overriding=true``.\n */\n overriding?: boolean;\n /**\n * If a local variable is overriding an external variable, external var will have the flag ``overridden=true``.\n */\n overridden?: boolean;\n defaultValue?: VariableValue;\n};\n\nexport type VariableStateMap = Record<string, VariableState>;\n\n/**\n * Structure used as key in the {@link VariableStoreStateMap}.\n */\nexport type VariableStateKey = {\n /**\n * name of the variable we want to access in the state.\n */\n name: string;\n /**\n * source of the variable we want to access in the state.\n * Defined only for external variables.\n */\n source?: string;\n};\n\n/**\n * A state map with two entry keys, materialized by {@link VariableStateKey} structure.\n */\nexport class VariableStoreStateMap {\n /**\n * \"Immerable\" is mandatory to be able to use this class in an immer context.\n * Ref: https://docs.pmnd.rs/zustand/integrations/immer-middleware#gotchas\n */\n [immerable] = true;\n\n private readonly DEFAULT_LOCAL_SOURCE_NAME = '';\n private readonly _state: Record<string, Record<string, VariableState>> = {};\n\n /**\n * Get variable state by key.\n * @param key\n */\n get(key: VariableStateKey): VariableState | undefined {\n return this._sourceStatesOrEmpty(key.source)[key.name];\n }\n\n /**\n * Set variable state by key.\n * @param key\n * @param value\n */\n set(key: VariableStateKey, value: VariableState): VariableState | undefined {\n const sourceName = this._sourceName(key.source);\n if (!this._state[sourceName]) {\n this._state[sourceName] = {};\n }\n this._sourceStatesOrEmpty(key.source)[key.name] = value;\n return value;\n }\n\n /**\n * Check presence of variable state by key.\n * @param key\n */\n has(key: VariableStateKey): boolean {\n return this._sourceStatesOrEmpty(key.source)[key.name] !== undefined;\n }\n\n /**\n * Delete variable state by key.\n * @param key\n */\n delete(key: VariableStateKey): boolean {\n const result = this.has(key);\n const sourceName = this._sourceName(key.source);\n const sourceStates = this._state[sourceName];\n\n // Delete var from source state\n if (sourceStates) {\n delete sourceStates[key.name];\n }\n\n // Delete source state from state if empty\n if (Object.keys(sourceStates ?? {})?.length === 0) {\n delete this._state[sourceName];\n }\n return result;\n }\n\n private _sourceName(source: string | undefined): string {\n return source ?? this.DEFAULT_LOCAL_SOURCE_NAME;\n }\n\n private _sourceStatesOrEmpty(source: string | undefined): Record<string, VariableState> {\n return this._state[this._sourceName(source)] ?? {};\n }\n}\n\nexport type VariableSrv = {\n state: VariableStateMap;\n};\n\nexport const VariableContext = createContext<VariableSrv | undefined>(undefined);\n\nfunction useVariableContext(): VariableSrv {\n const ctx = useContext(VariableContext);\n if (ctx === undefined) {\n throw new Error('No VariableContext found. Did you forget a Provider?');\n }\n return ctx;\n}\n\nexport function useVariableValues(names?: string[]): VariableStateMap {\n const { state } = useVariableContext();\n\n const values = useMemo(() => {\n const values: VariableStateMap = {};\n names?.forEach((name) => {\n const s = state[name];\n if (s) {\n values[name] = s;\n }\n });\n return values;\n }, [state, names]);\n\n if (names === undefined) {\n return state;\n }\n\n return values;\n}\n\n// useAllVariableValues wraps user-defined variables with built-in variables\nexport function useAllVariableValues(names?: string[]): VariableStateMap {\n const variableValues = useVariableValues(names);\n const builtinVariableValues = useBuiltinVariableValues(names);\n\n return useMemo(() => {\n return { ...variableValues, ...builtinVariableValues } as VariableStateMap;\n }, [variableValues, builtinVariableValues]);\n}\n\n// Convenience hook for replacing variables in a string\nexport function useReplaceVariablesInString(str: string | undefined): string | undefined {\n const variablesInString = str ? parseVariables(str) : [];\n const variableValues = useAllVariableValues(variablesInString);\n if (!str) return undefined;\n return replaceVariables(str, variableValues);\n}\n"],"names":["createContext","useContext","useMemo","immerable","parseVariables","replaceVariables","useBuiltinVariableValues","VariableStoreStateMap","DEFAULT_LOCAL_SOURCE_NAME","_state","get","key","_sourceStatesOrEmpty","source","name","set","value","sourceName","_sourceName","has","undefined","delete","result","sourceStates","Object","keys","length","VariableContext","useVariableContext","ctx","Error","useVariableValues","names","state","values","forEach","s","useAllVariableValues","variableValues","builtinVariableValues","useReplaceVariablesInString","str","variablesInString"],"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,EAAEC,OAAO,QAAQ,QAAQ;AAE3D,SAASC,SAAS,QAAQ,QAAQ;AAElC,SAASC,cAAc,EAAEC,gBAAgB,QAAQ,WAAW;AAC5D,SAASC,wBAAwB,QAAQ,sBAAsB;AAmC/D;;CAEC,GACD,OAAO,MAAMC;IACX;;;GAGC,GACD,CAACJ,UAAU,GAAG,KAAK;IAEFK,4BAA4B,GAAG;IAC/BC,SAAwD,CAAC,EAAE;IAE5E;;;GAGC,GACDC,IAAIC,GAAqB,EAA6B;QACpD,OAAO,IAAI,CAACC,oBAAoB,CAACD,IAAIE,MAAM,CAAC,CAACF,IAAIG,IAAI,CAAC;IACxD;IAEA;;;;GAIC,GACDC,IAAIJ,GAAqB,EAAEK,KAAoB,EAA6B;QAC1E,MAAMC,aAAa,IAAI,CAACC,WAAW,CAACP,IAAIE,MAAM;QAC9C,IAAI,CAAC,IAAI,CAACJ,MAAM,CAACQ,WAAW,EAAE;YAC5B,IAAI,CAACR,MAAM,CAACQ,WAAW,GAAG,CAAC;QAC7B;QACA,IAAI,CAACL,oBAAoB,CAACD,IAAIE,MAAM,CAAC,CAACF,IAAIG,IAAI,CAAC,GAAGE;QAClD,OAAOA;IACT;IAEA;;;GAGC,GACDG,IAAIR,GAAqB,EAAW;QAClC,OAAO,IAAI,CAACC,oBAAoB,CAACD,IAAIE,MAAM,C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O,SAASG,qBAAqBL,KAAgB;IACnD,MAAMM,iBAAiBP,kBAAkBC;IACzC,MAAMO,wBAAwBjC,yBAAyB0B;IAEvD,OAAO9B,QAAQ;QACb,OAAO;YAAE,GAAGoC,cAAc;YAAE,GAAGC,qBAAqB;QAAC;IACvD,GAAG;QAACD;QAAgBC;KAAsB;AAC5C;AAEA,uDAAuD;AACvD,OAAO,SAASC,4BAA4BC,GAAuB;IACjE,MAAMC,oBAAoBD,MAAMrC,eAAeqC,OAAO,EAAE;IACxD,MAAMH,iBAAiBD,qBAAqBK;IAC5C,IAAI,CAACD,KAAK,OAAOrB;IACjB,OAAOf,iBAAiBoC,KAAKH;AAC/B"}
@@ -23,7 +23,7 @@ export const WithDataQueries = (Story, context)=>{
23
23
  definitions: []
24
24
  }
25
25
  };
26
- const props = parameter === null || parameter === void 0 ? void 0 : parameter.props;
26
+ const props = parameter?.props;
27
27
  return /*#__PURE__*/ _jsx(DataQueriesProvider, {
28
28
  ...props,
29
29
  children: /*#__PURE__*/ _jsx(Story, {})
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/stories/shared-utils/decorators/WithDataQueries.tsx"],"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 { Definition, UnknownSpec } from '@perses-dev/core';\nimport { DataQueriesProvider, DataQueriesProviderProps } from '@perses-dev/plugin-system';\nimport { StoryFn, StoryContext } from '@storybook/react';\nimport { ReactElement } from 'react';\n\ndeclare module '@storybook/react' {\n interface Parameters {\n withDataQueries?: WithDataQueriesProvideParameter;\n }\n}\n\nexport type WithDataQueriesProvideParameter = {\n props: DataQueriesProviderProps;\n};\n\n// Type guard because storybook types parameters as `any`\nfunction isWithDataQueriesParameter(\n parameter: unknown | WithDataQueriesProvideParameter\n): parameter is WithDataQueriesProvideParameter {\n return !!parameter && typeof parameter === 'object' && 'props' in parameter;\n}\n\nexport const WithDataQueries = (Story: StoryFn, context: StoryContext<unknown>): ReactElement => {\n const initParameter = context.parameters.withDataQueries;\n const parameter = isWithDataQueriesParameter(initParameter)\n ? initParameter\n : { props: { definitions: [] as Array<Definition<UnknownSpec>> } };\n const props = parameter?.props;\n\n return (\n <DataQueriesProvider {...props}>\n <Story />\n </DataQueriesProvider>\n );\n};\n"],"names":["DataQueriesProvider","isWithDataQueriesParameter","parameter","WithDataQueries","Story","context","initParameter","parameters","withDataQueries","props","definitions"],"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,mBAAmB,QAAkC,4BAA4B;AAc1F,yDAAyD;AACzD,SAASC,2BACPC,SAAoD;IAEpD,OAAO,CAAC,CAACA,aAAa,OAAOA,cAAc,YAAY,WAAWA;AACpE;AAEA,OAAO,MAAMC,kBAAkB,CAACC,OAAgBC;IAC9C,MAAMC,gBAAgBD,QAAQE,UAAU,CAACC,eAAe;IACxD,MAAMN,YAAYD,2BAA2BK,iBACzCA,gBACA;QAAEG,OAAO;YAAEC,aAAa,EAAE;QAAmC;IAAE;IACnE,MAAMD,QAAQP,sBAAAA,gCAAAA,UAAWO,KAAK;IAE9B,qBACE,KAACT;QAAqB,GAAGS,KAAK;kBAC5B,cAAA,KAACL;;AAGP,EAAE"}
1
+ {"version":3,"sources":["../../../../src/stories/shared-utils/decorators/WithDataQueries.tsx"],"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 { Definition, UnknownSpec } from '@perses-dev/core';\nimport { DataQueriesProvider, DataQueriesProviderProps } from '@perses-dev/plugin-system';\nimport { StoryFn, StoryContext } from '@storybook/react';\nimport { ReactElement } from 'react';\n\ndeclare module '@storybook/react' {\n interface Parameters {\n withDataQueries?: WithDataQueriesProvideParameter;\n }\n}\n\nexport type WithDataQueriesProvideParameter = {\n props: DataQueriesProviderProps;\n};\n\n// Type guard because storybook types parameters as `any`\nfunction isWithDataQueriesParameter(\n parameter: unknown | WithDataQueriesProvideParameter\n): parameter is WithDataQueriesProvideParameter {\n return !!parameter && typeof parameter === 'object' && 'props' in parameter;\n}\n\nexport const WithDataQueries = (Story: StoryFn, context: StoryContext<unknown>): ReactElement => {\n const initParameter = context.parameters.withDataQueries;\n const parameter = isWithDataQueriesParameter(initParameter)\n ? initParameter\n : { props: { definitions: [] as Array<Definition<UnknownSpec>> } };\n const props = parameter?.props;\n\n return (\n <DataQueriesProvider {...props}>\n <Story />\n </DataQueriesProvider>\n );\n};\n"],"names":["DataQueriesProvider","isWithDataQueriesParameter","parameter","WithDataQueries","Story","context","initParameter","parameters","withDataQueries","props","definitions"],"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,mBAAmB,QAAkC,4BAA4B;AAc1F,yDAAyD;AACzD,SAASC,2BACPC,SAAoD;IAEpD,OAAO,CAAC,CAACA,aAAa,OAAOA,cAAc,YAAY,WAAWA;AACpE;AAEA,OAAO,MAAMC,kBAAkB,CAACC,OAAgBC;IAC9C,MAAMC,gBAAgBD,QAAQE,UAAU,CAACC,eAAe;IACxD,MAAMN,YAAYD,2BAA2BK,iBACzCA,gBACA;QAAEG,OAAO;YAAEC,aAAa,EAAE;QAAmC;IAAE;IACnE,MAAMD,QAAQP,WAAWO;IAEzB,qBACE,KAACT;QAAqB,GAAGS,KAAK;kBAC5B,cAAA,KAACL;;AAGP,EAAE"}
@@ -1 +1 @@
1
- {"version":3,"file":"WithPluginRegistry.d.ts","sourceRoot":"","sources":["../../../../src/stories/shared-utils/decorators/WithPluginRegistry.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAU3C,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAqBrC,eAAO,MAAM,kBAAkB,UAAW,OAAO,KAAG,YAYnD,CAAC"}
1
+ {"version":3,"file":"WithPluginRegistry.d.ts","sourceRoot":"","sources":["../../../../src/stories/shared-utils/decorators/WithPluginRegistry.tsx"],"names":[],"mappings":"AAcA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAErC,eAAO,MAAM,kBAAkB,UAAW,OAAO,KAAG,YAYnD,CAAC"}
@@ -11,30 +11,10 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
  import { jsx as _jsx } from "react/jsx-runtime";
14
- import { PluginRegistry, dynamicImportPluginLoader } from '@perses-dev/plugin-system';
15
- import prometheusResource from '@perses-dev/prometheus-plugin/plugin.json';
16
- import panelsResource from '@perses-dev/panels-plugin/plugin.json';
17
- const bundledPluginLoader = dynamicImportPluginLoader([
18
- {
19
- resource: prometheusResource,
20
- // This throws an error in CI (but not locally for some reason), likely because
21
- // this package isn't a dependency for dashboards. We probably do not want to
22
- // make it one solely for type-checking in storybook.
23
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
24
- // @ts-ignore
25
- importPlugin: ()=>import('@perses-dev/prometheus-plugin')
26
- },
27
- {
28
- resource: panelsResource,
29
- // Same comment as above.
30
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
31
- // @ts-ignore
32
- importPlugin: ()=>import('@perses-dev/panels-plugin')
33
- }
34
- ]);
14
+ import { PluginRegistry, remotePluginLoader } from '@perses-dev/plugin-system';
35
15
  export const WithPluginRegistry = (Story)=>{
36
16
  return /*#__PURE__*/ _jsx(PluginRegistry, {
37
- pluginLoader: bundledPluginLoader,
17
+ pluginLoader: remotePluginLoader(),
38
18
  defaultPluginKinds: {
39
19
  TimeSeriesQuery: 'PrometheusTimeSeriesQuery',
40
20
  TraceQuery: 'TempoTraceQuery'
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/stories/shared-utils/decorators/WithPluginRegistry.tsx"],"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 { StoryFn } from '@storybook/react';\nimport {\n PluginRegistry,\n PluginLoader,\n PluginModuleResource,\n dynamicImportPluginLoader,\n} from '@perses-dev/plugin-system';\n\nimport prometheusResource from '@perses-dev/prometheus-plugin/plugin.json';\nimport panelsResource from '@perses-dev/panels-plugin/plugin.json';\nimport { ReactElement } from 'react';\n\nconst bundledPluginLoader: PluginLoader = dynamicImportPluginLoader([\n {\n resource: prometheusResource as PluginModuleResource,\n // This throws an error in CI (but not locally for some reason), likely because\n // this package isn't a dependency for dashboards. We probably do not want to\n // make it one solely for type-checking in storybook.\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n importPlugin: () => import('@perses-dev/prometheus-plugin'),\n },\n {\n resource: panelsResource as PluginModuleResource,\n // Same comment as above.\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n importPlugin: () => import('@perses-dev/panels-plugin'),\n },\n]);\n\nexport const WithPluginRegistry = (Story: StoryFn): ReactElement => {\n return (\n <PluginRegistry\n pluginLoader={bundledPluginLoader}\n defaultPluginKinds={{\n TimeSeriesQuery: 'PrometheusTimeSeriesQuery',\n TraceQuery: 'TempoTraceQuery',\n }}\n >\n <Story />\n </PluginRegistry>\n );\n};\n"],"names":["PluginRegistry","dynamicImportPluginLoader","prometheusResource","panelsResource","bundledPluginLoader","resource","importPlugin","WithPluginRegistry","Story","pluginLoader","defaultPluginKinds","TimeSeriesQuery","TraceQuery"],"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,SACEA,cAAc,EAGdC,yBAAyB,QACpB,4BAA4B;AAEnC,OAAOC,wBAAwB,4CAA4C;AAC3E,OAAOC,oBAAoB,wCAAwC;AAGnE,MAAMC,sBAAoCH,0BAA0B;IAClE;QACEI,UAAUH;QACV,+EAA+E;QAC/E,6EAA6E;QAC7E,qDAAqD;QACrD,6DAA6D;QAC7D,aAAa;QACbI,cAAc,IAAM,MAAM,CAAC;IAC7B;IACA;QACED,UAAUF;QACV,yBAAyB;QACzB,6DAA6D;QAC7D,aAAa;QACbG,cAAc,IAAM,MAAM,CAAC;IAC7B;CACD;AAED,OAAO,MAAMC,qBAAqB,CAACC;IACjC,qBACE,KAACR;QACCS,cAAcL;QACdM,oBAAoB;YAClBC,iBAAiB;YACjBC,YAAY;QACd;kBAEA,cAAA,KAACJ;;AAGP,EAAE"}
1
+ {"version":3,"sources":["../../../../src/stories/shared-utils/decorators/WithPluginRegistry.tsx"],"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 { PluginRegistry, remotePluginLoader } from '@perses-dev/plugin-system';\nimport { StoryFn } from '@storybook/react';\n\nimport { ReactElement } from 'react';\n\nexport const WithPluginRegistry = (Story: StoryFn): ReactElement => {\n return (\n <PluginRegistry\n pluginLoader={remotePluginLoader()}\n defaultPluginKinds={{\n TimeSeriesQuery: 'PrometheusTimeSeriesQuery',\n TraceQuery: 'TempoTraceQuery',\n }}\n >\n <Story />\n </PluginRegistry>\n );\n};\n"],"names":["PluginRegistry","remotePluginLoader","WithPluginRegistry","Story","pluginLoader","defaultPluginKinds","TimeSeriesQuery","TraceQuery"],"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,cAAc,EAAEC,kBAAkB,QAAQ,4BAA4B;AAK/E,OAAO,MAAMC,qBAAqB,CAACC;IACjC,qBACE,KAACH;QACCI,cAAcH;QACdI,oBAAoB;YAClBC,iBAAiB;YACjBC,YAAY;QACd;kBAEA,cAAA,KAACJ;;AAGP,EAAE"}
@@ -29,7 +29,7 @@ export const WithPluginSystemBuiltinVariables = (Story, context)=>{
29
29
  const parameter = isWithBuiltinVariableParameter(initParameter) ? initParameter : {
30
30
  props: defaultValue
31
31
  };
32
- const props = parameter === null || parameter === void 0 ? void 0 : parameter.props;
32
+ const props = parameter?.props;
33
33
  return /*#__PURE__*/ _jsx(BuiltinVariableContext.Provider, {
34
34
  value: props,
35
35
  children: /*#__PURE__*/ _jsx(Story, {})
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.tsx"],"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 { StoryFn, StoryContext } from '@storybook/react';\nimport { ReactElement } from 'react';\nimport { BuiltinVariableContext, BuiltinVariableSrv } from '../../../runtime';\n\ndeclare module '@storybook/react' {\n interface Parameters {\n withPluginSystemBuiltinVariables?: WithPluginSystemBuiltinVariableParameter;\n }\n}\n\nexport type WithPluginSystemBuiltinVariableParameter = {\n props: BuiltinVariableSrv;\n};\n\n// Type guard because storybook types parameters as `any`\nfunction isWithBuiltinVariableParameter(\n parameter: unknown | WithPluginSystemBuiltinVariableParameter\n): parameter is WithPluginSystemBuiltinVariableParameter {\n return !!parameter && Array.isArray(parameter);\n}\n\n// This decorator is used for non-dashboards package Builtin variable needs.\n// Use the more specific decorator in the dashboards package when working with\n// dashboards.\n// This decorator includes \"PluginSystem\" in the name to differentiate it from\n// the datasource store decorator in the `dashboards` package.\nexport const WithPluginSystemBuiltinVariables = (Story: StoryFn, context: StoryContext<unknown>): ReactElement => {\n const initParameter = context.parameters.withPluginSystemBuiltinVariables;\n const defaultValue: BuiltinVariableSrv = {\n variables: [],\n };\n const parameter = isWithBuiltinVariableParameter(initParameter) ? initParameter : { props: defaultValue };\n\n const props = parameter?.props;\n\n return (\n <BuiltinVariableContext.Provider value={props}>\n <Story />\n </BuiltinVariableContext.Provider>\n );\n};\n"],"names":["BuiltinVariableContext","isWithBuiltinVariableParameter","parameter","Array","isArray","WithPluginSystemBuiltinVariables","Story","context","initParameter","parameters","withPluginSystemBuiltinVariables","defaultValue","variables","props","Provider","value"],"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;;AAIjC,SAASA,sBAAsB,QAA4B,mBAAmB;AAY9E,yDAAyD;AACzD,SAASC,+BACPC,SAA6D;IAE7D,OAAO,CAAC,CAACA,aAAaC,MAAMC,OAAO,CAACF;AACtC;AAEA,4EAA4E;AAC5E,8EAA8E;AAC9E,cAAc;AACd,8EAA8E;AAC9E,8DAA8D;AAC9D,OAAO,MAAMG,mCAAmC,CAACC,OAAgBC;IAC/D,MAAMC,gBAAgBD,QAAQE,UAAU,CAACC,gCAAgC;IACzE,MAAMC,eAAmC;QACvCC,WAAW,EAAE;IACf;IACA,MAAMV,YAAYD,+BAA+BO,iBAAiBA,gBAAgB;QAAEK,OAAOF;IAAa;IAExG,MAAME,QAAQX,sBAAAA,gCAAAA,UAAWW,KAAK;IAE9B,qBACE,KAACb,uBAAuBc,QAAQ;QAACC,OAAOF;kBACtC,cAAA,KAACP;;AAGP,EAAE"}
1
+ {"version":3,"sources":["../../../../src/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.tsx"],"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 { StoryFn, StoryContext } from '@storybook/react';\nimport { ReactElement } from 'react';\nimport { BuiltinVariableContext, BuiltinVariableSrv } from '../../../runtime';\n\ndeclare module '@storybook/react' {\n interface Parameters {\n withPluginSystemBuiltinVariables?: WithPluginSystemBuiltinVariableParameter;\n }\n}\n\nexport type WithPluginSystemBuiltinVariableParameter = {\n props: BuiltinVariableSrv;\n};\n\n// Type guard because storybook types parameters as `any`\nfunction isWithBuiltinVariableParameter(\n parameter: unknown | WithPluginSystemBuiltinVariableParameter\n): parameter is WithPluginSystemBuiltinVariableParameter {\n return !!parameter && Array.isArray(parameter);\n}\n\n// This decorator is used for non-dashboards package Builtin variable needs.\n// Use the more specific decorator in the dashboards package when working with\n// dashboards.\n// This decorator includes \"PluginSystem\" in the name to differentiate it from\n// the datasource store decorator in the `dashboards` package.\nexport const WithPluginSystemBuiltinVariables = (Story: StoryFn, context: StoryContext<unknown>): ReactElement => {\n const initParameter = context.parameters.withPluginSystemBuiltinVariables;\n const defaultValue: BuiltinVariableSrv = {\n variables: [],\n };\n const parameter = isWithBuiltinVariableParameter(initParameter) ? initParameter : { props: defaultValue };\n\n const props = parameter?.props;\n\n return (\n <BuiltinVariableContext.Provider value={props}>\n <Story />\n </BuiltinVariableContext.Provider>\n );\n};\n"],"names":["BuiltinVariableContext","isWithBuiltinVariableParameter","parameter","Array","isArray","WithPluginSystemBuiltinVariables","Story","context","initParameter","parameters","withPluginSystemBuiltinVariables","defaultValue","variables","props","Provider","value"],"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;;AAIjC,SAASA,sBAAsB,QAA4B,mBAAmB;AAY9E,yDAAyD;AACzD,SAASC,+BACPC,SAA6D;IAE7D,OAAO,CAAC,CAACA,aAAaC,MAAMC,OAAO,CAACF;AACtC;AAEA,4EAA4E;AAC5E,8EAA8E;AAC9E,cAAc;AACd,8EAA8E;AAC9E,8DAA8D;AAC9D,OAAO,MAAMG,mCAAmC,CAACC,OAAgBC;IAC/D,MAAMC,gBAAgBD,QAAQE,UAAU,CAACC,gCAAgC;IACzE,MAAMC,eAAmC;QACvCC,WAAW,EAAE;IACf;IACA,MAAMV,YAAYD,+BAA+BO,iBAAiBA,gBAAgB;QAAEK,OAAOF;IAAa;IAExG,MAAME,QAAQX,WAAWW;IAEzB,qBACE,KAACb,uBAAuBc,QAAQ;QAACC,OAAOF;kBACtC,cAAA,KAACP;;AAGP,EAAE"}