@perses-dev/plugin-system 0.39.0 → 0.40.1
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 +381 -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 +23 -28
- package/dist/cjs/components/OptionsEditorRadios/index.js +10 -8
- package/dist/cjs/components/OptionsEditorTabPanel/OptionsEditorTabPanel.js +6 -4
- package/dist/cjs/components/OptionsEditorTabPanel/index.js +10 -8
- 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 +257 -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 -19
- 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 +19 -11
- package/dist/cjs/runtime/DataQueriesProvider/index.js +11 -9
- package/dist/cjs/runtime/DataQueriesProvider/model.js +12 -8
- 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 +42 -12
- 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 -9
- package/dist/cjs/test/mock-data.js +3 -1
- 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 +334 -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 +2 -2
- package/dist/components/OptionsEditorRadios/OptionsEditorRadios.d.ts.map +1 -1
- package/dist/components/OptionsEditorRadios/OptionsEditorRadios.js +16 -23
- package/dist/components/OptionsEditorRadios/OptionsEditorRadios.js.map +1 -1
- package/dist/components/OptionsEditorRadios/index.js.map +1 -1
- package/dist/components/OptionsEditorTabPanel/OptionsEditorTabPanel.js.map +1 -1
- package/dist/components/OptionsEditorTabPanel/index.js.map +1 -1
- 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 +201 -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 +1 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +1 -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.js +4 -4
- 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 +3 -2
- package/dist/runtime/DataQueriesProvider/model.d.ts.map +1 -1
- package/dist/runtime/DataQueriesProvider/model.js +4 -4
- 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 +2 -1
- package/dist/runtime/template-variables.d.ts.map +1 -1
- package/dist/runtime/template-variables.js +27 -8
- 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.js.map +1 -1
- package/dist/test/mock-data.js.map +1 -1
- 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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/plugin-loading.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 { PluginModuleResource } from './plugins';\n\n/**\n * A component capable of loading the resource/metadata for all available plugins, then loading individual plugins for\n * those resources on-demand.\n */\nexport interface PluginLoader {\n getInstalledPlugins: () => Promise<PluginModuleResource[]>;\n importPluginModule: (resource: PluginModuleResource) => Promise<unknown>;\n}\n\n/**\n * The dynamic import for a single plugin resource.\n */\nexport interface DynamicImportPlugin {\n resource: PluginModuleResource;\n importPlugin(): Promise<unknown>;\n}\n\n/**\n * A PluginLoader for the common pattern in Perses where we eagerly import a plugin's resource file, and then lazy load\n * the plugin itself via a dynamic `import()` statement.\n */\nexport function dynamicImportPluginLoader(plugins: DynamicImportPlugin[]): PluginLoader {\n const importMap: Map<PluginModuleResource, DynamicImportPlugin['importPlugin']> = new Map(\n plugins.map((plugin) => [plugin.resource, plugin.importPlugin])\n );\n\n return {\n async getInstalledPlugins() {\n return Promise.resolve(Array.from(importMap.keys()));\n },\n importPluginModule(resource) {\n const importFn = importMap.get(resource);\n if (importFn === undefined) {\n throw new Error('Plugin not found');\n }\n return importFn();\n },\n };\n}\n"],"names":["dynamicImportPluginLoader","plugins","importMap","Map","map","plugin","resource","importPlugin","getInstalledPlugins","Promise","resolve","Array","from","keys","importPluginModule","importFn","get","undefined","Error"],"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;AAqBjC;;;CAGC,GACD,OAAO,SAASA,
|
|
1
|
+
{"version":3,"sources":["../../src/model/plugin-loading.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 { PluginModuleResource } from './plugins';\n\n/**\n * A component capable of loading the resource/metadata for all available plugins, then loading individual plugins for\n * those resources on-demand.\n */\nexport interface PluginLoader {\n getInstalledPlugins: () => Promise<PluginModuleResource[]>;\n importPluginModule: (resource: PluginModuleResource) => Promise<unknown>;\n}\n\n/**\n * The dynamic import for a single plugin resource.\n */\nexport interface DynamicImportPlugin {\n resource: PluginModuleResource;\n importPlugin(): Promise<unknown>;\n}\n\n/**\n * A PluginLoader for the common pattern in Perses where we eagerly import a plugin's resource file, and then lazy load\n * the plugin itself via a dynamic `import()` statement.\n */\nexport function dynamicImportPluginLoader(plugins: DynamicImportPlugin[]): PluginLoader {\n const importMap: Map<PluginModuleResource, DynamicImportPlugin['importPlugin']> = new Map(\n plugins.map((plugin) => [plugin.resource, plugin.importPlugin])\n );\n\n return {\n async getInstalledPlugins() {\n return Promise.resolve(Array.from(importMap.keys()));\n },\n importPluginModule(resource) {\n const importFn = importMap.get(resource);\n if (importFn === undefined) {\n throw new Error('Plugin not found');\n }\n return importFn();\n },\n };\n}\n"],"names":["dynamicImportPluginLoader","plugins","importMap","Map","map","plugin","resource","importPlugin","getInstalledPlugins","Promise","resolve","Array","from","keys","importPluginModule","importFn","get","undefined","Error"],"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;AAqBjC;;;CAGC,GACD,OAAO,SAASA,0BAA0BC,OAA8B;IACtE,MAAMC,YAA4E,IAAIC,IACpFF,QAAQG,IAAI,CAACC,SAAW;YAACA,OAAOC;YAAUD,OAAOE;SAAa;IAGhE,OAAO;QACL,MAAMC;YACJ,OAAOC,QAAQC,QAAQC,MAAMC,KAAKV,UAAUW;QAC9C;QACAC,oBAAmBR,QAAQ;YACzB,MAAMS,WAAWb,UAAUc,IAAIV;YAC/B,IAAIS,aAAaE,WAAW;gBAC1B,MAAM,IAAIC,MAAM;YAClB;YACA,OAAOH;QACT;IACF;AACF"}
|
|
@@ -28,8 +28,8 @@ export function useDataQueries(queryType) {
|
|
|
28
28
|
const filteredQueryResults = ctx.queryResults.filter((queryResult)=>queryResult.definition.kind === queryType);
|
|
29
29
|
// Filter the errors based on the specified query type
|
|
30
30
|
const filteredErrors = ctx.errors.filter((errors, index)=>{
|
|
31
|
-
var
|
|
32
|
-
return ((
|
|
31
|
+
var _ctx_queryResults_index;
|
|
32
|
+
return ((_ctx_queryResults_index = ctx.queryResults[index]) === null || _ctx_queryResults_index === void 0 ? void 0 : _ctx_queryResults_index.definition.kind) === queryType;
|
|
33
33
|
});
|
|
34
34
|
// Create a new context object with the filtered results and errors
|
|
35
35
|
const filteredCtx = {
|
|
@@ -42,7 +42,7 @@ export function useDataQueries(queryType) {
|
|
|
42
42
|
return filteredCtx;
|
|
43
43
|
}
|
|
44
44
|
export function DataQueriesProvider(props) {
|
|
45
|
-
const { definitions , options , children } = props;
|
|
45
|
+
const { definitions , options , children , queryOptions } = props;
|
|
46
46
|
const getQueryType = useQueryType();
|
|
47
47
|
const queryDefinitions = definitions.map((definition)=>{
|
|
48
48
|
const type = getQueryType(definition.kind);
|
|
@@ -55,7 +55,7 @@ export function DataQueriesProvider(props) {
|
|
|
55
55
|
});
|
|
56
56
|
// Filter definitions for time series query and other future query plugins
|
|
57
57
|
const timeSeriesQueries = queryDefinitions.filter((definition)=>definition.kind === 'TimeSeriesQuery');
|
|
58
|
-
const timeSeriesResults = useTimeSeriesQueries(timeSeriesQueries, options);
|
|
58
|
+
const timeSeriesResults = useTimeSeriesQueries(timeSeriesQueries, options, queryOptions);
|
|
59
59
|
const refetchAll = useCallback(()=>{
|
|
60
60
|
timeSeriesResults.forEach((result)=>result.refetch());
|
|
61
61
|
}, [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/runtime/DataQueriesProvider/DataQueriesProvider.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 { createContext, useCallback, useContext, useMemo } from 'react';\nimport { QueryType, TimeSeriesQueryDefinition } from '@perses-dev/core';\nimport { useTimeSeriesQueries } from '../time-series-queries';\nimport {\n DataQueriesProviderProps,\n UseDataQueryResults,\n transformQueryResults,\n DataQueriesContextType,\n QueryData,\n useQueryType,\n} from './model';\n\nexport const DataQueriesContext = createContext<DataQueriesContextType | undefined>(undefined);\n\nexport function useDataQueriesContext() {\n const ctx = useContext(DataQueriesContext);\n if (ctx === undefined) {\n throw new Error('No DataQueriesContext found. Did you forget a Provider?');\n }\n return ctx;\n}\n\nexport function useDataQueries<T extends keyof QueryType>(queryType: T): UseDataQueryResults<QueryType[T]> {\n const ctx = useDataQueriesContext();\n\n // Filter the query results based on the specified query type\n const filteredQueryResults = ctx.queryResults.filter(\n (queryResult) => queryResult.definition.kind === queryType\n ) as Array<QueryData<QueryType[T]>>;\n\n // Filter the errors based on the specified query type\n const filteredErrors = ctx.errors.filter((errors, index) => ctx.queryResults[index]?.definition.kind === queryType);\n\n // Create a new context object with the filtered results and errors\n const filteredCtx = {\n queryResults: filteredQueryResults,\n isFetching: filteredQueryResults.some((result) => result.isFetching),\n isLoading: filteredQueryResults.some((result) => result.isLoading),\n refetchAll: ctx.refetchAll,\n errors: filteredErrors,\n };\n\n return filteredCtx;\n}\n\nexport function DataQueriesProvider(props: DataQueriesProviderProps) {\n const { definitions, options, children } = props;\n\n const getQueryType = useQueryType();\n\n const queryDefinitions = definitions.map((definition) => {\n const type = getQueryType(definition.kind);\n return {\n kind: type,\n spec: {\n plugin: definition,\n },\n };\n });\n\n // Filter definitions for time series query and other future query plugins\n const timeSeriesQueries = queryDefinitions.filter(\n (definition) => definition.kind === 'TimeSeriesQuery'\n ) as TimeSeriesQueryDefinition[];\n const timeSeriesResults = useTimeSeriesQueries(timeSeriesQueries, options);\n\n const refetchAll = useCallback(() => {\n timeSeriesResults.forEach((result) => result.refetch());\n }, [timeSeriesResults]);\n\n const ctx = useMemo(() => {\n const mergedQueryResults = [...transformQueryResults(timeSeriesResults, timeSeriesQueries)];\n\n return {\n queryResults: mergedQueryResults,\n isFetching: mergedQueryResults.some((result) => result.isFetching),\n isLoading: mergedQueryResults.some((result) => result.isLoading),\n refetchAll,\n errors: mergedQueryResults.map((result) => result.error),\n };\n }, [timeSeriesQueries, timeSeriesResults, refetchAll]);\n\n return <DataQueriesContext.Provider value={ctx}>{children}</DataQueriesContext.Provider>;\n}\n"],"names":["createContext","useCallback","useContext","useMemo","useTimeSeriesQueries","transformQueryResults","useQueryType","DataQueriesContext","undefined","useDataQueriesContext","ctx","Error","useDataQueries","queryType","filteredQueryResults","queryResults","filter","queryResult","definition","kind","filteredErrors","errors","index","filteredCtx","isFetching","some","result","isLoading","refetchAll","DataQueriesProvider","props","definitions","options","children","getQueryType","queryDefinitions","map","type","spec","plugin","timeSeriesQueries","timeSeriesResults","forEach","refetch","mergedQueryResults","error","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
|
|
1
|
+
{"version":3,"sources":["../../../src/runtime/DataQueriesProvider/DataQueriesProvider.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 { createContext, useCallback, useContext, useMemo } from 'react';\nimport { QueryType, TimeSeriesQueryDefinition } from '@perses-dev/core';\nimport { useTimeSeriesQueries } from '../time-series-queries';\nimport {\n DataQueriesProviderProps,\n UseDataQueryResults,\n transformQueryResults,\n DataQueriesContextType,\n QueryData,\n useQueryType,\n} from './model';\n\nexport const DataQueriesContext = createContext<DataQueriesContextType | undefined>(undefined);\n\nexport function useDataQueriesContext() {\n const ctx = useContext(DataQueriesContext);\n if (ctx === undefined) {\n throw new Error('No DataQueriesContext found. Did you forget a Provider?');\n }\n return ctx;\n}\n\nexport function useDataQueries<T extends keyof QueryType>(queryType: T): UseDataQueryResults<QueryType[T]> {\n const ctx = useDataQueriesContext();\n\n // Filter the query results based on the specified query type\n const filteredQueryResults = ctx.queryResults.filter(\n (queryResult) => queryResult.definition.kind === queryType\n ) as Array<QueryData<QueryType[T]>>;\n\n // Filter the errors based on the specified query type\n const filteredErrors = ctx.errors.filter((errors, index) => ctx.queryResults[index]?.definition.kind === queryType);\n\n // Create a new context object with the filtered results and errors\n const filteredCtx = {\n queryResults: filteredQueryResults,\n isFetching: filteredQueryResults.some((result) => result.isFetching),\n isLoading: filteredQueryResults.some((result) => result.isLoading),\n refetchAll: ctx.refetchAll,\n errors: filteredErrors,\n };\n\n return filteredCtx;\n}\n\nexport function DataQueriesProvider(props: DataQueriesProviderProps) {\n const { definitions, options, children, queryOptions } = props;\n\n const getQueryType = useQueryType();\n\n const queryDefinitions = definitions.map((definition) => {\n const type = getQueryType(definition.kind);\n return {\n kind: type,\n spec: {\n plugin: definition,\n },\n };\n });\n\n // Filter definitions for time series query and other future query plugins\n const timeSeriesQueries = queryDefinitions.filter(\n (definition) => definition.kind === 'TimeSeriesQuery'\n ) as TimeSeriesQueryDefinition[];\n const timeSeriesResults = useTimeSeriesQueries(timeSeriesQueries, options, queryOptions);\n\n const refetchAll = useCallback(() => {\n timeSeriesResults.forEach((result) => result.refetch());\n }, [timeSeriesResults]);\n\n const ctx = useMemo(() => {\n const mergedQueryResults = [...transformQueryResults(timeSeriesResults, timeSeriesQueries)];\n\n return {\n queryResults: mergedQueryResults,\n isFetching: mergedQueryResults.some((result) => result.isFetching),\n isLoading: mergedQueryResults.some((result) => result.isLoading),\n refetchAll,\n errors: mergedQueryResults.map((result) => result.error),\n };\n }, [timeSeriesQueries, timeSeriesResults, refetchAll]);\n\n return <DataQueriesContext.Provider value={ctx}>{children}</DataQueriesContext.Provider>;\n}\n"],"names":["createContext","useCallback","useContext","useMemo","useTimeSeriesQueries","transformQueryResults","useQueryType","DataQueriesContext","undefined","useDataQueriesContext","ctx","Error","useDataQueries","queryType","filteredQueryResults","queryResults","filter","queryResult","definition","kind","filteredErrors","errors","index","filteredCtx","isFetching","some","result","isLoading","refetchAll","DataQueriesProvider","props","definitions","options","children","queryOptions","getQueryType","queryDefinitions","map","type","spec","plugin","timeSeriesQueries","timeSeriesResults","forEach","refetch","mergedQueryResults","error","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;;AAEjC,SAASA,aAAa,EAAEC,WAAW,EAAEC,UAAU,EAAEC,OAAO,QAAQ,QAAQ;AAExE,SAASC,oBAAoB,QAAQ,yBAAyB;AAC9D,SAGEC,qBAAqB,EAGrBC,YAAY,QACP,UAAU;AAEjB,OAAO,MAAMC,mCAAqBP,cAAkDQ,WAAW;AAE/F,OAAO,SAASC;IACd,MAAMC,MAAMR,WAAWK;IACvB,IAAIG,QAAQF,WAAW;QACrB,MAAM,IAAIG,MAAM;IAClB;IACA,OAAOD;AACT;AAEA,OAAO,SAASE,eAA0CC,SAAY;IACpE,MAAMH,MAAMD;IAEZ,6DAA6D;IAC7D,MAAMK,uBAAuBJ,IAAIK,aAAaC,OAC5C,CAACC,cAAgBA,YAAYC,WAAWC,SAASN;IAGnD,sDAAsD;IACtD,MAAMO,iBAAiBV,IAAIW,OAAOL,OAAO,CAACK,QAAQC;YAAUZ;QAAAA,OAAAA,CAAA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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/runtime/DataQueriesProvider/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 './DataQueriesProvider';\nexport * from './model';\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/DataQueriesProvider/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 './DataQueriesProvider';\nexport * from './model';\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,wBAAwB;AACtC,cAAc,UAAU"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { Definition, QueryDefinition, UnknownSpec, QueryDataType } from '@perses-dev/core';
|
|
3
|
-
import { UseQueryResult } from '@tanstack/react-query';
|
|
3
|
+
import { QueryObserverOptions, UseQueryResult } from '@tanstack/react-query';
|
|
4
4
|
declare type QueryOptions = Record<string, unknown>;
|
|
5
5
|
export interface DataQueriesProviderProps<QueryPluginSpec = UnknownSpec> {
|
|
6
6
|
definitions: Array<Definition<QueryPluginSpec>>;
|
|
7
|
-
options?: QueryOptions;
|
|
8
7
|
children?: React.ReactNode;
|
|
8
|
+
options?: QueryOptions;
|
|
9
|
+
queryOptions?: QueryObserverOptions;
|
|
9
10
|
}
|
|
10
11
|
export interface DataQueriesContextType {
|
|
11
12
|
queryResults: QueryData[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/runtime/DataQueriesProvider/model.ts"],"names":[],"mappings":";AAaA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC3F,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/runtime/DataQueriesProvider/model.ts"],"names":[],"mappings":";AAaA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC3F,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAI7E,aAAK,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAC5C,MAAM,WAAW,wBAAwB,CAAC,eAAe,GAAG,WAAW;IACrE,WAAW,EAAE,KAAK,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC,CAAC;IAChD,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,YAAY,CAAC,EAAE,oBAAoB,CAAC;CACrC;AAED,MAAM,WAAW,sBAAsB;IACrC,YAAY,EAAE,SAAS,EAAE,CAAC;IAC1B,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,OAAO,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,mBAAmB,CAAC,CAAC,CAAE,SAAQ,IAAI,CAAC,sBAAsB,EAAE,cAAc,CAAC;IAC1F,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;CACnC;AAED,oBAAY,SAAS,CAAC,CAAC,GAAG,aAAa,IAAI;IACzC,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,UAAU,EAAE,eAAe,CAAC;IAC5B,KAAK,EAAE,OAAO,CAAC;IACf,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB,CAAC;AAEF,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,cAAc,EAAE,EAAE,WAAW,EAAE,eAAe,EAAE,0DAW9F;AAED,wBAAgB,YAAY,IAAI,CAAC,UAAU,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAmCzE"}
|
|
@@ -32,8 +32,8 @@ export function useQueryType() {
|
|
|
32
32
|
};
|
|
33
33
|
if (timeSeriesQueryPlugins) {
|
|
34
34
|
timeSeriesQueryPlugins.forEach((plugin)=>{
|
|
35
|
-
var
|
|
36
|
-
(
|
|
35
|
+
var _map_TimeSeriesQuery;
|
|
36
|
+
(_map_TimeSeriesQuery = map['TimeSeriesQuery']) === null || _map_TimeSeriesQuery === void 0 ? void 0 : _map_TimeSeriesQuery.push(plugin.kind);
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
return map;
|
|
@@ -45,8 +45,8 @@ export function useQueryType() {
|
|
|
45
45
|
return undefined;
|
|
46
46
|
}
|
|
47
47
|
for(const queryType in queryTypeMap){
|
|
48
|
-
var
|
|
49
|
-
if ((
|
|
48
|
+
var _queryTypeMap_queryType;
|
|
49
|
+
if ((_queryTypeMap_queryType = queryTypeMap[queryType]) === null || _queryTypeMap_queryType === void 0 ? void 0 : _queryTypeMap_queryType.includes(pluginKind)) {
|
|
50
50
|
return queryType;
|
|
51
51
|
}
|
|
52
52
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/runtime/DataQueriesProvider/model.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 { Definition, QueryDefinition, UnknownSpec, QueryDataType } from '@perses-dev/core';\nimport { UseQueryResult } from '@tanstack/react-query';\nimport { useCallback, useMemo } from 'react';\nimport { useListPluginMetadata } from '../plugin-registry';\n\ntype QueryOptions = Record<string, unknown>;\nexport interface DataQueriesProviderProps<QueryPluginSpec = UnknownSpec> {\n definitions: Array<Definition<QueryPluginSpec>>;\n options?: QueryOptions;\n
|
|
1
|
+
{"version":3,"sources":["../../../src/runtime/DataQueriesProvider/model.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 { Definition, QueryDefinition, UnknownSpec, QueryDataType } from '@perses-dev/core';\nimport { QueryObserverOptions, UseQueryResult } from '@tanstack/react-query';\nimport { useCallback, useMemo } from 'react';\nimport { useListPluginMetadata } from '../plugin-registry';\n\ntype QueryOptions = Record<string, unknown>;\nexport interface DataQueriesProviderProps<QueryPluginSpec = UnknownSpec> {\n definitions: Array<Definition<QueryPluginSpec>>;\n children?: React.ReactNode;\n options?: QueryOptions;\n queryOptions?: QueryObserverOptions;\n}\n\nexport interface DataQueriesContextType {\n queryResults: QueryData[];\n refetchAll: () => void;\n isFetching: boolean;\n isLoading: boolean;\n errors: unknown[];\n}\n\nexport interface UseDataQueryResults<T> extends Omit<DataQueriesContextType, 'queryResults'> {\n queryResults: Array<QueryData<T>>;\n}\n\nexport type QueryData<T = QueryDataType> = {\n data?: T;\n definition: QueryDefinition;\n error: unknown;\n isFetching: boolean;\n isLoading: boolean;\n refetch?: () => void;\n};\n\nexport function transformQueryResults(results: UseQueryResult[], definitions: QueryDefinition[]) {\n return results.map(({ data, isFetching, isLoading, refetch, error }, i) => {\n return {\n definition: definitions[i],\n data,\n isFetching,\n isLoading,\n refetch,\n error,\n } as QueryData;\n });\n}\n\nexport function useQueryType(): (pluginKind: string) => string | undefined {\n const { data: timeSeriesQueryPlugins, isLoading } = useListPluginMetadata('TimeSeriesQuery');\n\n const queryTypeMap = useMemo(() => {\n const map: Record<string, string[]> = {\n TimeSeriesQuery: [],\n };\n\n if (timeSeriesQueryPlugins) {\n timeSeriesQueryPlugins.forEach((plugin) => {\n map['TimeSeriesQuery']?.push(plugin.kind);\n });\n }\n\n return map;\n }, [timeSeriesQueryPlugins]);\n\n const getQueryType = useCallback(\n (pluginKind: string) => {\n if (isLoading) {\n return undefined;\n }\n\n for (const queryType in queryTypeMap) {\n if (queryTypeMap[queryType]?.includes(pluginKind)) {\n return queryType;\n }\n }\n\n throw new Error(`Unable to determine the query type: ${pluginKind}`);\n },\n [queryTypeMap, isLoading]\n );\n\n return getQueryType;\n}\n"],"names":["useCallback","useMemo","useListPluginMetadata","transformQueryResults","results","definitions","map","data","isFetching","isLoading","refetch","error","i","definition","useQueryType","timeSeriesQueryPlugins","queryTypeMap","TimeSeriesQuery","forEach","plugin","push","kind","getQueryType","pluginKind","undefined","queryType","includes","Error"],"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,WAAW,EAAEC,OAAO,QAAQ,QAAQ;AAC7C,SAASC,qBAAqB,QAAQ,qBAAqB;AA+B3D,OAAO,SAASC,sBAAsBC,OAAyB,EAAEC,WAA8B;IAC7F,OAAOD,QAAQE,IAAI,CAAC,EAAEC,KAAI,EAAEC,WAAU,EAAEC,UAAS,EAAEC,QAAO,EAAEC,MAAK,EAAE,EAAEC;QACnE,OAAO;YACLC,YAAYR,WAAW,CAACO,EAAE;YAC1BL;YACAC;YACAC;YACAC;YACAC;QACF;IACF;AACF;AAEA,OAAO,SAASG;IACd,MAAM,EAAEP,MAAMQ,uBAAsB,EAAEN,UAAS,EAAE,GAAGP,sBAAsB;IAE1E,MAAMc,eAAef,QAAQ;QAC3B,MAAMK,MAAgC;YACpCW,iBAAiB,EAAE;QACrB;QAEA,IAAIF,wBAAwB;YAC1BA,uBAAuBG,QAAQ,CAACC;oBAC9Bb;gBAAAA,CAAAA,uBAAAA,GAAG,CAAC,kBAAkB,cAAtBA,kCAAAA,KAAAA,IAAAA,qBAAwBc,KAAKD,OAAOE;YACtC;QACF;QAEA,OAAOf;IACT,GAAG;QAACS;KAAuB;IAE3B,MAAMO,eAAetB,YACnB,CAACuB;QACC,IAAId,WAAW;YACb,OAAOe;QACT;QAEA,IAAK,MAAMC,aAAaT,aAAc;gBAChCA;YAAJ,IAAIA,CAAAA,0BAAAA,YAAY,CAACS,UAAU,cAAvBT,qCAAAA,KAAAA,IAAAA,wBAAyBU,SAASH,aAAa;gBACjD,OAAOE;YACT;QACF;QAEA,MAAM,IAAIE,MAAM,CAAC,oCAAoC,EAAEJ,WAAW,CAAC;IACrE,GACA;QAACP;QAAcP;KAAU;IAG3B,OAAOa;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/runtime/TimeRangeProvider/TimeRangeProvider.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 React, { useMemo, useState, useCallback, createContext, useContext } from 'react';\nimport {\n AbsoluteTimeRange,\n DurationString,\n isRelativeTimeRange,\n TimeRangeValue,\n toAbsoluteTimeRange,\n} from '@perses-dev/core';\nimport { useSetRefreshIntervalParams, useSetTimeRangeParams } from './query-params';\n\nexport interface TimeRangeProviderProps {\n initialTimeRange: TimeRangeValue;\n initialRefreshInterval?: DurationString;\n enabledURLParams?: boolean;\n children?: React.ReactNode;\n}\n\nexport interface TimeRange {\n timeRange: TimeRangeValue;\n absoluteTimeRange: AbsoluteTimeRange; // resolved absolute time for plugins to use\n setTimeRange: (value: TimeRangeValue) => void;\n refresh: () => void;\n refreshKey: string;\n refreshInterval?: DurationString;\n refreshIntervalInMs: number;\n setRefreshInterval: (value: DurationString) => void;\n}\n\nexport const TimeRangeContext = createContext<TimeRange | undefined>(undefined);\n\nexport function useTimeRangeContext() {\n const ctx = useContext(TimeRangeContext);\n if (ctx === undefined) {\n throw new Error('No TimeRangeContext found. Did you forget a Provider?');\n }\n return ctx;\n}\n\n/**\n * Get and set the current resolved time range at runtime.\n */\nexport function useTimeRange(): TimeRange {\n return useTimeRangeContext();\n}\n\n/**\n * Provider implementation that supplies the time range state at runtime.\n */\nexport function TimeRangeProvider(props: TimeRangeProviderProps) {\n const { initialTimeRange, initialRefreshInterval, enabledURLParams, children } = props;\n\n const { timeRange, setTimeRange } = useSetTimeRangeParams(initialTimeRange, enabledURLParams);\n const { refreshInterval, setRefreshInterval, refreshIntervalInMs } = useSetRefreshIntervalParams(\n initialRefreshInterval,\n enabledURLParams\n );\n\n const [refreshKey, setRefreshKey] = useState(0);\n\n const refresh = useCallback(() => {\n setRefreshKey(refreshKey + 1);\n }, [refreshKey]);\n\n const ctx = useMemo(() => {\n const absoluteTimeRange = isRelativeTimeRange(timeRange) ? toAbsoluteTimeRange(timeRange) : timeRange;\n return {\n timeRange,\n setTimeRange,\n absoluteTimeRange,\n refresh,\n refreshKey: `${absoluteTimeRange.start}:${absoluteTimeRange.end}:${refreshInterval}:${refreshKey}`,\n refreshInterval,\n refreshIntervalInMs,\n setRefreshInterval,\n };\n }, [timeRange, setTimeRange, refresh, refreshKey, refreshInterval, refreshIntervalInMs, setRefreshInterval]);\n\n return <TimeRangeContext.Provider value={ctx}>{children}</TimeRangeContext.Provider>;\n}\n"],"names":["React","useMemo","useState","useCallback","createContext","useContext","isRelativeTimeRange","toAbsoluteTimeRange","useSetRefreshIntervalParams","useSetTimeRangeParams","TimeRangeContext","undefined","useTimeRangeContext","ctx","Error","useTimeRange","TimeRangeProvider","props","initialTimeRange","initialRefreshInterval","enabledURLParams","children","timeRange","setTimeRange","refreshInterval","setRefreshInterval","refreshIntervalInMs","refreshKey","setRefreshKey","refresh","absoluteTimeRange","start","end","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
|
|
1
|
+
{"version":3,"sources":["../../../src/runtime/TimeRangeProvider/TimeRangeProvider.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 React, { useMemo, useState, useCallback, createContext, useContext } from 'react';\nimport {\n AbsoluteTimeRange,\n DurationString,\n isRelativeTimeRange,\n TimeRangeValue,\n toAbsoluteTimeRange,\n} from '@perses-dev/core';\nimport { useSetRefreshIntervalParams, useSetTimeRangeParams } from './query-params';\n\nexport interface TimeRangeProviderProps {\n initialTimeRange: TimeRangeValue;\n initialRefreshInterval?: DurationString;\n enabledURLParams?: boolean;\n children?: React.ReactNode;\n}\n\nexport interface TimeRange {\n timeRange: TimeRangeValue;\n absoluteTimeRange: AbsoluteTimeRange; // resolved absolute time for plugins to use\n setTimeRange: (value: TimeRangeValue) => void;\n refresh: () => void;\n refreshKey: string;\n refreshInterval?: DurationString;\n refreshIntervalInMs: number;\n setRefreshInterval: (value: DurationString) => void;\n}\n\nexport const TimeRangeContext = createContext<TimeRange | undefined>(undefined);\n\nexport function useTimeRangeContext() {\n const ctx = useContext(TimeRangeContext);\n if (ctx === undefined) {\n throw new Error('No TimeRangeContext found. Did you forget a Provider?');\n }\n return ctx;\n}\n\n/**\n * Get and set the current resolved time range at runtime.\n */\nexport function useTimeRange(): TimeRange {\n return useTimeRangeContext();\n}\n\n/**\n * Provider implementation that supplies the time range state at runtime.\n */\nexport function TimeRangeProvider(props: TimeRangeProviderProps) {\n const { initialTimeRange, initialRefreshInterval, enabledURLParams, children } = props;\n\n const { timeRange, setTimeRange } = useSetTimeRangeParams(initialTimeRange, enabledURLParams);\n const { refreshInterval, setRefreshInterval, refreshIntervalInMs } = useSetRefreshIntervalParams(\n initialRefreshInterval,\n enabledURLParams\n );\n\n const [refreshKey, setRefreshKey] = useState(0);\n\n const refresh = useCallback(() => {\n setRefreshKey(refreshKey + 1);\n }, [refreshKey]);\n\n const ctx = useMemo(() => {\n const absoluteTimeRange = isRelativeTimeRange(timeRange) ? toAbsoluteTimeRange(timeRange) : timeRange;\n return {\n timeRange,\n setTimeRange,\n absoluteTimeRange,\n refresh,\n refreshKey: `${absoluteTimeRange.start}:${absoluteTimeRange.end}:${refreshInterval}:${refreshKey}`,\n refreshInterval,\n refreshIntervalInMs,\n setRefreshInterval,\n };\n }, [timeRange, setTimeRange, refresh, refreshKey, refreshInterval, refreshIntervalInMs, setRefreshInterval]);\n\n return <TimeRangeContext.Provider value={ctx}>{children}</TimeRangeContext.Provider>;\n}\n"],"names":["React","useMemo","useState","useCallback","createContext","useContext","isRelativeTimeRange","toAbsoluteTimeRange","useSetRefreshIntervalParams","useSetTimeRangeParams","TimeRangeContext","undefined","useTimeRangeContext","ctx","Error","useTimeRange","TimeRangeProvider","props","initialTimeRange","initialRefreshInterval","enabledURLParams","children","timeRange","setTimeRange","refreshInterval","setRefreshInterval","refreshIntervalInMs","refreshKey","setRefreshKey","refresh","absoluteTimeRange","start","end","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;;AAEjC,OAAOA,SAASC,OAAO,EAAEC,QAAQ,EAAEC,WAAW,EAAEC,aAAa,EAAEC,UAAU,QAAQ,QAAQ;AACzF,SAGEC,mBAAmB,EAEnBC,mBAAmB,QACd,mBAAmB;AAC1B,SAASC,2BAA2B,EAAEC,qBAAqB,QAAQ,iBAAiB;AAoBpF,OAAO,MAAMC,iCAAmBN,cAAqCO,WAAW;AAEhF,OAAO,SAASC;IACd,MAAMC,MAAMR,WAAWK;IACvB,IAAIG,QAAQF,WAAW;QACrB,MAAM,IAAIG,MAAM;IAClB;IACA,OAAOD;AACT;AAEA;;CAEC,GACD,OAAO,SAASE;IACd,OAAOH;AACT;AAEA;;CAEC,GACD,OAAO,SAASI,kBAAkBC,KAA6B;IAC7D,MAAM,EAAEC,iBAAgB,EAAEC,uBAAsB,EAAEC,iBAAgB,EAAEC,SAAQ,EAAE,GAAGJ;IAEjF,MAAM,EAAEK,UAAS,EAAEC,aAAY,EAAE,GAAGd,sBAAsBS,kBAAkBE;IAC5E,MAAM,EAAEI,gBAAe,EAAEC,mBAAkB,EAAEC,oBAAmB,EAAE,GAAGlB,4BACnEW,wBACAC;IAGF,MAAM,CAACO,YAAYC,cAAc,GAAG1B,SAAS;IAE7C,MAAM2B,UAAU1B,YAAY;QAC1ByB,cAAcD,aAAa;IAC7B,GAAG;QAACA;KAAW;IAEf,MAAMd,MAAMZ,QAAQ;QAClB,MAAM6B,oBAAoBxB,oBAAoBgB,aAAaf,oBAAoBe,aAAaA;QAC5F,OAAO;YACLA;YACAC;YACAO;YACAD;YACAF,YAAY,CAAC,EAAEG,kBAAkBC,MAAM,CAAC,EAAED,kBAAkBE,IAAI,CAAC,EAAER,gBAAgB,CAAC,EAAEG,WAAW,CAAC;YAClGH;YACAE;YACAD;QACF;IACF,GAAG;QAACH;QAAWC;QAAcM;QAASF;QAAYH;QAAiBE;QAAqBD;KAAmB;IAE3G,qBAAO,KAACf,iBAAiBuB;QAASC,OAAOrB;kBAAMQ;;AACjD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/runtime/TimeRangeProvider/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 './TimeRangeProvider';\nexport * from './query-params';\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/TimeRangeProvider/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 './TimeRangeProvider';\nexport * from './query-params';\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,iBAAiB"}
|
|
@@ -198,7 +198,7 @@ function getRefreshIntervalInMs(refreshInterval) {
|
|
|
198
198
|
const [refreshIntervalState, setRefreshIntervalState] = useState(initialRefreshInterval);
|
|
199
199
|
const { refresh } = query;
|
|
200
200
|
useEffect(()=>{
|
|
201
|
-
// when dashboard loaded with no params, default to dashboard
|
|
201
|
+
// when dashboard loaded with no params, default to dashboard refresh interval
|
|
202
202
|
if (enabledURLParams && !paramsLoaded && !refresh) {
|
|
203
203
|
setQuery({
|
|
204
204
|
refresh: initialRefreshInterval
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/runtime/TimeRangeProvider/query-params.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 { useMemo, useCallback, useEffect, useState } from 'react';\nimport { useQueryParams, QueryParamConfig } from 'use-query-params';\nimport { getUnixTime, isDate } from 'date-fns';\nimport {\n TimeRangeValue,\n isRelativeTimeRange,\n isDurationString,\n DurationString,\n AbsoluteTimeRange,\n parseDurationString,\n} from '@perses-dev/core';\nimport { TimeRange } from './TimeRangeProvider';\n\nexport type TimeOptionValue = Date | DurationString | null | undefined;\n\n/* Interprets an encoded string and returns either the string or null/undefined if not available */\nfunction getEncodedValue(\n input: string | Array<string | null> | null | undefined,\n allowEmptyString?: boolean\n): string | null | undefined {\n if (input == null) {\n return input;\n }\n // '' or []\n if (input.length === 0 && (!allowEmptyString || (allowEmptyString && input !== ''))) {\n return null;\n }\n\n const str = input instanceof Array ? input[0] : input;\n if (str == null) {\n return str;\n }\n if (!allowEmptyString && str === '') {\n return null;\n }\n\n return str;\n}\n\n/* Encodes individual TimeRangeValue as a string, depends on whether start is relative or absolute */\nexport function encodeTimeRangeValue(timeOptionValue: TimeOptionValue): string | null | undefined {\n if (!timeOptionValue) {\n return timeOptionValue;\n }\n\n if (typeof timeOptionValue === 'string') {\n if (isDurationString(timeOptionValue)) {\n return timeOptionValue;\n }\n }\n return (getUnixTime(timeOptionValue) * 1000).toString();\n}\n\n/* Converts param input to supported relative or absolute time range format */\nexport function decodeTimeRangeValue(\n input: string | Array<string | null> | null | undefined\n): Date | DurationString | null | undefined {\n const paramString = getEncodedValue(input);\n if (paramString == null) return paramString;\n return isDurationString(paramString) ? paramString : new Date(Number(paramString));\n}\n\n/**\n * Custom TimeRangeValue param type\n * See: https://github.com/pbeshai/use-query-params/tree/master/packages/serialize-query-params#param-types\n */\nexport const TimeRangeParam: QueryParamConfig<TimeOptionValue, TimeOptionValue> = {\n encode: encodeTimeRangeValue,\n decode: decodeTimeRangeValue,\n equals: (valueA: TimeOptionValue, valueB: TimeOptionValue) => {\n if (valueA === valueB) return true;\n if (valueA == null || valueB == null) return valueA === valueB;\n return valueA.valueOf() === valueB.valueOf();\n },\n};\n\nexport const timeRangeQueryConfig = {\n start: TimeRangeParam,\n end: TimeRangeParam,\n};\n\nexport const refreshIntervalQueryConfig = {\n refresh: TimeRangeParam,\n};\n\n/**\n * Gets the initial time range taking into account URL params and dashboard JSON duration\n * Sets start query param if it is empty on page load\n */\nexport function useInitialTimeRange(dashboardDuration: DurationString): TimeRangeValue {\n const [query] = useQueryParams(timeRangeQueryConfig, { updateType: 'replaceIn' });\n const { start, end } = query;\n return useMemo(() => {\n let initialTimeRange: TimeRangeValue = { pastDuration: dashboardDuration };\n if (!start) {\n return initialTimeRange;\n }\n const startStr = start.toString();\n if (isDurationString(startStr)) {\n initialTimeRange = { pastDuration: startStr };\n } else if (isDate(start) && isDate(end)) {\n initialTimeRange = { start: start, end: end } as AbsoluteTimeRange;\n }\n return initialTimeRange;\n }, [start, end, dashboardDuration]);\n}\n\n/**\n * Returns time range getter and setter, set enabledURLParams to false to disable query string serialization\n */\nexport function useSetTimeRangeParams(\n initialTimeRange: TimeRangeValue,\n enabledURLParams = true\n): Pick<TimeRange, 'timeRange' | 'setTimeRange'> {\n const [query, setQuery] = useQueryParams(timeRangeQueryConfig, { updateType: 'replaceIn' });\n\n // determine whether initial param had previously been populated to fix back btn\n const [paramsLoaded, setParamsLoaded] = useState<boolean>(false);\n\n // optional fallback when app does not want query string as source of truth\n // this occurs when enabledURLParams is set to false on TimeRangeProvider\n const [timeRangeState, setTimeRangeState] = useState<TimeRangeValue>(initialTimeRange);\n\n const { start } = query;\n\n useEffect(() => {\n // when dashboard loaded with no params, default to dashboard duration\n if (enabledURLParams && !paramsLoaded && !start) {\n if (isRelativeTimeRange(initialTimeRange)) {\n setQuery({ start: initialTimeRange.pastDuration, end: undefined });\n setParamsLoaded(true);\n }\n }\n }, [initialTimeRange, enabledURLParams, paramsLoaded, start, setQuery]);\n\n const setTimeRange: TimeRange['setTimeRange'] = useCallback(\n (value: TimeRangeValue) => {\n if (isRelativeTimeRange(value)) {\n setQuery({ start: value.pastDuration, end: undefined });\n } else {\n setQuery(value);\n }\n },\n [setQuery]\n );\n\n if (!enabledURLParams) {\n return { timeRange: timeRangeState, setTimeRange: setTimeRangeState };\n }\n return { timeRange: initialTimeRange, setTimeRange: setTimeRange };\n}\n\n/**\n * Gets the initial refresh interval taking into account URL params and dashboard JSON duration\n * Sets refresh query param if it is empty on page load\n */\nexport function useInitialRefreshInterval(dashboardDuration: DurationString): DurationString {\n const [query] = useQueryParams(refreshIntervalQueryConfig, { updateType: 'replaceIn' });\n const { refresh } = query;\n return useMemo(() => {\n let initialTimeRange: DurationString = dashboardDuration;\n if (!refresh) {\n return initialTimeRange;\n }\n const startStr = refresh.toString();\n if (isDurationString(startStr)) {\n initialTimeRange = startStr;\n }\n return initialTimeRange;\n }, [dashboardDuration, refresh]);\n}\n\nfunction getRefreshIntervalInMs(refreshInterval?: DurationString) {\n let refreshIntervalInMs = 0;\n if (refreshInterval) {\n const refreshIntervalDuration = parseDurationString(refreshInterval);\n if (refreshIntervalDuration && refreshIntervalDuration.seconds) {\n refreshIntervalInMs = refreshIntervalDuration?.seconds * 1000;\n }\n }\n return refreshIntervalInMs;\n}\n\n/**\n * Returns refresh interval getter and setter, set enabledURLParams to false to disable query string serialization\n */\nexport function useSetRefreshIntervalParams(\n initialRefreshInterval?: DurationString,\n enabledURLParams = true\n): Pick<TimeRange, 'refreshInterval' | 'setRefreshInterval' | 'refreshIntervalInMs'> {\n const [query, setQuery] = useQueryParams(refreshIntervalQueryConfig, { updateType: 'replaceIn' });\n\n // determine whether initial param had previously been populated to fix back btn\n const [paramsLoaded, setParamsLoaded] = useState<boolean>(false);\n\n // optional fallback when app does not want query string as source of truth\n // this occurs when enabledURLParams is set to false on TimeRangeProvider\n const [refreshIntervalState, setRefreshIntervalState] = useState<DurationString | undefined>(initialRefreshInterval);\n\n const { refresh } = query;\n\n useEffect(() => {\n // when dashboard loaded with no params, default to dashboard duration\n if (enabledURLParams && !paramsLoaded && !refresh) {\n setQuery({ refresh: initialRefreshInterval });\n setParamsLoaded(true);\n }\n }, [initialRefreshInterval, enabledURLParams, paramsLoaded, refresh, setQuery]);\n\n const setRefreshInterval: TimeRange['setRefreshInterval'] = useCallback(\n (refresh: DurationString) => setQuery({ refresh }),\n [setQuery]\n );\n\n if (!enabledURLParams) {\n return {\n refreshInterval: refreshIntervalState,\n setRefreshInterval: setRefreshIntervalState,\n refreshIntervalInMs: getRefreshIntervalInMs(refreshIntervalState),\n };\n }\n return {\n refreshInterval: initialRefreshInterval,\n setRefreshInterval: setRefreshInterval,\n refreshIntervalInMs: getRefreshIntervalInMs(initialRefreshInterval),\n };\n}\n"],"names":["useMemo","useCallback","useEffect","useState","useQueryParams","getUnixTime","isDate","isRelativeTimeRange","isDurationString","parseDurationString","getEncodedValue","input","allowEmptyString","length","str","Array","encodeTimeRangeValue","timeOptionValue","toString","decodeTimeRangeValue","paramString","Date","Number","TimeRangeParam","encode","decode","equals","valueA","valueB","valueOf","timeRangeQueryConfig","start","end","refreshIntervalQueryConfig","refresh","useInitialTimeRange","dashboardDuration","query","updateType","initialTimeRange","pastDuration","startStr","useSetTimeRangeParams","enabledURLParams","setQuery","paramsLoaded","setParamsLoaded","timeRangeState","setTimeRangeState","undefined","setTimeRange","value","timeRange","useInitialRefreshInterval","getRefreshIntervalInMs","refreshInterval","refreshIntervalInMs","refreshIntervalDuration","seconds","useSetRefreshIntervalParams","initialRefreshInterval","refreshIntervalState","setRefreshIntervalState","setRefreshInterval"],"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,OAAO,EAAEC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,OAAO,CAAC;AAClE,SAASC,cAAc,QAA0B,kBAAkB,CAAC;AACpE,SAASC,WAAW,EAAEC,MAAM,QAAQ,UAAU,CAAC;AAC/C,SAEEC,mBAAmB,EACnBC,gBAAgB,EAGhBC,mBAAmB,QACd,kBAAkB,CAAC;AAK1B,iGAAiG,GACjG,SAASC,eAAe,CACtBC,KAAuD,EACvDC,gBAA0B,EACC;IAC3B,IAAID,KAAK,IAAI,IAAI,EAAE;QACjB,OAAOA,KAAK,CAAC;IACf,CAAC;IACD,WAAW;IACX,IAAIA,KAAK,CAACE,MAAM,KAAK,CAAC,IAAK,CAAA,CAACD,gBAAgB,IAAKA,gBAAgB,IAAID,KAAK,KAAK,EAAE,AAAC,CAAA,AAAC,EAAE;QACnF,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAMG,GAAG,GAAGH,KAAK,YAAYI,KAAK,GAAGJ,KAAK,CAAC,CAAC,CAAC,GAAGA,KAAK,AAAC;IACtD,IAAIG,GAAG,IAAI,IAAI,EAAE;QACf,OAAOA,GAAG,CAAC;IACb,CAAC;IACD,IAAI,CAACF,gBAAgB,IAAIE,GAAG,KAAK,EAAE,EAAE;QACnC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAOA,GAAG,CAAC;AACb,CAAC;AAED,mGAAmG,GACnG,OAAO,SAASE,oBAAoB,CAACC,eAAgC,EAA6B;IAChG,IAAI,CAAC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;IAEjE,2EAA2E;IAC3E,yEAAyE;IACzE,MAAM,CAAC0D,oBAAoB,EAAEC,uBAAuB,CAAC,GAAG3D,QAAQ,CAA6ByD,sBAAsB,CAAC,AAAC;IAErH,MAAM,EAAE1B,OAAO,CAAA,EAAE,GAAGG,KAAK,AAAC;IAE1BnC,SAAS,CAAC,IAAM;QACd,sEAAsE;QACtE,IAAIyC,gBAAgB,IAAI,CAACE,YAAY,IAAI,CAACX,OAAO,EAAE;YACjDU,QAAQ,CAAC;gBAAEV,OAAO,EAAE0B,sBAAsB;aAAE,CAAC,CAAC;YAC9Cd,eAAe,CAAC,IAAI,CAAC,CAAC;QACxB,CAAC;IACH,CAAC,EAAE;QAACc,sBAAsB;QAAEjB,gBAAgB;QAAEE,YAAY;QAAEX,OAAO;QAAEU,QAAQ;KAAC,CAAC,CAAC;IAEhF,MAAMmB,kBAAkB,GAAoC9D,WAAW,CACrE,CAACiC,OAAuB,GAAKU,QAAQ,CAAC;YAAEV,OAAO;SAAE,CAAC,EAClD;QAACU,QAAQ;KAAC,CACX,AAAC;IAEF,IAAI,CAACD,gBAAgB,EAAE;QACrB,OAAO;YACLY,eAAe,EAAEM,oBAAoB;YACrCE,kBAAkB,EAAED,uBAAuB;YAC3CN,mBAAmB,EAAEF,sBAAsB,CAACO,oBAAoB,CAAC;SAClE,CAAC;IACJ,CAAC;IACD,OAAO;QACLN,eAAe,EAAEK,sBAAsB;QACvCG,kBAAkB,EAAEA,kBAAkB;QACtCP,mBAAmB,EAAEF,sBAAsB,CAACM,sBAAsB,CAAC;KACpE,CAAC;AACJ,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/runtime/TimeRangeProvider/query-params.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 { useMemo, useCallback, useEffect, useState } from 'react';\nimport { useQueryParams, QueryParamConfig } from 'use-query-params';\nimport { getUnixTime, isDate } from 'date-fns';\nimport {\n TimeRangeValue,\n isRelativeTimeRange,\n isDurationString,\n DurationString,\n AbsoluteTimeRange,\n parseDurationString,\n} from '@perses-dev/core';\nimport { TimeRange } from './TimeRangeProvider';\n\nexport type TimeOptionValue = Date | DurationString | null | undefined;\n\n/* Interprets an encoded string and returns either the string or null/undefined if not available */\nfunction getEncodedValue(\n input: string | Array<string | null> | null | undefined,\n allowEmptyString?: boolean\n): string | null | undefined {\n if (input == null) {\n return input;\n }\n // '' or []\n if (input.length === 0 && (!allowEmptyString || (allowEmptyString && input !== ''))) {\n return null;\n }\n\n const str = input instanceof Array ? input[0] : input;\n if (str == null) {\n return str;\n }\n if (!allowEmptyString && str === '') {\n return null;\n }\n\n return str;\n}\n\n/* Encodes individual TimeRangeValue as a string, depends on whether start is relative or absolute */\nexport function encodeTimeRangeValue(timeOptionValue: TimeOptionValue): string | null | undefined {\n if (!timeOptionValue) {\n return timeOptionValue;\n }\n\n if (typeof timeOptionValue === 'string') {\n if (isDurationString(timeOptionValue)) {\n return timeOptionValue;\n }\n }\n return (getUnixTime(timeOptionValue) * 1000).toString();\n}\n\n/* Converts param input to supported relative or absolute time range format */\nexport function decodeTimeRangeValue(\n input: string | Array<string | null> | null | undefined\n): Date | DurationString | null | undefined {\n const paramString = getEncodedValue(input);\n if (paramString == null) return paramString;\n return isDurationString(paramString) ? paramString : new Date(Number(paramString));\n}\n\n/**\n * Custom TimeRangeValue param type\n * See: https://github.com/pbeshai/use-query-params/tree/master/packages/serialize-query-params#param-types\n */\nexport const TimeRangeParam: QueryParamConfig<TimeOptionValue, TimeOptionValue> = {\n encode: encodeTimeRangeValue,\n decode: decodeTimeRangeValue,\n equals: (valueA: TimeOptionValue, valueB: TimeOptionValue) => {\n if (valueA === valueB) return true;\n if (valueA == null || valueB == null) return valueA === valueB;\n return valueA.valueOf() === valueB.valueOf();\n },\n};\n\nexport const timeRangeQueryConfig = {\n start: TimeRangeParam,\n end: TimeRangeParam,\n};\n\nexport const refreshIntervalQueryConfig = {\n refresh: TimeRangeParam,\n};\n\n/**\n * Gets the initial time range taking into account URL params and dashboard JSON duration\n * Sets start query param if it is empty on page load\n */\nexport function useInitialTimeRange(dashboardDuration: DurationString): TimeRangeValue {\n const [query] = useQueryParams(timeRangeQueryConfig, { updateType: 'replaceIn' });\n const { start, end } = query;\n return useMemo(() => {\n let initialTimeRange: TimeRangeValue = { pastDuration: dashboardDuration };\n if (!start) {\n return initialTimeRange;\n }\n const startStr = start.toString();\n if (isDurationString(startStr)) {\n initialTimeRange = { pastDuration: startStr };\n } else if (isDate(start) && isDate(end)) {\n initialTimeRange = { start: start, end: end } as AbsoluteTimeRange;\n }\n return initialTimeRange;\n }, [start, end, dashboardDuration]);\n}\n\n/**\n * Returns time range getter and setter, set enabledURLParams to false to disable query string serialization\n */\nexport function useSetTimeRangeParams(\n initialTimeRange: TimeRangeValue,\n enabledURLParams = true\n): Pick<TimeRange, 'timeRange' | 'setTimeRange'> {\n const [query, setQuery] = useQueryParams(timeRangeQueryConfig, { updateType: 'replaceIn' });\n\n // determine whether initial param had previously been populated to fix back btn\n const [paramsLoaded, setParamsLoaded] = useState<boolean>(false);\n\n // optional fallback when app does not want query string as source of truth\n // this occurs when enabledURLParams is set to false on TimeRangeProvider\n const [timeRangeState, setTimeRangeState] = useState<TimeRangeValue>(initialTimeRange);\n\n const { start } = query;\n\n useEffect(() => {\n // when dashboard loaded with no params, default to dashboard duration\n if (enabledURLParams && !paramsLoaded && !start) {\n if (isRelativeTimeRange(initialTimeRange)) {\n setQuery({ start: initialTimeRange.pastDuration, end: undefined });\n setParamsLoaded(true);\n }\n }\n }, [initialTimeRange, enabledURLParams, paramsLoaded, start, setQuery]);\n\n const setTimeRange: TimeRange['setTimeRange'] = useCallback(\n (value: TimeRangeValue) => {\n if (isRelativeTimeRange(value)) {\n setQuery({ start: value.pastDuration, end: undefined });\n } else {\n setQuery(value);\n }\n },\n [setQuery]\n );\n\n if (!enabledURLParams) {\n return { timeRange: timeRangeState, setTimeRange: setTimeRangeState };\n }\n return { timeRange: initialTimeRange, setTimeRange: setTimeRange };\n}\n\n/**\n * Gets the initial refresh interval taking into account URL params and dashboard JSON duration\n * Sets refresh query param if it is empty on page load\n */\nexport function useInitialRefreshInterval(dashboardDuration: DurationString): DurationString {\n const [query] = useQueryParams(refreshIntervalQueryConfig, { updateType: 'replaceIn' });\n const { refresh } = query;\n return useMemo(() => {\n let initialTimeRange: DurationString = dashboardDuration;\n if (!refresh) {\n return initialTimeRange;\n }\n const startStr = refresh.toString();\n if (isDurationString(startStr)) {\n initialTimeRange = startStr;\n }\n return initialTimeRange;\n }, [dashboardDuration, refresh]);\n}\n\nfunction getRefreshIntervalInMs(refreshInterval?: DurationString) {\n let refreshIntervalInMs = 0;\n if (refreshInterval) {\n const refreshIntervalDuration = parseDurationString(refreshInterval);\n if (refreshIntervalDuration && refreshIntervalDuration.seconds) {\n refreshIntervalInMs = refreshIntervalDuration?.seconds * 1000;\n }\n }\n return refreshIntervalInMs;\n}\n\n/**\n * Returns refresh interval getter and setter, set enabledURLParams to false to disable query string serialization\n */\nexport function useSetRefreshIntervalParams(\n initialRefreshInterval?: DurationString,\n enabledURLParams = true\n): Pick<TimeRange, 'refreshInterval' | 'setRefreshInterval' | 'refreshIntervalInMs'> {\n const [query, setQuery] = useQueryParams(refreshIntervalQueryConfig, { updateType: 'replaceIn' });\n\n // determine whether initial param had previously been populated to fix back btn\n const [paramsLoaded, setParamsLoaded] = useState<boolean>(false);\n\n // optional fallback when app does not want query string as source of truth\n // this occurs when enabledURLParams is set to false on TimeRangeProvider\n const [refreshIntervalState, setRefreshIntervalState] = useState<DurationString | undefined>(initialRefreshInterval);\n\n const { refresh } = query;\n\n useEffect(() => {\n // when dashboard loaded with no params, default to dashboard refresh interval\n if (enabledURLParams && !paramsLoaded && !refresh) {\n setQuery({ refresh: initialRefreshInterval });\n setParamsLoaded(true);\n }\n }, [initialRefreshInterval, enabledURLParams, paramsLoaded, refresh, setQuery]);\n\n const setRefreshInterval: TimeRange['setRefreshInterval'] = useCallback(\n (refresh: DurationString) => setQuery({ refresh }),\n [setQuery]\n );\n\n if (!enabledURLParams) {\n return {\n refreshInterval: refreshIntervalState,\n setRefreshInterval: setRefreshIntervalState,\n refreshIntervalInMs: getRefreshIntervalInMs(refreshIntervalState),\n };\n }\n return {\n refreshInterval: initialRefreshInterval,\n setRefreshInterval: setRefreshInterval,\n refreshIntervalInMs: getRefreshIntervalInMs(initialRefreshInterval),\n };\n}\n"],"names":["useMemo","useCallback","useEffect","useState","useQueryParams","getUnixTime","isDate","isRelativeTimeRange","isDurationString","parseDurationString","getEncodedValue","input","allowEmptyString","length","str","Array","encodeTimeRangeValue","timeOptionValue","toString","decodeTimeRangeValue","paramString","Date","Number","TimeRangeParam","encode","decode","equals","valueA","valueB","valueOf","timeRangeQueryConfig","start","end","refreshIntervalQueryConfig","refresh","useInitialTimeRange","dashboardDuration","query","updateType","initialTimeRange","pastDuration","startStr","useSetTimeRangeParams","enabledURLParams","setQuery","paramsLoaded","setParamsLoaded","timeRangeState","setTimeRangeState","undefined","setTimeRange","value","timeRange","useInitialRefreshInterval","getRefreshIntervalInMs","refreshInterval","refreshIntervalInMs","refreshIntervalDuration","seconds","useSetRefreshIntervalParams","initialRefreshInterval","refreshIntervalState","setRefreshIntervalState","setRefreshInterval"],"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,OAAO,EAAEC,WAAW,EAAEC,SAA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AwB,GAAG3D,SAAqCyD;IAE7F,MAAM,EAAE1B,QAAO,EAAE,GAAGG;IAEpBnC,UAAU;QACR,8EAA8E;QAC9E,IAAIyC,oBAAoB,CAACE,gBAAgB,CAACX,SAAS;YACjDU,SAAS;gBAAEV,SAAS0B;YAAuB;YAC3Cd,gBAAgB;QAClB;IACF,GAAG;QAACc;QAAwBjB;QAAkBE;QAAcX;QAASU;KAAS;IAE9E,MAAMmB,qBAAsD9D,YAC1D,CAACiC,UAA4BU,SAAS;YAAEV;QAAQ,IAChD;QAACU;KAAS;IAGZ,IAAI,CAACD,kBAAkB;QACrB,OAAO;YACLY,iBAAiBM;YACjBE,oBAAoBD;YACpBN,qBAAqBF,uBAAuBO;QAC9C;IACF;IACA,OAAO;QACLN,iBAAiBK;QACjBG,oBAAoBA;QACpBP,qBAAqBF,uBAAuBM;IAC9C;AACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { BuiltinVariableDefinition } from '@perses-dev/core';
|
|
3
|
+
import { VariableStateMap } from './template-variables';
|
|
4
|
+
export declare type BuiltinVariableSrv = {
|
|
5
|
+
variables: BuiltinVariableDefinition[];
|
|
6
|
+
};
|
|
7
|
+
export declare const BuiltinVariableContext: import("react").Context<BuiltinVariableSrv | undefined>;
|
|
8
|
+
export declare function useBuiltinVariableContext(): BuiltinVariableSrv;
|
|
9
|
+
export declare function useBuiltinVariableValues(names?: string[]): VariableStateMap;
|
|
10
|
+
export declare function useBuiltinVariableDefinitions(): BuiltinVariableDefinition[];
|
|
11
|
+
//# sourceMappingURL=builtin-variables.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builtin-variables.d.ts","sourceRoot":"","sources":["../../src/runtime/builtin-variables.ts"],"names":[],"mappings":";AAcA,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD,oBAAY,kBAAkB,GAAG;IAC/B,SAAS,EAAE,yBAAyB,EAAE,CAAC;CACxC,CAAC;AAEF,eAAO,MAAM,sBAAsB,yDAA2D,CAAC;AAE/F,wBAAgB,yBAAyB,uBAMxC;AAED,wBAAgB,wBAAwB,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,gBAAgB,CA0B3E;AAED,wBAAgB,6BAA6B,IAAI,yBAAyB,EAAE,CAG3E"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { createContext, useContext, useMemo } from 'react';
|
|
14
|
+
export const BuiltinVariableContext = createContext(undefined);
|
|
15
|
+
export function useBuiltinVariableContext() {
|
|
16
|
+
const ctx = useContext(BuiltinVariableContext);
|
|
17
|
+
if (ctx === undefined) {
|
|
18
|
+
throw new Error('No BuiltinVariableContext found. Did you forget a Provider?');
|
|
19
|
+
}
|
|
20
|
+
return ctx;
|
|
21
|
+
}
|
|
22
|
+
export function useBuiltinVariableValues(names) {
|
|
23
|
+
const { variables } = useBuiltinVariableContext();
|
|
24
|
+
const states = useMemo(()=>{
|
|
25
|
+
const values = {};
|
|
26
|
+
for (const variable of variables){
|
|
27
|
+
values[variable.spec.name] = {
|
|
28
|
+
loading: false,
|
|
29
|
+
value: variable.spec.value()
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
return values;
|
|
33
|
+
}, [
|
|
34
|
+
variables
|
|
35
|
+
]);
|
|
36
|
+
const values = useMemo(()=>{
|
|
37
|
+
const values = {};
|
|
38
|
+
names === null || names === void 0 ? void 0 : names.forEach((name)=>{
|
|
39
|
+
const s = states[name];
|
|
40
|
+
if (s) {
|
|
41
|
+
values[name] = s;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
return values;
|
|
45
|
+
}, [
|
|
46
|
+
names,
|
|
47
|
+
states
|
|
48
|
+
]);
|
|
49
|
+
if (names === undefined) {
|
|
50
|
+
return states;
|
|
51
|
+
}
|
|
52
|
+
return values;
|
|
53
|
+
}
|
|
54
|
+
export function useBuiltinVariableDefinitions() {
|
|
55
|
+
const { variables } = useBuiltinVariableContext();
|
|
56
|
+
return variables;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=builtin-variables.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/runtime/builtin-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 { BuiltinVariableDefinition } from '@perses-dev/core';\nimport { VariableStateMap } from './template-variables';\n\nexport type BuiltinVariableSrv = {\n variables: BuiltinVariableDefinition[];\n};\n\nexport const BuiltinVariableContext = createContext<BuiltinVariableSrv | undefined>(undefined);\n\nexport function useBuiltinVariableContext() {\n const ctx = useContext(BuiltinVariableContext);\n if (ctx === undefined) {\n throw new Error('No BuiltinVariableContext found. Did you forget a Provider?');\n }\n return ctx;\n}\n\nexport function useBuiltinVariableValues(names?: string[]): VariableStateMap {\n const { variables } = useBuiltinVariableContext();\n const states = useMemo(() => {\n const values: VariableStateMap = {};\n for (const variable of variables) {\n values[variable.spec.name] = { loading: false, value: variable.spec.value() };\n }\n return values;\n }, [variables]);\n\n const values = useMemo(() => {\n const values: VariableStateMap = {};\n names?.forEach((name) => {\n const s = states[name];\n if (s) {\n values[name] = s;\n }\n });\n return values;\n }, [names, states]);\n\n if (names === undefined) {\n return states;\n }\n\n return values;\n}\n\nexport function useBuiltinVariableDefinitions(): BuiltinVariableDefinition[] {\n const { variables } = useBuiltinVariableContext();\n return variables;\n}\n"],"names":["createContext","useContext","useMemo","BuiltinVariableContext","undefined","useBuiltinVariableContext","ctx","Error","useBuiltinVariableValues","names","variables","states","values","variable","spec","name","loading","value","forEach","s","useBuiltinVariableDefinitions"],"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;AAQ3D,OAAO,MAAMC,yBAAyBH,cAA8CI,WAAW;AAE/F,OAAO,SAASC;IACd,MAAMC,MAAML,WAAWE;IACvB,IAAIG,QAAQF,WAAW;QACrB,MAAM,IAAIG,MAAM;IAClB;IACA,OAAOD;AACT;AAEA,OAAO,SAASE,yBAAyBC,KAAgB;IACvD,MAAM,EAAEC,UAAS,EAAE,GAAGL;IACtB,MAAMM,SAAST,QAAQ;QACrB,MAAMU,SAA2B,CAAC;QAClC,KAAK,MAAMC,YAAYH,UAAW;YAChCE,MAAM,CAACC,SAASC,KAAKC,KAAK,GAAG;gBAAEC,SAAS;gBAAOC,OAAOJ,SAASC,KAAKG;YAAQ;QAC9E;QACA,OAAOL;IACT,GAAG;QAACF;KAAU;IAEd,MAAME,SAASV,QAAQ;QACrB,MAAMU,SAA2B,CAAC;QAClCH,kBAAAA,mBAAAA,KAAAA,IAAAA,MAAOS,QAAQ,CAACH;YACd,MAAMI,IAAIR,MAAM,CAACI,KAAK;YACtB,IAAII,GAAG;gBACLP,MAAM,CAACG,KAAK,GAAGI;YACjB;QACF;QACA,OAAOP;IACT,GAAG;QAACH;QAAOE;KAAO;IAElB,IAAIF,UAAUL,WAAW;QACvB,OAAOO;IACT;IAEA,OAAOC;AACT;AAEA,OAAO,SAASQ;IACd,MAAM,EAAEV,UAAS,EAAE,GAAGL;IACtB,OAAOK;AACT"}
|
|
@@ -7,23 +7,31 @@ export interface DatasourceStore {
|
|
|
7
7
|
*/
|
|
8
8
|
getDatasourceClient<Client>(selector: DatasourceSelector): Promise<Client>;
|
|
9
9
|
/**
|
|
10
|
-
* Gets a list of datasource
|
|
10
|
+
* Gets a list of datasource selection items for a plugin kind.
|
|
11
11
|
*/
|
|
12
|
-
|
|
12
|
+
listDatasourceSelectItems(datasourcePluginKind: string): Promise<DatasourceSelectItemGroup[]>;
|
|
13
13
|
}
|
|
14
|
-
export interface
|
|
14
|
+
export interface DatasourceSelectItemGroup {
|
|
15
|
+
group?: string;
|
|
16
|
+
editLink?: string;
|
|
17
|
+
items: DatasourceSelectItem[];
|
|
18
|
+
}
|
|
19
|
+
export interface DatasourceSelectItem {
|
|
15
20
|
name: string;
|
|
21
|
+
overridden?: boolean;
|
|
22
|
+
overriding?: boolean;
|
|
16
23
|
selector: DatasourceSelector;
|
|
17
24
|
}
|
|
18
25
|
export declare const DatasourceStoreContext: import("react").Context<DatasourceStore | undefined>;
|
|
19
26
|
export declare function useDatasourceStore(): DatasourceStore;
|
|
20
27
|
/**
|
|
21
|
-
* Lists all available Datasource
|
|
22
|
-
*
|
|
28
|
+
* Lists all available Datasource selection items for a given datasource plugin kind.
|
|
29
|
+
* Returns a list, with all information that can be used in a datasource selection context (group, name, selector, kind, ...)
|
|
23
30
|
*/
|
|
24
|
-
export declare function
|
|
31
|
+
export declare function useListDatasourceSelectItems(datasourcePluginKind: string): import("@tanstack/react-query").UseQueryResult<DatasourceSelectItemGroup[], unknown>;
|
|
25
32
|
/**
|
|
26
33
|
* Provides a convenience hook for getting a DatasourceClient for a given DatasourceSelector.
|
|
27
34
|
*/
|
|
28
35
|
export declare function useDatasourceClient<Client>(selector: DatasourceSelector): import("@tanstack/react-query").UseQueryResult<Client, unknown>;
|
|
36
|
+
export declare function useDatasource(selector: DatasourceSelector): import("@tanstack/react-query").UseQueryResult<DatasourceSpec<import("@perses-dev/core").UnknownSpec>, unknown>;
|
|
29
37
|
//# sourceMappingURL=datasources.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datasources.d.ts","sourceRoot":"","sources":["../../src/runtime/datasources.ts"],"names":[],"mappings":";AAaA,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAItE,MAAM,WAAW,eAAe;IAE9B,aAAa,CAAC,QAAQ,EAAE,kBAAkB,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IAErE;;OAEG;IACH,mBAAmB,CAAC,MAAM,EAAE,QAAQ,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE3E;;OAEG;IACH,
|
|
1
|
+
{"version":3,"file":"datasources.d.ts","sourceRoot":"","sources":["../../src/runtime/datasources.ts"],"names":[],"mappings":";AAaA,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAItE,MAAM,WAAW,eAAe;IAE9B,aAAa,CAAC,QAAQ,EAAE,kBAAkB,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IAErE;;OAEG;IACH,mBAAmB,CAAC,MAAM,EAAE,QAAQ,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE3E;;OAEG;IACH,yBAAyB,CAAC,oBAAoB,EAAE,MAAM,GAAG,OAAO,CAAC,yBAAyB,EAAE,CAAC,CAAC;CAC/F;AAED,MAAM,WAAW,yBAAyB;IACxC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,oBAAoB,EAAE,CAAC;CAC/B;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,QAAQ,EAAE,kBAAkB,CAAC;CAC9B;AAED,eAAO,MAAM,sBAAsB,sDAAwD,CAAC;AAE5F,wBAAgB,kBAAkB,oBAMjC;AAED;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,oBAAoB,EAAE,MAAM,wFAKxE;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,QAAQ,EAAE,kBAAkB,mEAGvE;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,kBAAkB,mHAGzD"}
|
|
@@ -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;AAEhG,MAAM,WAAW,yBAAyB;IACxC,SAAS,CAAC,CAAC,SAAS,UAAU,EAAE,UAAU,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/F,kBAAkB,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;IACtE,kBAAkB,EAAE,kBAAkB,CAAC;CACxC;AAED,eAAO,MAAM,qBAAqB,gEAAkE,CAAC;AAErG;;;GAGG;AACH,wBAAgB,iBAAiB,8BAMhC;AAGD,aAAK,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,EAAE,MAAM,CAAC,CAAC,EACtG,UAAU,GAAG,SAAS,CACvB,CAAC;AAEF;;GAEG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,UAAU,EAAE,UAAU,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,kFAQzG;AAED;;GAE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