@perses-dev/plugin-system 0.38.0 → 0.40.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.
- package/dist/cjs/components/CalculationSelector/CalculationSelector.js +6 -4
- package/dist/cjs/components/CalculationSelector/index.js +10 -8
- package/dist/cjs/components/DatasourceEditorForm/DatasourceEditorForm.js +380 -0
- package/dist/cjs/components/DatasourceEditorForm/index.js +30 -0
- package/dist/cjs/components/DatasourceSelect.js +119 -21
- package/dist/cjs/components/LegendOptionsEditor/LegendOptionsEditor.js +18 -16
- package/dist/cjs/components/LegendOptionsEditor/index.js +10 -8
- package/dist/cjs/components/OptionsEditorRadios/OptionsEditorRadios.js +69 -0
- package/dist/cjs/components/OptionsEditorRadios/index.js +30 -0
- package/dist/cjs/components/{OptionsEditorTabs/TabPanel.js → OptionsEditorTabPanel/OptionsEditorTabPanel.js} +8 -6
- package/dist/cjs/components/OptionsEditorTabPanel/index.js +30 -0
- package/dist/cjs/components/OptionsEditorTabs/OptionsEditorTabs.js +10 -8
- package/dist/cjs/components/OptionsEditorTabs/index.js +10 -8
- package/dist/cjs/components/PanelSpecEditor/PanelSpecEditor.js +13 -11
- package/dist/cjs/components/PanelSpecEditor/index.js +10 -8
- package/dist/cjs/components/PluginEditor/PluginEditor.js +24 -31
- package/dist/cjs/components/PluginEditor/index.js +11 -9
- package/dist/cjs/components/PluginEditor/plugin-editor-api.js +5 -3
- package/dist/cjs/components/PluginKindSelect/PluginKindSelect.js +23 -12
- package/dist/cjs/components/PluginKindSelect/index.js +10 -8
- package/dist/cjs/components/PluginRegistry/PluginRegistry.js +11 -9
- package/dist/cjs/components/PluginRegistry/index.js +10 -8
- package/dist/cjs/components/PluginRegistry/plugin-indexes.js +6 -2
- package/dist/cjs/components/PluginSpecEditor/PluginSpecEditor.js +6 -4
- package/dist/cjs/components/PluginSpecEditor/index.js +10 -8
- package/dist/cjs/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.js +15 -13
- package/dist/cjs/components/TimeSeriesQueryEditor/TimeSeriesQueryInput.js +21 -19
- package/dist/cjs/components/TimeSeriesQueryEditor/index.js +10 -8
- package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +256 -166
- package/dist/cjs/components/Variables/VariableEditorForm/VariablePreview.js +32 -28
- package/dist/cjs/components/Variables/VariableEditorForm/index.js +11 -9
- package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +28 -32
- package/dist/cjs/components/Variables/index.js +11 -9
- package/dist/cjs/components/Variables/variable-model.js +17 -9
- package/dist/cjs/components/index.js +22 -18
- package/dist/cjs/constants/index.js +10 -8
- package/dist/cjs/constants/user-interface-text.js +3 -1
- package/dist/cjs/index.js +16 -13
- package/dist/cjs/model/index.js +17 -15
- package/dist/cjs/model/legend.js +32 -20
- package/dist/cjs/model/panels.js +2 -2
- package/dist/cjs/model/plugin-base.js +2 -2
- package/dist/cjs/model/plugin-loading.js +3 -1
- package/dist/cjs/runtime/DataQueriesProvider/DataQueriesProvider.js +55 -35
- package/dist/cjs/runtime/DataQueriesProvider/index.js +11 -9
- package/dist/cjs/runtime/DataQueriesProvider/model.js +61 -0
- package/dist/cjs/runtime/TimeRangeProvider/TimeRangeProvider.js +19 -11
- package/dist/cjs/runtime/TimeRangeProvider/index.js +11 -9
- package/dist/cjs/runtime/TimeRangeProvider/query-params.js +36 -18
- package/dist/cjs/runtime/builtin-variables.js +81 -0
- package/dist/cjs/runtime/datasources.js +29 -11
- package/dist/cjs/runtime/index.js +16 -13
- package/dist/cjs/runtime/plugin-registry.js +41 -11
- package/dist/cjs/runtime/template-variables.js +96 -4
- package/dist/cjs/runtime/time-series-queries.js +39 -27
- package/dist/cjs/stories/shared-utils/decorators/WithDataQueries.js +7 -5
- package/dist/cjs/stories/shared-utils/decorators/WithPluginRegistry.js +16 -14
- package/dist/cjs/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.js +42 -0
- package/dist/cjs/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.js +19 -13
- package/dist/cjs/stories/shared-utils/decorators/WithPluginSystemTemplateVariables.js +6 -4
- package/dist/cjs/stories/shared-utils/decorators/WithTimeRange.js +7 -5
- package/dist/cjs/stories/shared-utils/decorators/index.js +15 -12
- package/dist/cjs/stories/shared-utils/index.js +10 -8
- package/dist/cjs/test/index.js +11 -8
- package/dist/cjs/test/mock-data.js +57 -0
- package/dist/cjs/test/render.js +13 -11
- package/dist/cjs/test/test-plugins/bert/index.js +14 -10
- package/dist/cjs/test/test-plugins/ernie/index.js +13 -9
- package/dist/cjs/test/test-plugins/index.js +11 -9
- package/dist/cjs/test-utils/index.js +10 -8
- package/dist/cjs/test-utils/mock-plugin-registry.js +8 -4
- package/dist/cjs/utils/action.js +43 -0
- package/dist/cjs/utils/index.js +11 -8
- package/dist/cjs/utils/variables.js +26 -8
- package/dist/cjs/validation/datasource.js +30 -0
- package/dist/cjs/validation/index.js +32 -0
- package/dist/cjs/validation/resource.js +24 -0
- package/dist/cjs/validation/variable.js +29 -0
- package/dist/components/CalculationSelector/CalculationSelector.js.map +1 -1
- package/dist/components/CalculationSelector/index.js.map +1 -1
- package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts +15 -0
- package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts.map +1 -0
- package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js +333 -0
- package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js.map +1 -0
- package/dist/components/DatasourceEditorForm/index.d.ts +2 -0
- package/dist/components/DatasourceEditorForm/index.d.ts.map +1 -0
- package/dist/components/DatasourceEditorForm/index.js +15 -0
- package/dist/components/DatasourceEditorForm/index.js.map +1 -0
- package/dist/components/DatasourceSelect.d.ts +5 -0
- package/dist/components/DatasourceSelect.d.ts.map +1 -1
- package/dist/components/DatasourceSelect.js +102 -19
- package/dist/components/DatasourceSelect.js.map +1 -1
- package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js +2 -2
- package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js.map +1 -1
- package/dist/components/LegendOptionsEditor/index.js.map +1 -1
- package/dist/components/OptionsEditorRadios/OptionsEditorRadios.d.ts +16 -0
- package/dist/components/OptionsEditorRadios/OptionsEditorRadios.d.ts.map +1 -0
- package/dist/components/OptionsEditorRadios/OptionsEditorRadios.js +61 -0
- package/dist/components/OptionsEditorRadios/OptionsEditorRadios.js.map +1 -0
- package/dist/components/OptionsEditorRadios/index.d.ts +2 -0
- package/dist/components/OptionsEditorRadios/index.d.ts.map +1 -0
- package/dist/components/OptionsEditorRadios/index.js +15 -0
- package/dist/components/OptionsEditorRadios/index.js.map +1 -0
- package/dist/components/OptionsEditorTabPanel/OptionsEditorTabPanel.d.ts +9 -0
- package/dist/components/OptionsEditorTabPanel/OptionsEditorTabPanel.d.ts.map +1 -0
- package/dist/components/{OptionsEditorTabs/TabPanel.js → OptionsEditorTabPanel/OptionsEditorTabPanel.js} +2 -2
- package/dist/components/OptionsEditorTabPanel/OptionsEditorTabPanel.js.map +1 -0
- package/dist/components/OptionsEditorTabPanel/index.d.ts +2 -0
- package/dist/components/OptionsEditorTabPanel/index.d.ts.map +1 -0
- package/dist/components/OptionsEditorTabPanel/index.js +15 -0
- package/dist/components/OptionsEditorTabPanel/index.js.map +1 -0
- package/dist/components/OptionsEditorTabs/OptionsEditorTabs.js +2 -2
- package/dist/components/OptionsEditorTabs/OptionsEditorTabs.js.map +1 -1
- package/dist/components/OptionsEditorTabs/index.js.map +1 -1
- package/dist/components/PanelSpecEditor/PanelSpecEditor.js +2 -2
- package/dist/components/PanelSpecEditor/PanelSpecEditor.js.map +1 -1
- package/dist/components/PanelSpecEditor/index.js.map +1 -1
- package/dist/components/PluginEditor/PluginEditor.js +15 -24
- package/dist/components/PluginEditor/PluginEditor.js.map +1 -1
- package/dist/components/PluginEditor/index.js.map +1 -1
- package/dist/components/PluginEditor/plugin-editor-api.d.ts +1 -1
- package/dist/components/PluginEditor/plugin-editor-api.js +2 -2
- package/dist/components/PluginEditor/plugin-editor-api.js.map +1 -1
- package/dist/components/PluginKindSelect/PluginKindSelect.d.ts +3 -3
- package/dist/components/PluginKindSelect/PluginKindSelect.d.ts.map +1 -1
- package/dist/components/PluginKindSelect/PluginKindSelect.js +21 -12
- package/dist/components/PluginKindSelect/PluginKindSelect.js.map +1 -1
- package/dist/components/PluginKindSelect/index.js.map +1 -1
- package/dist/components/PluginRegistry/PluginRegistry.js +3 -3
- package/dist/components/PluginRegistry/PluginRegistry.js.map +1 -1
- package/dist/components/PluginRegistry/index.js.map +1 -1
- package/dist/components/PluginRegistry/plugin-indexes.js.map +1 -1
- package/dist/components/PluginSpecEditor/PluginSpecEditor.js.map +1 -1
- package/dist/components/PluginSpecEditor/index.js.map +1 -1
- package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.js +4 -4
- package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.js.map +1 -1
- package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryInput.js +1 -1
- package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryInput.js.map +1 -1
- package/dist/components/TimeSeriesQueryEditor/index.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts +10 -7
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +200 -112
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariablePreview.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/index.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts +5 -4
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +22 -30
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -1
- package/dist/components/Variables/index.js.map +1 -1
- package/dist/components/Variables/variable-model.js +3 -3
- package/dist/components/Variables/variable-model.js.map +1 -1
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +2 -0
- package/dist/components/index.js.map +1 -1
- package/dist/constants/index.js.map +1 -1
- package/dist/constants/user-interface-text.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/model/datasource.d.ts +2 -1
- package/dist/model/datasource.d.ts.map +1 -1
- package/dist/model/datasource.js.map +1 -1
- package/dist/model/index.js.map +1 -1
- package/dist/model/legend.d.ts +1 -1
- package/dist/model/legend.d.ts.map +1 -1
- package/dist/model/legend.js +14 -14
- package/dist/model/legend.js.map +1 -1
- package/dist/model/panels.js.map +1 -1
- package/dist/model/plugin-base.js.map +1 -1
- package/dist/model/plugin-loading.js.map +1 -1
- package/dist/runtime/DataQueriesProvider/DataQueriesProvider.d.ts +5 -5
- package/dist/runtime/DataQueriesProvider/DataQueriesProvider.d.ts.map +1 -1
- package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js +40 -28
- package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js.map +1 -1
- package/dist/runtime/DataQueriesProvider/index.js.map +1 -1
- package/dist/runtime/DataQueriesProvider/model.d.ts +17 -12
- package/dist/runtime/DataQueriesProvider/model.d.ts.map +1 -1
- package/dist/runtime/DataQueriesProvider/model.js +47 -1
- package/dist/runtime/DataQueriesProvider/model.js.map +1 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js.map +1 -1
- package/dist/runtime/TimeRangeProvider/index.js.map +1 -1
- package/dist/runtime/TimeRangeProvider/query-params.js +1 -1
- package/dist/runtime/TimeRangeProvider/query-params.js.map +1 -1
- package/dist/runtime/builtin-variables.d.ts +11 -0
- package/dist/runtime/builtin-variables.d.ts.map +1 -0
- package/dist/runtime/builtin-variables.js +59 -0
- package/dist/runtime/builtin-variables.js.map +1 -0
- package/dist/runtime/datasources.d.ts +14 -6
- package/dist/runtime/datasources.d.ts.map +1 -1
- package/dist/runtime/datasources.js +13 -6
- package/dist/runtime/datasources.js.map +1 -1
- package/dist/runtime/index.d.ts +1 -0
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +1 -0
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/plugin-registry.d.ts +2 -0
- package/dist/runtime/plugin-registry.d.ts.map +1 -1
- package/dist/runtime/plugin-registry.js +19 -2
- package/dist/runtime/plugin-registry.js.map +1 -1
- package/dist/runtime/template-variables.d.ts +62 -2
- package/dist/runtime/template-variables.d.ts.map +1 -1
- package/dist/runtime/template-variables.js +83 -1
- package/dist/runtime/template-variables.js.map +1 -1
- package/dist/runtime/time-series-queries.d.ts +3 -3
- package/dist/runtime/time-series-queries.d.ts.map +1 -1
- package/dist/runtime/time-series-queries.js +14 -12
- package/dist/runtime/time-series-queries.js.map +1 -1
- package/dist/stories/shared-utils/decorators/WithDataQueries.js.map +1 -1
- package/dist/stories/shared-utils/decorators/WithPluginRegistry.js.map +1 -1
- package/dist/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.d.ts +13 -0
- package/dist/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.d.ts.map +1 -0
- package/dist/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.js +39 -0
- package/dist/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.js.map +1 -0
- package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.d.ts.map +1 -1
- package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.js +11 -7
- package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.js.map +1 -1
- package/dist/stories/shared-utils/decorators/WithPluginSystemTemplateVariables.js.map +1 -1
- package/dist/stories/shared-utils/decorators/WithTimeRange.js.map +1 -1
- package/dist/stories/shared-utils/decorators/index.d.ts +1 -0
- package/dist/stories/shared-utils/decorators/index.d.ts.map +1 -1
- package/dist/stories/shared-utils/decorators/index.js +1 -0
- package/dist/stories/shared-utils/decorators/index.js.map +1 -1
- package/dist/stories/shared-utils/index.js.map +1 -1
- package/dist/test/index.d.ts +1 -0
- package/dist/test/index.d.ts.map +1 -1
- package/dist/test/index.js +1 -0
- package/dist/test/index.js.map +1 -1
- package/dist/test/mock-data.d.ts +3 -0
- package/dist/test/mock-data.d.ts.map +1 -0
- package/dist/test/mock-data.js +49 -0
- package/dist/test/mock-data.js.map +1 -0
- package/dist/test/render.js +2 -2
- package/dist/test/render.js.map +1 -1
- package/dist/test/setup-tests.js.map +1 -1
- package/dist/test/test-plugins/bert/index.js.map +1 -1
- package/dist/test/test-plugins/ernie/index.js.map +1 -1
- package/dist/test/test-plugins/index.js.map +1 -1
- package/dist/test-utils/index.js.map +1 -1
- package/dist/test-utils/mock-plugin-registry.js +2 -2
- package/dist/test-utils/mock-plugin-registry.js.map +1 -1
- package/dist/utils/action.d.ts +4 -0
- package/dist/utils/action.d.ts.map +1 -0
- package/dist/utils/action.js +27 -0
- package/dist/utils/action.js.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/variables.d.ts.map +1 -1
- package/dist/utils/variables.js +17 -5
- package/dist/utils/variables.js.map +1 -1
- package/dist/validation/datasource.d.ts +19 -0
- package/dist/validation/datasource.d.ts.map +1 -0
- package/dist/validation/datasource.js +22 -0
- package/dist/validation/datasource.js.map +1 -0
- package/dist/validation/index.d.ts +4 -0
- package/dist/validation/index.d.ts.map +1 -0
- package/dist/validation/index.js +17 -0
- package/dist/validation/index.js.map +1 -0
- package/dist/validation/resource.d.ts +3 -0
- package/dist/validation/resource.d.ts.map +1 -0
- package/dist/validation/resource.js +16 -0
- package/dist/validation/resource.js.map +1 -0
- package/dist/validation/variable.d.ts +19 -0
- package/dist/validation/variable.d.ts.map +1 -0
- package/dist/validation/variable.js +21 -0
- package/dist/validation/variable.js.map +1 -0
- package/package.json +8 -6
- package/dist/components/OptionsEditorTabs/TabPanel.d.ts +0 -9
- package/dist/components/OptionsEditorTabs/TabPanel.d.ts.map +0 -1
- package/dist/components/OptionsEditorTabs/TabPanel.js.map +0 -1
|
@@ -21,14 +21,14 @@ export function useDatasourceStore() {
|
|
|
21
21
|
return ctx;
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
|
-
* Lists all available Datasource
|
|
25
|
-
*
|
|
26
|
-
*/ export function
|
|
27
|
-
const {
|
|
24
|
+
* Lists all available Datasource selection items for a given datasource plugin kind.
|
|
25
|
+
* Returns a list, with all information that can be used in a datasource selection context (group, name, selector, kind, ...)
|
|
26
|
+
*/ export function useListDatasourceSelectItems(datasourcePluginKind) {
|
|
27
|
+
const { listDatasourceSelectItems } = useDatasourceStore();
|
|
28
28
|
return useQuery([
|
|
29
|
-
'
|
|
29
|
+
'listDatasourceSelectItems',
|
|
30
30
|
datasourcePluginKind
|
|
31
|
-
], ()=>
|
|
31
|
+
], ()=>listDatasourceSelectItems(datasourcePluginKind));
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
34
|
* Provides a convenience hook for getting a DatasourceClient for a given DatasourceSelector.
|
|
@@ -39,5 +39,12 @@ export function useDatasourceStore() {
|
|
|
39
39
|
selector
|
|
40
40
|
], ()=>store.getDatasourceClient(selector));
|
|
41
41
|
}
|
|
42
|
+
export function useDatasource(selector) {
|
|
43
|
+
const store = useDatasourceStore();
|
|
44
|
+
return useQuery([
|
|
45
|
+
'getDatasource',
|
|
46
|
+
selector
|
|
47
|
+
], ()=>store.getDatasource(selector));
|
|
48
|
+
}
|
|
42
49
|
|
|
43
50
|
//# sourceMappingURL=datasources.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/runtime/datasources.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DatasourceSelector, DatasourceSpec } from '@perses-dev/core';\nimport { useQuery } from '@tanstack/react-query';\nimport { createContext, useContext } from 'react';\n\nexport interface DatasourceStore {\n // TODO: Do we even need this method?\n getDatasource(selector: DatasourceSelector): Promise<DatasourceSpec>;\n\n /**\n * Given a DatasourceSelector, gets a `Client` object from the corresponding Datasource plugin.\n */\n getDatasourceClient<Client>(selector: DatasourceSelector): Promise<Client>;\n\n /**\n * Gets a list of datasource
|
|
1
|
+
{"version":3,"sources":["../../src/runtime/datasources.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DatasourceSelector, DatasourceSpec } from '@perses-dev/core';\nimport { useQuery } from '@tanstack/react-query';\nimport { createContext, useContext } from 'react';\n\nexport interface DatasourceStore {\n // TODO: Do we even need this method?\n getDatasource(selector: DatasourceSelector): Promise<DatasourceSpec>;\n\n /**\n * Given a DatasourceSelector, gets a `Client` object from the corresponding Datasource plugin.\n */\n getDatasourceClient<Client>(selector: DatasourceSelector): Promise<Client>;\n\n /**\n * Gets a list of datasource selection items for a plugin kind.\n */\n listDatasourceSelectItems(datasourcePluginKind: string): Promise<DatasourceSelectItemGroup[]>;\n}\n\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 selector: DatasourceSelector;\n}\n\nexport const DatasourceStoreContext = createContext<DatasourceStore | undefined>(undefined);\n\nexport function useDatasourceStore() {\n const ctx = useContext(DatasourceStoreContext);\n if (ctx === undefined) {\n throw new Error('No DatasourceStoreContext found. Did you forget a Provider?');\n }\n return ctx;\n}\n\n/**\n * Lists all available Datasource selection items for a given datasource plugin kind.\n * Returns a list, with all information that can be used in a datasource selection context (group, name, selector, kind, ...)\n */\nexport function useListDatasourceSelectItems(datasourcePluginKind: string) {\n const { listDatasourceSelectItems } = useDatasourceStore();\n return useQuery(['listDatasourceSelectItems', datasourcePluginKind], () =>\n listDatasourceSelectItems(datasourcePluginKind)\n );\n}\n\n/**\n * Provides a convenience hook for getting a DatasourceClient for a given DatasourceSelector.\n */\nexport function useDatasourceClient<Client>(selector: DatasourceSelector) {\n const store = useDatasourceStore();\n return useQuery<Client>(['getDatasourceClient', selector], () => store.getDatasourceClient<Client>(selector));\n}\n\nexport function useDatasource(selector: DatasourceSelector) {\n const store = useDatasourceStore();\n return useQuery(['getDatasource', selector], () => store.getDatasource(selector));\n}\n"],"names":["useQuery","createContext","useContext","DatasourceStoreContext","undefined","useDatasourceStore","ctx","Error","useListDatasourceSelectItems","datasourcePluginKind","listDatasourceSelectItems","useDatasourceClient","selector","store","getDatasourceClient","useDatasource","getDatasource"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAASA,QAAQ,QAAQ,wBAAwB;AACjD,SAASC,aAAa,EAAEC,UAAU,QAAQ,QAAQ;AA8BlD,OAAO,MAAMC,yBAAyBF,cAA2CG,WAAW;AAE5F,OAAO,SAASC;IACd,MAAMC,MAAMJ,WAAWC;IACvB,IAAIG,QAAQF,WAAW;QACrB,MAAM,IAAIG,MAAM;IAClB;IACA,OAAOD;AACT;AAEA;;;CAGC,GACD,OAAO,SAASE,6BAA6BC,oBAA4B;IACvE,MAAM,EAAEC,0BAAyB,EAAE,GAAGL;IACtC,OAAOL,SAAS;QAAC;QAA6BS;KAAqB,EAAE,IACnEC,0BAA0BD;AAE9B;AAEA;;CAEC,GACD,OAAO,SAASE,oBAA4BC,QAA4B;IACtE,MAAMC,QAAQR;IACd,OAAOL,SAAiB;QAAC;QAAuBY;KAAS,EAAE,IAAMC,MAAMC,oBAA4BF;AACrG;AAEA,OAAO,SAASG,cAAcH,QAA4B;IACxD,MAAMC,QAAQR;IACd,OAAOL,SAAS;QAAC;QAAiBY;KAAS,EAAE,IAAMC,MAAMG,cAAcJ;AACzE"}
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAaA,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAaA,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC"}
|
package/dist/runtime/index.js
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
+
export * from './builtin-variables';
|
|
13
14
|
export * from './datasources';
|
|
14
15
|
export * from './plugin-registry';
|
|
15
16
|
export * from './template-variables';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/runtime/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './datasources';\nexport * from './plugin-registry';\nexport * from './template-variables';\nexport * from './TimeRangeProvider';\nexport * from './time-series-queries';\nexport * from './DataQueriesProvider';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,
|
|
1
|
+
{"version":3,"sources":["../../src/runtime/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './builtin-variables';\nexport * from './datasources';\nexport * from './plugin-registry';\nexport * from './template-variables';\nexport * from './TimeRangeProvider';\nexport * from './time-series-queries';\nexport * from './DataQueriesProvider';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,sBAAsB;AACpC,cAAc,gBAAgB;AAC9B,cAAc,oBAAoB;AAClC,cAAc,uBAAuB;AACrC,cAAc,sBAAsB;AACpC,cAAc,wBAAwB;AACtC,cAAc,wBAAwB"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { UseQueryOptions } from '@tanstack/react-query';
|
|
3
|
+
import { BuiltinVariableDefinition } from '@perses-dev/core';
|
|
3
4
|
import { DefaultPluginKinds, PluginImplementation, PluginMetadata, PluginType } from '../model';
|
|
4
5
|
export interface PluginRegistryContextType {
|
|
5
6
|
getPlugin<T extends PluginType>(pluginType: T, kind: string): Promise<PluginImplementation<T>>;
|
|
@@ -28,5 +29,6 @@ declare type UseListPluginMetadataOptions = Omit<UseQueryOptions<PluginMetadata[
|
|
|
28
29
|
* Gets a list of plugin metadata for the specified plugin type and returns it, along with loading/error state.
|
|
29
30
|
*/
|
|
30
31
|
export declare function useListPluginMetadata(pluginType: PluginType, options?: UseListPluginMetadataOptions): import("@tanstack/react-query").UseQueryResult<PluginMetadata[], Error>;
|
|
32
|
+
export declare function usePluginBuiltinVariableDefinitions(): import("@tanstack/react-query").UseQueryResult<BuiltinVariableDefinition[], unknown>;
|
|
31
33
|
export {};
|
|
32
34
|
//# sourceMappingURL=plugin-registry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-registry.d.ts","sourceRoot":"","sources":["../../src/runtime/plugin-registry.ts"],"names":[],"mappings":";AAcA,OAAO,EAAwB,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC9E,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEh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AAe,CAAC,cAAc,EAAE,EAAE,KAAK,EAAE,cAAc,EAAE,EAAE,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,EAChF,UAAU,GAAG,SAAS,CACvB,CAAC;AAEF;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,4BAA4B,2EAGnG;AAED,wBAAgB,mCAAmC,yFAelD"}
|
|
@@ -26,11 +26,11 @@ 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
|
|
29
|
+
var _options_enabled;
|
|
30
30
|
// We never want to ask for a plugin when the kind isn't set yet, so disable those queries automatically
|
|
31
31
|
options = {
|
|
32
32
|
...options,
|
|
33
|
-
enabled: ((
|
|
33
|
+
enabled: ((_options_enabled = options === null || options === void 0 ? void 0 : options.enabled) !== null && _options_enabled !== void 0 ? _options_enabled : true) && kind !== ''
|
|
34
34
|
};
|
|
35
35
|
const { getPlugin } = usePluginRegistry();
|
|
36
36
|
return useQuery([
|
|
@@ -65,5 +65,22 @@ export const PluginRegistryContext = createContext(undefined);
|
|
|
65
65
|
pluginType
|
|
66
66
|
], ()=>listPluginMetadata(pluginType), options);
|
|
67
67
|
}
|
|
68
|
+
export function usePluginBuiltinVariableDefinitions() {
|
|
69
|
+
const { getPlugin , listPluginMetadata } = usePluginRegistry();
|
|
70
|
+
return useQuery([
|
|
71
|
+
'usePluginBuiltinVariableDefinitions'
|
|
72
|
+
], async ()=>{
|
|
73
|
+
const datasources = await listPluginMetadata('Datasource');
|
|
74
|
+
const datasourceKinds = new Set(datasources.map((datasource)=>datasource.kind));
|
|
75
|
+
const result = [];
|
|
76
|
+
for (const kind of datasourceKinds){
|
|
77
|
+
const plugin = await getPlugin('Datasource', kind);
|
|
78
|
+
if (plugin.getBuiltinVariableDefinitions) {
|
|
79
|
+
plugin.getBuiltinVariableDefinitions().forEach((definition)=>result.push(definition));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return result;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
68
85
|
|
|
69
86
|
//# sourceMappingURL=plugin-registry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/runtime/plugin-registry.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { createContext, useContext } from 'react';\nimport { useQuery, useQueries, UseQueryOptions } from '@tanstack/react-query';\nimport { DefaultPluginKinds, PluginImplementation, PluginMetadata, PluginType } from '../model';\n\nexport interface PluginRegistryContextType {\n getPlugin<T extends PluginType>(pluginType: T, kind: string): Promise<PluginImplementation<T>>;\n listPluginMetadata(pluginType: PluginType): Promise<PluginMetadata[]>;\n defaultPluginKinds: DefaultPluginKinds;\n}\n\nexport const PluginRegistryContext = createContext<PluginRegistryContextType | undefined>(undefined);\n\n/**\n * Use the PluginRegistry context directly. This is meant as an escape hatch for custom async flows. You should probably\n * be using `usePlugin` or `useListPluginMetadata` instead.\n */\nexport function usePluginRegistry() {\n const ctx = useContext(PluginRegistryContext);\n if (ctx === undefined) {\n throw new Error('PluginRegistryContext not found. Did you forget a provider?');\n }\n return ctx;\n}\n\n// Allows consumers to pass useQuery options from react-query when loading a plugin\ntype UsePluginOptions<T extends PluginType> = Omit<\n UseQueryOptions<PluginImplementation<T>, Error, PluginImplementation<T>, [string, PluginType, string]>,\n 'queryKey' | 'queryFn'\n>;\n\n/**\n * Loads a plugin and returns the plugin implementation, along with loading/error state.\n */\nexport function usePlugin<T extends PluginType>(pluginType: T, kind: string, options?: UsePluginOptions<T>) {\n // We never want to ask for a plugin when the kind isn't set yet, so disable those queries automatically\n options = {\n ...options,\n enabled: (options?.enabled ?? true) && kind !== '',\n };\n const { getPlugin } = usePluginRegistry();\n return useQuery(['getPlugin', pluginType, kind], () => getPlugin(pluginType, kind), options);\n}\n\n/**\n * Loads a list of plugins and returns the plugin implementation, along with loading/error state.\n */\nexport function usePlugins<T extends PluginType>(pluginType: T, plugins: Array<{ kind: string }>) {\n const { getPlugin } = usePluginRegistry();\n return useQueries({\n queries: plugins.map((p) => {\n return {\n queryKey: ['getPlugin', pluginType, p.kind],\n queryFn: () => getPlugin(pluginType, p.kind),\n };\n }),\n });\n}\n\n// Allow consumers to pass useQuery options from react-query when listing metadata\ntype UseListPluginMetadataOptions = Omit<\n UseQueryOptions<PluginMetadata[], Error, PluginMetadata[], [string, PluginType]>,\n 'queryKey' | 'queryFn'\n>;\n\n/**\n * Gets a list of plugin metadata for the specified plugin type and returns it, along with loading/error state.\n */\nexport function useListPluginMetadata(pluginType: PluginType, options?: UseListPluginMetadataOptions) {\n const { listPluginMetadata } = usePluginRegistry();\n return useQuery(['listPluginMetadata', pluginType], () => listPluginMetadata(pluginType), options);\n}\n"],"names":["createContext","useContext","useQuery","useQueries","PluginRegistryContext","undefined","usePluginRegistry","ctx","Error","usePlugin","pluginType","kind","options","enabled","getPlugin","usePlugins","plugins","queries","map","p","queryKey","queryFn","useListPluginMetadata","listPluginMetadata"],"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,
|
|
1
|
+
{"version":3,"sources":["../../src/runtime/plugin-registry.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { createContext, useContext } from 'react';\nimport { useQuery, useQueries, UseQueryOptions } from '@tanstack/react-query';\nimport { BuiltinVariableDefinition } from '@perses-dev/core';\nimport { DefaultPluginKinds, PluginImplementation, PluginMetadata, PluginType } from '../model';\n\nexport interface PluginRegistryContextType {\n getPlugin<T extends PluginType>(pluginType: T, kind: string): Promise<PluginImplementation<T>>;\n listPluginMetadata(pluginType: PluginType): Promise<PluginMetadata[]>;\n defaultPluginKinds: DefaultPluginKinds;\n}\n\nexport const PluginRegistryContext = createContext<PluginRegistryContextType | undefined>(undefined);\n\n/**\n * Use the PluginRegistry context directly. This is meant as an escape hatch for custom async flows. You should probably\n * be using `usePlugin` or `useListPluginMetadata` instead.\n */\nexport function usePluginRegistry() {\n const ctx = useContext(PluginRegistryContext);\n if (ctx === undefined) {\n throw new Error('PluginRegistryContext not found. Did you forget a provider?');\n }\n return ctx;\n}\n\n// Allows consumers to pass useQuery options from react-query when loading a plugin\ntype UsePluginOptions<T extends PluginType> = Omit<\n UseQueryOptions<PluginImplementation<T>, Error, PluginImplementation<T>, [string, PluginType, string]>,\n 'queryKey' | 'queryFn'\n>;\n\n/**\n * Loads a plugin and returns the plugin implementation, along with loading/error state.\n */\nexport function usePlugin<T extends PluginType>(pluginType: T, kind: string, options?: UsePluginOptions<T>) {\n // We never want to ask for a plugin when the kind isn't set yet, so disable those queries automatically\n options = {\n ...options,\n enabled: (options?.enabled ?? true) && kind !== '',\n };\n const { getPlugin } = usePluginRegistry();\n return useQuery(['getPlugin', pluginType, kind], () => getPlugin(pluginType, kind), options);\n}\n\n/**\n * Loads a list of plugins and returns the plugin implementation, along with loading/error state.\n */\nexport function usePlugins<T extends PluginType>(pluginType: T, plugins: Array<{ kind: string }>) {\n const { getPlugin } = usePluginRegistry();\n return useQueries({\n queries: plugins.map((p) => {\n return {\n queryKey: ['getPlugin', pluginType, p.kind],\n queryFn: () => getPlugin(pluginType, p.kind),\n };\n }),\n });\n}\n\n// Allow consumers to pass useQuery options from react-query when listing metadata\ntype UseListPluginMetadataOptions = Omit<\n UseQueryOptions<PluginMetadata[], Error, PluginMetadata[], [string, PluginType]>,\n 'queryKey' | 'queryFn'\n>;\n\n/**\n * Gets a list of plugin metadata for the specified plugin type and returns it, along with loading/error state.\n */\nexport function useListPluginMetadata(pluginType: PluginType, options?: UseListPluginMetadataOptions) {\n const { listPluginMetadata } = usePluginRegistry();\n return useQuery(['listPluginMetadata', pluginType], () => listPluginMetadata(pluginType), options);\n}\n\nexport function usePluginBuiltinVariableDefinitions() {\n const { getPlugin, listPluginMetadata } = usePluginRegistry();\n\n return useQuery(['usePluginBuiltinVariableDefinitions'], async () => {\n const datasources = await listPluginMetadata('Datasource');\n const datasourceKinds = new Set(datasources.map((datasource) => datasource.kind));\n const result: BuiltinVariableDefinition[] = [];\n for (const kind of datasourceKinds) {\n const plugin = await getPlugin('Datasource', kind);\n if (plugin.getBuiltinVariableDefinitions) {\n plugin.getBuiltinVariableDefinitions().forEach((definition) => result.push(definition));\n }\n }\n return result;\n });\n}\n"],"names":["createContext","useContext","useQuery","useQueries","PluginRegistryContext","undefined","usePluginRegistry","ctx","Error","usePlugin","pluginType","kind","options","enabled","getPlugin","usePlugins","plugins","queries","map","p","queryKey","queryFn","useListPluginMetadata","listPluginMetadata","usePluginBuiltinVariableDefinitions","datasources","datasourceKinds","Set","datasource","result","plugin","getBuiltinVariableDefinitions","forEach","definition","push"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,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,UAAS,EAAES,mBAAkB,EAAE,GAAGjB;IAE1C,OAAOJ,SAAS;QAAC;KAAsC,EAAE;QACvD,MAAMuB,cAAc,MAAMF,mBAAmB;QAC7C,MAAMG,kBAAkB,IAAIC,IAAIF,YAAYP,IAAI,CAACU,aAAeA,WAAWjB;QAC3E,MAAMkB,SAAsC,EAAE;QAC9C,KAAK,MAAMlB,QAAQe,gBAAiB;YAClC,MAAMI,SAAS,MAAMhB,UAAU,cAAcH;YAC7C,IAAImB,OAAOC,+BAA+B;gBACxCD,OAAOC,gCAAgCC,QAAQ,CAACC,aAAeJ,OAAOK,KAAKD;YAC7E;QACF;QACA,OAAOJ;IACT;AACF"}
|
|
@@ -1,17 +1,77 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import {
|
|
2
|
+
import { VariableValue } from '@perses-dev/core';
|
|
3
|
+
import { immerable } from 'immer';
|
|
3
4
|
import { VariableOption } from '../model';
|
|
4
5
|
export declare type VariableState = {
|
|
5
6
|
value: VariableValue;
|
|
6
7
|
options?: VariableOption[];
|
|
7
8
|
loading: boolean;
|
|
8
9
|
error?: Error;
|
|
10
|
+
/**
|
|
11
|
+
* If a local variable is overriding an external variable, local var will have the flag ``overriding=true``.
|
|
12
|
+
*/
|
|
13
|
+
overriding?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* If a local variable is overriding an external variable, external var will have the flag ``overridden=true``.
|
|
16
|
+
*/
|
|
17
|
+
overridden?: boolean;
|
|
18
|
+
defaultValue?: VariableValue;
|
|
9
19
|
};
|
|
10
|
-
export declare type VariableStateMap = Record<
|
|
20
|
+
export declare type VariableStateMap = Record<string, VariableState>;
|
|
21
|
+
/**
|
|
22
|
+
* Structure used as key in the {@link VariableStoreStateMap}.
|
|
23
|
+
*/
|
|
24
|
+
export declare type VariableStateKey = {
|
|
25
|
+
/**
|
|
26
|
+
* name of the variable we want to access in the state.
|
|
27
|
+
*/
|
|
28
|
+
name: string;
|
|
29
|
+
/**
|
|
30
|
+
* source of the variable we want to access in the state.
|
|
31
|
+
* Defined only for external variables.
|
|
32
|
+
*/
|
|
33
|
+
source?: string;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* A state map with two entry keys, materialized by {@link VariableStateKey} structure.
|
|
37
|
+
*/
|
|
38
|
+
export declare class VariableStoreStateMap {
|
|
39
|
+
/**
|
|
40
|
+
* "Immerable" is mandatory to be able to use this class in an immer context.
|
|
41
|
+
* Ref: https://docs.pmnd.rs/zustand/integrations/immer-middleware#gotchas
|
|
42
|
+
*/
|
|
43
|
+
[immerable]: boolean;
|
|
44
|
+
private readonly DEFAULT_LOCAL_SOURCE_NAME;
|
|
45
|
+
private readonly _state;
|
|
46
|
+
/**
|
|
47
|
+
* Get variable state by key.
|
|
48
|
+
* @param key
|
|
49
|
+
*/
|
|
50
|
+
get(key: VariableStateKey): VariableState | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Set variable state by key.
|
|
53
|
+
* @param key
|
|
54
|
+
* @param value
|
|
55
|
+
*/
|
|
56
|
+
set(key: VariableStateKey, value: VariableState): VariableState | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Check presence of variable state by key.
|
|
59
|
+
* @param key
|
|
60
|
+
*/
|
|
61
|
+
has(key: VariableStateKey): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Delete variable state by key.
|
|
64
|
+
* @param key
|
|
65
|
+
*/
|
|
66
|
+
delete(key: VariableStateKey): boolean;
|
|
67
|
+
private _sourceName;
|
|
68
|
+
private _sourceStatesOrEmpty;
|
|
69
|
+
}
|
|
11
70
|
export declare type TemplateVariableSrv = {
|
|
12
71
|
state: VariableStateMap;
|
|
13
72
|
};
|
|
14
73
|
export declare const TemplateVariableContext: import("react").Context<TemplateVariableSrv | undefined>;
|
|
15
74
|
export declare function useTemplateVariableValues(names?: string[]): VariableStateMap;
|
|
75
|
+
export declare function useVariableValues(names?: string[]): VariableStateMap;
|
|
16
76
|
export declare function useReplaceVariablesInString(str: string | undefined): string | undefined;
|
|
17
77
|
//# sourceMappingURL=template-variables.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template-variables.d.ts","sourceRoot":"","sources":["../../src/runtime/template-variables.ts"],"names":[],"mappings":";AAcA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"template-variables.d.ts","sourceRoot":"","sources":["../../src/runtime/template-variables.ts"],"names":[],"mappings":";AAcA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAI1C,oBAAY,aAAa,GAAG;IAC1B,KAAK,EAAE,aAAa,CAAC;IACrB,OAAO,CAAC,EAAE,cAAc,EAAE,CAAC;IAC3B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,YAAY,CAAC,EAAE,aAAa,CAAC;CAC9B,CAAC;AAEF,oBAAY,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;AAE7D;;GAEG;AACH,oBAAY,gBAAgB,GAAG;IAC7B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;GAEG;AACH,qBAAa,qBAAqB;IAChC;;;OAGG;IACH,CAAC,SAAS,CAAC,UAAQ;IAEnB,OAAO,CAAC,QAAQ,CAAC,yBAAyB,CAAM;IAChD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqD;IAE5E;;;OAGG;IACH,GAAG,CAAC,GAAG,EAAE,gBAAgB,GAAG,aAAa,GAAG,SAAS;IAIrD;;;;OAIG;IACH,GAAG,CAAC,GAAG,EAAE,gBAAgB,EAAE,KAAK,EAAE,aAAa,GAAG,aAAa,GAAG,SAAS;IAS3E;;;OAGG;IACH,GAAG,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO;IAInC;;;OAGG;IACH,MAAM,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO;IAiBtC,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,oBAAoB;CAG7B;AAED,oBAAY,mBAAmB,GAAG;IAChC,KAAK,EAAE,gBAAgB,CAAC;CACzB,CAAC;AAEF,eAAO,MAAM,uBAAuB,0DAA4D,CAAC;AAUjG,wBAAgB,yBAAyB,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,gBAAgB,CAmB5E;AAED,wBAAgB,iBAAiB,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,gBAAgB,CAKpE;AAGD,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAKvF"}
|
|
@@ -10,8 +10,85 @@
|
|
|
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
|
+
}
|
|
13
26
|
import { createContext, useContext, useMemo } from 'react';
|
|
27
|
+
import { immerable } from 'immer';
|
|
14
28
|
import { parseTemplateVariables, replaceTemplateVariables } from '../utils';
|
|
29
|
+
import { useBuiltinVariableValues } from './builtin-variables';
|
|
30
|
+
let _immerable = immerable;
|
|
31
|
+
/**
|
|
32
|
+
* A state map with two entry keys, materialized by {@link VariableStateKey} structure.
|
|
33
|
+
*/ export class VariableStoreStateMap {
|
|
34
|
+
/**
|
|
35
|
+
* Get variable state by key.
|
|
36
|
+
* @param key
|
|
37
|
+
*/ get(key) {
|
|
38
|
+
return this._sourceStatesOrEmpty(key.source)[key.name];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Set variable state by key.
|
|
42
|
+
* @param key
|
|
43
|
+
* @param value
|
|
44
|
+
*/ set(key, value) {
|
|
45
|
+
const sourceName = this._sourceName(key.source);
|
|
46
|
+
if (!this._state[sourceName]) {
|
|
47
|
+
this._state[sourceName] = {};
|
|
48
|
+
}
|
|
49
|
+
this._sourceStatesOrEmpty(key.source)[key.name] = value;
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Check presence of variable state by key.
|
|
54
|
+
* @param key
|
|
55
|
+
*/ has(key) {
|
|
56
|
+
return this._sourceStatesOrEmpty(key.source)[key.name] !== undefined;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Delete variable state by key.
|
|
60
|
+
* @param key
|
|
61
|
+
*/ delete(key) {
|
|
62
|
+
var _Object_keys;
|
|
63
|
+
const result = this.has(key);
|
|
64
|
+
const sourceName = this._sourceName(key.source);
|
|
65
|
+
const sourceStates = this._state[sourceName];
|
|
66
|
+
// Delete var from source state
|
|
67
|
+
if (sourceStates) {
|
|
68
|
+
delete sourceStates[key.name];
|
|
69
|
+
}
|
|
70
|
+
// 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) {
|
|
72
|
+
delete this._state[sourceName];
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
_sourceName(source) {
|
|
77
|
+
return source !== null && source !== void 0 ? source : this.DEFAULT_LOCAL_SOURCE_NAME;
|
|
78
|
+
}
|
|
79
|
+
_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", {});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
15
92
|
export const TemplateVariableContext = createContext(undefined);
|
|
16
93
|
function useTemplateVariableContext() {
|
|
17
94
|
const ctx = useContext(TemplateVariableContext);
|
|
@@ -40,10 +117,15 @@ export function useTemplateVariableValues(names) {
|
|
|
40
117
|
}
|
|
41
118
|
return values;
|
|
42
119
|
}
|
|
120
|
+
export function useVariableValues(names) {
|
|
121
|
+
const templateVariableValues = useTemplateVariableValues(names);
|
|
122
|
+
const builtinVariableValues = useBuiltinVariableValues(names);
|
|
123
|
+
return Object.assign(templateVariableValues, builtinVariableValues);
|
|
124
|
+
}
|
|
43
125
|
// Convenience hook for replacing template variables in a string
|
|
44
126
|
export function useReplaceVariablesInString(str) {
|
|
45
127
|
const variablesInString = str ? parseTemplateVariables(str) : [];
|
|
46
|
-
const variableValues =
|
|
128
|
+
const variableValues = useVariableValues(variablesInString);
|
|
47
129
|
if (!str) return undefined;
|
|
48
130
|
return replaceTemplateVariables(str, variableValues);
|
|
49
131
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/runtime/template-variables.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, useMemo } from 'react';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/runtime/template-variables.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, useMemo } from 'react';\nimport { VariableValue } from '@perses-dev/core';\nimport { immerable } from 'immer';\nimport { VariableOption } from '../model';\nimport { parseTemplateVariables, replaceTemplateVariables } 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 TemplateVariableSrv = {\n state: VariableStateMap;\n};\n\nexport const TemplateVariableContext = createContext<TemplateVariableSrv | undefined>(undefined);\n\nfunction useTemplateVariableContext() {\n const ctx = useContext(TemplateVariableContext);\n if (ctx === undefined) {\n throw new Error('No TemplateVariableContext found. Did you forget a Provider?');\n }\n return ctx;\n}\n\nexport function useTemplateVariableValues(names?: string[]): VariableStateMap {\n const { state } = useTemplateVariableContext();\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\nexport function useVariableValues(names?: string[]): VariableStateMap {\n const templateVariableValues = useTemplateVariableValues(names);\n const builtinVariableValues = useBuiltinVariableValues(names);\n\n return Object.assign(templateVariableValues, builtinVariableValues);\n}\n\n// Convenience hook for replacing template variables in a string\nexport function useReplaceVariablesInString(str: string | undefined): string | undefined {\n const variablesInString = str ? parseTemplateVariables(str) : [];\n const variableValues = useVariableValues(variablesInString);\n if (!str) return undefined;\n return replaceTemplateVariables(str, variableValues);\n}\n"],"names":["createContext","useContext","useMemo","immerable","parseTemplateVariables","replaceTemplateVariables","useBuiltinVariableValues","VariableStoreStateMap","get","key","_sourceStatesOrEmpty","source","name","set","value","sourceName","_sourceName","_state","has","undefined","delete","Object","result","sourceStates","keys","length","DEFAULT_LOCAL_SOURCE_NAME","TemplateVariableContext","useTemplateVariableContext","ctx","Error","useTemplateVariableValues","names","state","values","forEach","s","useVariableValues","templateVariableValues","builtinVariableValues","assign","useReplaceVariablesInString","str","variablesInString","variableValues"],"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,sBAAsB,EAAEC,wBAAwB,QAAQ,WAAW;AAC5E,SAASC,wBAAwB,QAAQ,sBAAsB;IA2C5DH,aAAAA;AARH;;CAEC,GACD,OAAO,MAAMI;IAUX;;;GAGC,GACDC,IAAIC,GAAqB,EAA6B;QACpD,OAAO,IAAI,CAACC,qBAAqBD,IAAIE,OAAO,CAACF,IAAIG,KAAK;IACxD;IAEA;;;;GAIC,GACDC,IAAIJ,GAAqB,EAAEK,KAAoB,EAA6B;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G,SAASS;IACP,MAAMC,MAAM5B,WAAW0B;IACvB,IAAIE,QAAQV,WAAW;QACrB,MAAM,IAAIW,MAAM;IAClB;IACA,OAAOD;AACT;AAEA,OAAO,SAASE,0BAA0BC,KAAgB;IACxD,MAAM,EAAEC,MAAK,EAAE,GAAGL;IAElB,MAAMM,SAAShC,QAAQ;QACrB,MAAMgC,SAA2B,CAAC;QAClCF,kBAAAA,mBAAAA,KAAAA,IAAAA,MAAOG,QAAQ,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,OAAO,SAASG,kBAAkBL,KAAgB;IAChD,MAAMM,yBAAyBP,0BAA0BC;IACzD,MAAMO,wBAAwBjC,yBAAyB0B;IAEvD,OAAOX,OAAOmB,OAAOF,wBAAwBC;AAC/C;AAEA,gEAAgE;AAChE,OAAO,SAASE,4BAA4BC,GAAuB;IACjE,MAAMC,oBAAoBD,MAAMtC,uBAAuBsC,OAAO,EAAE;IAChE,MAAME,iBAAiBP,kBAAkBM;IACzC,IAAI,CAACD,KAAK,OAAOvB;IACjB,OAAOd,yBAAyBqC,KAAKE;AACvC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { QueryCache } from '@tanstack/react-query';
|
|
1
|
+
import { QueryCache, QueryObserverOptions } from '@tanstack/react-query';
|
|
2
2
|
import { TimeSeriesQueryDefinition, TimeSeriesData } from '@perses-dev/core';
|
|
3
3
|
import { TimeSeriesDataQuery } from '../model';
|
|
4
4
|
export interface UseTimeSeriesQueryOptions {
|
|
@@ -8,11 +8,11 @@ export declare const TIME_SERIES_QUERY_KEY = "TimeSeriesQuery";
|
|
|
8
8
|
/**
|
|
9
9
|
* Runs a time series query using a plugin and returns the results.
|
|
10
10
|
*/
|
|
11
|
-
export declare const useTimeSeriesQuery: (definition: TimeSeriesQueryDefinition, options?: UseTimeSeriesQueryOptions) => import("@tanstack/react-query").UseQueryResult<TimeSeriesData, unknown>;
|
|
11
|
+
export declare const useTimeSeriesQuery: (definition: TimeSeriesQueryDefinition, options?: UseTimeSeriesQueryOptions, queryOptions?: QueryObserverOptions) => import("@tanstack/react-query").UseQueryResult<TimeSeriesData, unknown>;
|
|
12
12
|
/**
|
|
13
13
|
* Runs multiple time series queries using plugins and returns the results.
|
|
14
14
|
*/
|
|
15
|
-
export declare function useTimeSeriesQueries(definitions: TimeSeriesQueryDefinition[], options?: UseTimeSeriesQueryOptions): import("@tanstack/react-query").UseQueryResult<TimeSeriesData, unknown>[];
|
|
15
|
+
export declare function useTimeSeriesQueries(definitions: TimeSeriesQueryDefinition[], options?: UseTimeSeriesQueryOptions, queryOptions?: QueryObserverOptions): import("@tanstack/react-query").UseQueryResult<TimeSeriesData, unknown>[];
|
|
16
16
|
/**
|
|
17
17
|
* Get active time series queries for query results summary
|
|
18
18
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time-series-queries.d.ts","sourceRoot":"","sources":["../../src/runtime/time-series-queries.ts"],"names":[],"mappings":"AAaA,OAAO,
|
|
1
|
+
{"version":3,"file":"time-series-queries.d.ts","sourceRoot":"","sources":["../../src/runtime/time-series-queries.ts"],"names":[],"mappings":"AAaA,OAAO,EAKL,UAAU,EAEV,oBAAoB,EACrB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,yBAAyB,EAAe,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC1F,OAAO,EAAE,mBAAmB,EAAiD,MAAM,UAAU,CAAC;AAM9F,MAAM,WAAW,yBAAyB;IACxC,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,eAAO,MAAM,qBAAqB,oBAAoB,CAAC;AAmDvD;;GAEG;AACH,eAAO,MAAM,kBAAkB,eACjB,yBAAyB,YAC3B,yBAAyB,iBACpB,oBAAoB,4EAoBpC,CAAC;AAEF;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,yBAAyB,EAAE,EACxC,OAAO,CAAC,EAAE,yBAAyB,EACnC,YAAY,CAAC,EAAE,oBAAoB,6EA4BpC;AAmBD;;GAEG;AACH,wBAAgB,0BAA0B,0BAIzC;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,UAAU,yBAW3D"}
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { useQuery, useQueries, useQueryClient } from '@tanstack/react-query';
|
|
14
|
-
import {
|
|
14
|
+
import { useVariableValues } from './template-variables';
|
|
15
15
|
import { useTimeRange } from './TimeRangeProvider';
|
|
16
16
|
import { useDatasourceStore } from './datasources';
|
|
17
17
|
import { usePlugin, usePluginRegistry, usePlugins } from './plugin-registry';
|
|
@@ -46,8 +46,8 @@ function getQueryOptions({ plugin , definition , context }) {
|
|
|
46
46
|
let waitToLoad = false;
|
|
47
47
|
if (variableDependencies) {
|
|
48
48
|
waitToLoad = variableDependencies.some((v)=>{
|
|
49
|
-
var
|
|
50
|
-
return (
|
|
49
|
+
var _variableState_v;
|
|
50
|
+
return (_variableState_v = variableState[v]) === null || _variableState_v === void 0 ? void 0 : _variableState_v.loading;
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
53
|
const queryEnabled = plugin !== undefined && !waitToLoad;
|
|
@@ -58,7 +58,7 @@ function getQueryOptions({ plugin , definition , context }) {
|
|
|
58
58
|
}
|
|
59
59
|
/**
|
|
60
60
|
* Runs a time series query using a plugin and returns the results.
|
|
61
|
-
*/ export const useTimeSeriesQuery = (definition, options)=>{
|
|
61
|
+
*/ export const useTimeSeriesQuery = (definition, options, queryOptions)=>{
|
|
62
62
|
const { data: plugin } = usePlugin(TIME_SERIES_QUERY_KEY, definition.spec.plugin.kind);
|
|
63
63
|
const context = useTimeSeriesQueryContext();
|
|
64
64
|
const { queryEnabled , queryKey } = getQueryOptions({
|
|
@@ -66,8 +66,9 @@ function getQueryOptions({ plugin , definition , context }) {
|
|
|
66
66
|
definition,
|
|
67
67
|
context
|
|
68
68
|
});
|
|
69
|
+
var _queryOptions_enabled;
|
|
69
70
|
return useQuery({
|
|
70
|
-
enabled: queryEnabled,
|
|
71
|
+
enabled: ((_queryOptions_enabled = queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.enabled) !== null && _queryOptions_enabled !== void 0 ? _queryOptions_enabled : true) || queryEnabled,
|
|
71
72
|
queryKey: queryKey,
|
|
72
73
|
refetchInterval: context.refreshIntervalInMs > 0 ? context.refreshIntervalInMs : false,
|
|
73
74
|
queryFn: ()=>{
|
|
@@ -86,7 +87,7 @@ function getQueryOptions({ plugin , definition , context }) {
|
|
|
86
87
|
};
|
|
87
88
|
/**
|
|
88
89
|
* Runs multiple time series queries using plugins and returns the results.
|
|
89
|
-
*/ export function useTimeSeriesQueries(definitions, options) {
|
|
90
|
+
*/ export function useTimeSeriesQueries(definitions, options, queryOptions) {
|
|
90
91
|
const { getPlugin } = usePluginRegistry();
|
|
91
92
|
const context = useTimeSeriesQueryContext();
|
|
92
93
|
const pluginLoaderResponse = usePlugins(TIME_SERIES_QUERY_KEY, definitions.map((d)=>({
|
|
@@ -94,15 +95,16 @@ function getQueryOptions({ plugin , definition , context }) {
|
|
|
94
95
|
})));
|
|
95
96
|
return useQueries({
|
|
96
97
|
queries: definitions.map((definition, idx)=>{
|
|
97
|
-
var
|
|
98
|
-
const plugin = (
|
|
98
|
+
var _pluginLoaderResponse_idx;
|
|
99
|
+
const plugin = (_pluginLoaderResponse_idx = pluginLoaderResponse[idx]) === null || _pluginLoaderResponse_idx === void 0 ? void 0 : _pluginLoaderResponse_idx.data;
|
|
99
100
|
const { queryEnabled , queryKey } = getQueryOptions({
|
|
100
101
|
plugin,
|
|
101
102
|
definition,
|
|
102
103
|
context
|
|
103
104
|
});
|
|
105
|
+
var _queryOptions_enabled;
|
|
104
106
|
return {
|
|
105
|
-
enabled: queryEnabled,
|
|
107
|
+
enabled: ((_queryOptions_enabled = queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.enabled) !== null && _queryOptions_enabled !== void 0 ? _queryOptions_enabled : true) && queryEnabled,
|
|
106
108
|
queryKey: queryKey,
|
|
107
109
|
refetchInterval: context.refreshIntervalInMs > 0 ? context.refreshIntervalInMs : undefined,
|
|
108
110
|
queryFn: async ()=>{
|
|
@@ -123,7 +125,7 @@ function getQueryOptions({ plugin , definition , context }) {
|
|
|
123
125
|
* Build the time series query context object from data available at runtime
|
|
124
126
|
*/ function useTimeSeriesQueryContext() {
|
|
125
127
|
const { absoluteTimeRange , refreshKey , refreshIntervalInMs } = useTimeRange();
|
|
126
|
-
const variableState =
|
|
128
|
+
const variableState = useVariableValues();
|
|
127
129
|
const datasourceStore = useDatasourceStore();
|
|
128
130
|
return {
|
|
129
131
|
timeRange: absoluteTimeRange,
|
|
@@ -147,8 +149,8 @@ function getQueryOptions({ plugin , definition , context }) {
|
|
|
147
149
|
for (const query of cache.findAll({
|
|
148
150
|
type: 'active'
|
|
149
151
|
})){
|
|
150
|
-
var
|
|
151
|
-
const firstPart = (
|
|
152
|
+
var _query_queryKey;
|
|
153
|
+
const firstPart = (_query_queryKey = query.queryKey) === null || _query_queryKey === void 0 ? void 0 : _query_queryKey[0];
|
|
152
154
|
if ((firstPart === null || firstPart === void 0 ? void 0 : firstPart.kind) && firstPart.kind.startsWith(TIME_SERIES_QUERY_KEY)) {
|
|
153
155
|
queries.push(query);
|
|
154
156
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/runtime/time-series-queries.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useQuery, useQueries, useQueryClient, Query, QueryCache, QueryKey } from '@tanstack/react-query';\nimport { TimeSeriesQueryDefinition, UnknownSpec, TimeSeriesData } from '@perses-dev/core';\nimport { TimeSeriesDataQuery, TimeSeriesQueryContext, TimeSeriesQueryPlugin } from '../model';\nimport { VariableStateMap, useTemplateVariableValues } from './template-variables';\nimport { useTimeRange } from './TimeRangeProvider';\nimport { useDatasourceStore } from './datasources';\nimport { usePlugin, usePluginRegistry, usePlugins } from './plugin-registry';\n\nexport interface UseTimeSeriesQueryOptions {\n suggestedStepMs?: number;\n}\n\nexport const TIME_SERIES_QUERY_KEY = 'TimeSeriesQuery';\n\n/**\n * Returns a serialized string of the current state of variable values.\n */\nfunction getVariableValuesKey(v: VariableStateMap) {\n return Object.values(v)\n .map((v) => JSON.stringify(v.value))\n .join(',');\n}\n\nfunction filterVariableStateMap(v: VariableStateMap, names?: string[]) {\n if (!names) {\n return v;\n }\n return Object.fromEntries(Object.entries(v).filter(([name]) => names.includes(name)));\n}\n\nfunction getQueryOptions({\n plugin,\n definition,\n context,\n}: {\n plugin?: TimeSeriesQueryPlugin;\n definition: TimeSeriesQueryDefinition;\n context: TimeSeriesQueryContext;\n}) {\n const { timeRange, datasourceStore, suggestedStepMs, variableState, refreshKey } = context;\n\n const dependencies = plugin?.dependsOn ? plugin.dependsOn(definition.spec.plugin.spec, context) : {};\n const variableDependencies = dependencies?.variables;\n\n // Determine queryKey\n const filteredVariabledState = filterVariableStateMap(variableState, variableDependencies);\n const variablesValueKey = getVariableValuesKey(filteredVariabledState);\n const queryKey = [definition, timeRange, datasourceStore, suggestedStepMs, variablesValueKey, refreshKey] as const;\n\n // Determine queryEnabled\n let waitToLoad = false;\n if (variableDependencies) {\n waitToLoad = variableDependencies.some((v) => variableState[v]?.loading);\n }\n\n const queryEnabled = plugin !== undefined && !waitToLoad;\n\n return {\n queryKey,\n queryEnabled,\n };\n}\n\n/**\n * Runs a time series query using a plugin and returns the results.\n */\nexport const useTimeSeriesQuery = (definition: TimeSeriesQueryDefinition, options?: UseTimeSeriesQueryOptions) => {\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: queryEnabled,\n queryKey: queryKey,\n refetchInterval: context.refreshIntervalInMs > 0 ? context.refreshIntervalInMs : false,\n queryFn: () => {\n // The 'enabled' option should prevent this from happening, but make TypeScript happy by checking\n if (plugin === undefined) {\n throw new Error('Expected plugin to be loaded');\n }\n // Keep options out of query key so we don't re-run queries because suggested step changes\n const ctx: TimeSeriesQueryContext = { ...context, suggestedStepMs: options?.suggestedStepMs };\n return plugin.getTimeSeriesData(definition.spec.plugin.spec, ctx);\n },\n });\n};\n\n/**\n * Runs multiple time series queries using plugins and returns the results.\n */\nexport function useTimeSeriesQueries(definitions: TimeSeriesQueryDefinition[], options?: UseTimeSeriesQueryOptions) {\n const { getPlugin } = usePluginRegistry();\n const context = useTimeSeriesQueryContext();\n\n const pluginLoaderResponse = usePlugins(\n TIME_SERIES_QUERY_KEY,\n definitions.map((d) => ({ kind: d.spec.plugin.kind }))\n );\n\n return useQueries({\n queries: definitions.map((definition, idx) => {\n const plugin = pluginLoaderResponse[idx]?.data;\n const { queryEnabled, queryKey } = getQueryOptions({ plugin, definition, context });\n return {\n enabled: queryEnabled,\n queryKey: queryKey,\n refetchInterval: context.refreshIntervalInMs > 0 ? context.refreshIntervalInMs : undefined,\n queryFn: async () => {\n // Keep options out of query key so we don't re-run queries because suggested step changes\n const ctx: TimeSeriesQueryContext = { ...context, suggestedStepMs: options?.suggestedStepMs };\n const plugin = await getPlugin(TIME_SERIES_QUERY_KEY, definition.spec.plugin.kind);\n const data = await plugin.getTimeSeriesData(definition.spec.plugin.spec, ctx);\n return data;\n },\n };\n }),\n });\n}\n\n/**\n * Build the time series query context object from data available at runtime\n */\nfunction useTimeSeriesQueryContext(): TimeSeriesQueryContext {\n const { absoluteTimeRange, refreshKey, refreshIntervalInMs } = useTimeRange();\n const variableState = useTemplateVariableValues();\n const datasourceStore = useDatasourceStore();\n\n return {\n timeRange: absoluteTimeRange,\n variableState,\n datasourceStore,\n refreshKey,\n refreshIntervalInMs: refreshIntervalInMs,\n };\n}\n\n/**\n * Get active time series queries for query results summary\n */\nexport function useActiveTimeSeriesQueries() {\n const queryClient = useQueryClient();\n const queryCache = queryClient.getQueryCache();\n return getActiveTimeSeriesQueries(queryCache);\n}\n\n/**\n * Filter all cached queries down to only active time series queries\n */\nexport function getActiveTimeSeriesQueries(cache: QueryCache) {\n const queries: TimeSeriesDataQuery[] = [];\n\n for (const query of cache.findAll({ type: 'active' })) {\n const firstPart = query.queryKey?.[0] as UnknownSpec;\n if (firstPart?.kind && (firstPart.kind as string).startsWith(TIME_SERIES_QUERY_KEY)) {\n queries.push(query as Query<TimeSeriesData, unknown, TimeSeriesData, QueryKey>);\n }\n }\n\n return queries;\n}\n"],"names":["useQuery","useQueries","useQueryClient","useTemplateVariableValues","useTimeRange","useDatasourceStore","usePlugin","usePluginRegistry","usePlugins","TIME_SERIES_QUERY_KEY","getVariableValuesKey","v","Object","values","map","JSON","stringify","value","join","filterVariableStateMap","names","fromEntries","entries","filter","name","includes","getQueryOptions","plugin","definition","context","timeRange","datasourceStore","suggestedStepMs","variableState","refreshKey","dependencies","dependsOn","spec","variableDependencies","variables","filteredVariabledState","variablesValueKey","queryKey","waitToLoad","some","loading","queryEnabled","undefined","useTimeSeriesQuery","options","data","kind","useTimeSeriesQueryContext","enabled","refetchInterval","refreshIntervalInMs","queryFn","Error","ctx","getTimeSeriesData","useTimeSeriesQueries","definitions","getPlugin","pluginLoaderResponse","d","queries","idx","absoluteTimeRange","useActiveTimeSeriesQueries","queryClient","queryCache","getQueryCache","getActiveTimeSeriesQueries","cache","query","findAll","type","firstPart","startsWith","push"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,QAAQ,EAAEC,UAAU,EAAEC,cAAc,QAAqC,uBAAuB,CAAC;AAG1G,SAA2BC,yBAAyB,QAAQ,sBAAsB,CAAC;AACnF,SAASC,YAAY,QAAQ,qBAAqB,CAAC;AACnD,SAASC,kBAAkB,QAAQ,eAAe,CAAC;AACnD,SAASC,SAAS,EAAEC,iBAAiB,EAAEC,UAAU,QAAQ,mBAAmB,CAAC;AAM7E,OAAO,MAAMC,qBAAqB,GAAG,iBAAiB,CAAC;AAEvD;;CAEC,GACD,SAASC,oBAAoB,CAACC,CAAmB,EAAE;IACjD,OAAOC,MAAM,CAACC,MAAM,CAACF,CAAC,CAAC,CACpBG,GAAG,CAAC,CAACH,CAAC,GAAKI,IAAI,CAACC,SAAS,CAACL,CAAC,CAACM,KAAK,CAAC,CAAC,CACnCC,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CAAC;AAED,SAASC,sBAAsB,CAACR,CAAmB,EAAES,KAAgB,EAAE;IACrE,IAAI,CAACA,KAAK,EAAE;QACV,OAAOT,CAAC,CAAC;IACX,CAAC;IACD,OAAOC,MAAM,CAACS,WAAW,CAACT,MAAM,CAACU,OAAO,CAACX,CAAC,CAAC,CAACY,MAAM,CAAC,CAAC,CAACC,IAAI,CAAC,GAAKJ,KAAK,CAACK,QAAQ,CAACD,IAAI,CAAC,CAAC,CAAC,CAAC;AACxF,CAAC;AAED,SAASE,eAAe,CAAC,EACvBC,MAAM,CAAA,EACNC,UAAU,CAAA,EACVC,OAAO,CAAA,EAKR,EAAE;IACD,MAAM,EAAEC,SAAS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AAI,CAAY2B,UAAU,CAACrE,qBAAqB,CAAC,EAAE;YACnFwD,OAAO,CAACc,IAAI,CAACL,KAAK,CAA6D,CAAC;QAClF,CAAC;IACH,CAAC;IAED,OAAOT,OAAO,CAAC;AACjB,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/runtime/time-series-queries.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport {\n useQuery,\n useQueries,\n useQueryClient,\n Query,\n QueryCache,\n QueryKey,\n QueryObserverOptions,\n} from '@tanstack/react-query';\nimport { TimeSeriesQueryDefinition, UnknownSpec, TimeSeriesData } from '@perses-dev/core';\nimport { TimeSeriesDataQuery, TimeSeriesQueryContext, TimeSeriesQueryPlugin } from '../model';\nimport { VariableStateMap, useVariableValues } from './template-variables';\nimport { useTimeRange } from './TimeRangeProvider';\nimport { useDatasourceStore } from './datasources';\nimport { usePlugin, usePluginRegistry, usePlugins } from './plugin-registry';\n\nexport interface UseTimeSeriesQueryOptions {\n suggestedStepMs?: number;\n}\n\nexport const TIME_SERIES_QUERY_KEY = 'TimeSeriesQuery';\n\n/**\n * Returns a serialized string of the current state of variable values.\n */\nfunction getVariableValuesKey(v: VariableStateMap) {\n return Object.values(v)\n .map((v) => JSON.stringify(v.value))\n .join(',');\n}\n\nfunction filterVariableStateMap(v: VariableStateMap, names?: string[]) {\n if (!names) {\n return v;\n }\n return Object.fromEntries(Object.entries(v).filter(([name]) => names.includes(name)));\n}\n\nfunction getQueryOptions({\n plugin,\n definition,\n context,\n}: {\n plugin?: TimeSeriesQueryPlugin;\n definition: TimeSeriesQueryDefinition;\n context: TimeSeriesQueryContext;\n}) {\n const { timeRange, datasourceStore, suggestedStepMs, variableState, refreshKey } = context;\n\n const dependencies = plugin?.dependsOn ? plugin.dependsOn(definition.spec.plugin.spec, context) : {};\n const variableDependencies = dependencies?.variables;\n\n // Determine queryKey\n const filteredVariabledState = filterVariableStateMap(variableState, variableDependencies);\n const variablesValueKey = getVariableValuesKey(filteredVariabledState);\n const queryKey = [definition, timeRange, datasourceStore, suggestedStepMs, variablesValueKey, refreshKey] as const;\n\n // Determine queryEnabled\n let waitToLoad = false;\n if (variableDependencies) {\n waitToLoad = variableDependencies.some((v) => variableState[v]?.loading);\n }\n\n const queryEnabled = plugin !== undefined && !waitToLoad;\n\n return {\n queryKey,\n queryEnabled,\n };\n}\n\n/**\n * Runs a time series query using a plugin and returns the results.\n */\nexport const useTimeSeriesQuery = (\n definition: TimeSeriesQueryDefinition,\n options?: UseTimeSeriesQueryOptions,\n queryOptions?: QueryObserverOptions\n) => {\n const { data: plugin } = usePlugin(TIME_SERIES_QUERY_KEY, definition.spec.plugin.kind);\n const context = useTimeSeriesQueryContext();\n\n const { queryEnabled, queryKey } = getQueryOptions({ plugin, definition, context });\n return useQuery({\n enabled: (queryOptions?.enabled ?? true) || queryEnabled,\n queryKey: queryKey,\n refetchInterval: context.refreshIntervalInMs > 0 ? context.refreshIntervalInMs : false,\n queryFn: () => {\n // The 'enabled' option should prevent this from happening, but make TypeScript happy by checking\n if (plugin === undefined) {\n throw new Error('Expected plugin to be loaded');\n }\n // Keep options out of query key so we don't re-run queries because suggested step changes\n const ctx: TimeSeriesQueryContext = { ...context, suggestedStepMs: options?.suggestedStepMs };\n return plugin.getTimeSeriesData(definition.spec.plugin.spec, ctx);\n },\n });\n};\n\n/**\n * Runs multiple time series queries using plugins and returns the results.\n */\nexport function useTimeSeriesQueries(\n definitions: TimeSeriesQueryDefinition[],\n options?: UseTimeSeriesQueryOptions,\n queryOptions?: QueryObserverOptions\n) {\n const { getPlugin } = usePluginRegistry();\n const context = useTimeSeriesQueryContext();\n\n const pluginLoaderResponse = usePlugins(\n TIME_SERIES_QUERY_KEY,\n definitions.map((d) => ({ kind: d.spec.plugin.kind }))\n );\n\n return useQueries({\n queries: definitions.map((definition, idx) => {\n const plugin = pluginLoaderResponse[idx]?.data;\n const { queryEnabled, queryKey } = getQueryOptions({ plugin, definition, context });\n return {\n enabled: (queryOptions?.enabled ?? true) && queryEnabled,\n queryKey: queryKey,\n refetchInterval: context.refreshIntervalInMs > 0 ? context.refreshIntervalInMs : undefined,\n queryFn: async () => {\n // Keep options out of query key so we don't re-run queries because suggested step changes\n const ctx: TimeSeriesQueryContext = { ...context, suggestedStepMs: options?.suggestedStepMs };\n const plugin = await getPlugin(TIME_SERIES_QUERY_KEY, definition.spec.plugin.kind);\n const data = await plugin.getTimeSeriesData(definition.spec.plugin.spec, ctx);\n return data;\n },\n };\n }),\n });\n}\n\n/**\n * Build the time series query context object from data available at runtime\n */\nfunction useTimeSeriesQueryContext(): TimeSeriesQueryContext {\n const { absoluteTimeRange, refreshKey, refreshIntervalInMs } = useTimeRange();\n const variableState = useVariableValues();\n const datasourceStore = useDatasourceStore();\n\n return {\n timeRange: absoluteTimeRange,\n variableState,\n datasourceStore,\n refreshKey,\n refreshIntervalInMs: refreshIntervalInMs,\n };\n}\n\n/**\n * Get active time series queries for query results summary\n */\nexport function useActiveTimeSeriesQueries() {\n const queryClient = useQueryClient();\n const queryCache = queryClient.getQueryCache();\n return getActiveTimeSeriesQueries(queryCache);\n}\n\n/**\n * Filter all cached queries down to only active time series queries\n */\nexport function getActiveTimeSeriesQueries(cache: QueryCache) {\n const queries: TimeSeriesDataQuery[] = [];\n\n for (const query of cache.findAll({ type: 'active' })) {\n const firstPart = query.queryKey?.[0] as UnknownSpec;\n if (firstPart?.kind && (firstPart.kind as string).startsWith(TIME_SERIES_QUERY_KEY)) {\n queries.push(query as Query<TimeSeriesData, unknown, TimeSeriesData, QueryKey>);\n }\n }\n\n return queries;\n}\n"],"names":["useQuery","useQueries","useQueryClient","useVariableValues","useTimeRange","useDatasourceStore","usePlugin","usePluginRegistry","usePlugins","TIME_SERIES_QUERY_KEY","getVariableValuesKey","v","Object","values","map","JSON","stringify","value","join","filterVariableStateMap","names","fromEntries","entries","filter","name","includes","getQueryOptions","plugin","definition","context","timeRange","datasourceStore","suggestedStepMs","variableState","refreshKey","dependencies","dependsOn","spec","variableDependencies","variables","filteredVariabledState","variablesValueKey","queryKey","waitToLoad","some","loading","queryEnabled","undefined","useTimeSeriesQuery","options","queryOptions","data","kind","useTimeSeriesQueryContext","enabled","refetchInterval","refreshIntervalInMs","queryFn","Error","ctx","getTimeSeriesData","useTimeSeriesQueries","definitions","getPlugin","pluginLoaderResponse","d","queries","idx","absoluteTimeRange","useActiveTimeSeriesQueries","queryClient","queryCache","getQueryCache","getActiveTimeSeriesQueries","cache","query","findAll","type","firstPart","startsWith","push"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SACEA,QAAQ,EACRC,UAAU,EACVC,cAAc,QAKT,wBAAwB;AAG/B,SAA2BC,iBAAiB,QAAQ,uBAAuB;AAC3E,SAASC,YAAY,QAAQ,sBAAsB;AACnD,SAASC,kBAAkB,QAAQ,gBAAgB;AACnD,SAASC,SAAS,EAAEC,iBAAiB,EAAEC,UAAU,QAAQ,oBAAoB;AAM7E,OAAO,MAAMC,wBAAwB,kBAAkB;AAEvD;;CAEC,GACD,SAASC,qBAAqBC,CAAmB;IAC/C,OAAOC,OAAOC,OAAOF,GAClBG,IAAI,CAACH,IAAMI,KAAKC,UAAUL,EAAEM,QAC5BC,KAAK;AACV;AAEA,SAASC,uBAAuBR,CAAmB,EAAES,KAAgB;IACnE,IAAI,CAACA,OAAO;QACV,OAAOT;IACT;IACA,O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