@perses-dev/plugin-system 0.55.0-beta.10 → 0.55.0-beta.12
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/components/MultiQueryEditor/MultiQueryEditor.d.ts.map +1 -1
- package/dist/components/MultiQueryEditor/MultiQueryEditor.js +16 -1
- package/dist/components/MultiQueryEditor/MultiQueryEditor.js.map +1 -1
- package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts.map +1 -1
- package/dist/components/PanelSpecEditor/PanelSpecEditor.js +4 -1
- package/dist/components/PanelSpecEditor/PanelSpecEditor.js.map +1 -1
- package/dist/components/PluginEditor/plugin-editor-api.d.ts +7 -1
- package/dist/components/PluginEditor/plugin-editor-api.d.ts.map +1 -1
- package/dist/components/PluginEditor/plugin-editor-api.js +6 -1
- package/dist/components/PluginEditor/plugin-editor-api.js.map +1 -1
- package/dist/components/PluginKindSelect/PluginKindSelect.d.ts +14 -0
- package/dist/components/PluginKindSelect/PluginKindSelect.d.ts.map +1 -1
- package/dist/components/PluginKindSelect/PluginKindSelect.js +187 -23
- package/dist/components/PluginKindSelect/PluginKindSelect.js.map +1 -1
- package/dist/components/PluginRegistry/PluginRegistry.d.ts.map +1 -1
- package/dist/components/PluginRegistry/PluginRegistry.js +67 -4
- package/dist/components/PluginRegistry/PluginRegistry.js.map +1 -1
- package/dist/components/PluginRegistry/plugin-indexes.d.ts +1 -0
- package/dist/components/PluginRegistry/plugin-indexes.d.ts.map +1 -1
- package/dist/components/PluginRegistry/plugin-indexes.js +6 -1
- package/dist/components/PluginRegistry/plugin-indexes.js.map +1 -1
- package/dist/components/PluginSpecEditor/PluginSpecEditor.d.ts.map +1 -1
- package/dist/components/PluginSpecEditor/PluginSpecEditor.js +6 -2
- package/dist/components/PluginSpecEditor/PluginSpecEditor.js.map +1 -1
- package/dist/components/Variables/variable-model.d.ts.map +1 -1
- package/dist/components/Variables/variable-model.js +7 -2
- package/dist/components/Variables/variable-model.js.map +1 -1
- package/dist/model/plugins.d.ts +11 -0
- package/dist/model/plugins.d.ts.map +1 -1
- package/dist/model/plugins.js.map +1 -1
- package/dist/remote/PluginRuntime.js +10 -10
- package/dist/remote/PluginRuntime.js.map +1 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeProviders.d.ts +3 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeProviders.d.ts.map +1 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeProviders.js +2 -2
- package/dist/runtime/TimeRangeProvider/TimeRangeProviders.js.map +1 -1
- package/dist/runtime/alerts-queries.d.ts.map +1 -1
- package/dist/runtime/alerts-queries.js +6 -2
- package/dist/runtime/alerts-queries.js.map +1 -1
- package/dist/runtime/annotations.d.ts.map +1 -1
- package/dist/runtime/annotations.js +10 -3
- package/dist/runtime/annotations.js.map +1 -1
- package/dist/runtime/log-queries.d.ts.map +1 -1
- package/dist/runtime/log-queries.js +3 -1
- package/dist/runtime/log-queries.js.map +1 -1
- package/dist/runtime/plugin-registry.d.ts +22 -8
- package/dist/runtime/plugin-registry.d.ts.map +1 -1
- package/dist/runtime/plugin-registry.js +52 -16
- package/dist/runtime/plugin-registry.js.map +1 -1
- package/dist/runtime/profile-queries.d.ts.map +1 -1
- package/dist/runtime/profile-queries.js +3 -1
- package/dist/runtime/profile-queries.js.map +1 -1
- package/dist/runtime/silences-queries.d.ts.map +1 -1
- package/dist/runtime/silences-queries.js +6 -2
- package/dist/runtime/silences-queries.js.map +1 -1
- package/dist/runtime/time-series-queries.d.ts.map +1 -1
- package/dist/runtime/time-series-queries.js +10 -3
- package/dist/runtime/time-series-queries.js.map +1 -1
- package/dist/runtime/trace-queries.d.ts.map +1 -1
- package/dist/runtime/trace-queries.js +6 -2
- package/dist/runtime/trace-queries.js.map +1 -1
- package/dist/runtime/variables.d.ts +6 -0
- package/dist/runtime/variables.d.ts.map +1 -1
- package/dist/runtime/variables.js +17 -1
- package/dist/runtime/variables.js.map +1 -1
- 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/plugin-versions.d.ts +18 -0
- package/dist/utils/plugin-versions.d.ts.map +1 -0
- package/dist/utils/plugin-versions.js +52 -0
- package/dist/utils/plugin-versions.js.map +1 -0
- package/package.json +5 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/remote/PluginRuntime.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport * as EmotionReact from '@emotion/react';\nimport * as EmotionStyled from '@emotion/styled';\nimport type { ModuleFederation } from '@module-federation/enhanced/runtime';\nimport { createInstance } from '@module-federation/enhanced/runtime';\nimport * as ReactQuery from '@tanstack/react-query';\nimport React from 'react';\nimport ReactDOM from 'react-dom';\nimport * as ReactHookForm from 'react-hook-form';\nimport * as ReactRouterDOM from 'react-router-dom';\n\nimport type { PersesPlugin, RemotePluginModule } from './PersesPlugin.types';\n\nlet instance: ModuleFederation | null = null;\n\nfunction createSharedModuleLoader<TModule>(loadModule: () => Promise<TModule>): () => Promise<() => TModule> {\n return async () => {\n const module = await loadModule();\n return () => module;\n };\n}\n\nexport interface HostSharedModules {\n '@perses-dev/spec': unknown;\n '@perses-dev/client': unknown;\n '@perses-dev/components': unknown;\n '@perses-dev/plugin-system': unknown;\n '@perses-dev/explore': unknown;\n '@perses-dev/dashboards': unknown;\n}\n\ntype HostSharedModuleName = keyof HostSharedModules;\n\nconst hostSharedModules = new Map<HostSharedModuleName, unknown>();\n\n/*\n * Shared singletons must be provided to Module Federation *synchronously* (via `lib`) so the host's\n * copy wins singleton negotiation to avoid loader deadlocks or multiple instances.\n */\nexport function registerHostSharedModules(modules: HostSharedModules): void {\n for (const [name, module] of Object.entries(modules) as Array<[HostSharedModuleName, unknown]>) {\n hostSharedModules.set(name, module);\n }\n}\n\nfunction getHostSharedModule(name: HostSharedModuleName): unknown {\n const module = hostSharedModules.get(name);\n if (!module) {\n throw new Error(\n `Shared module \"${name}\" was not registered before a plugin tried to consume it. ` +\n `Call registerHostSharedModules() during app bootstrap.`,\n );\n }\n return module;\n}\n\nconst getPluginRuntime = (): ModuleFederation => {\n if (instance === null) {\n const pluginRuntime = createInstance({\n name: '@perses/perses-ui-host',\n remotes: [], // all remotes are loaded dynamically\n shared: {\n react: {\n version: React.version,\n lib: () => React,\n shareConfig: {\n singleton: true,\n requiredVersion: `^${React.version}`,\n },\n },\n 'react-dom': {\n version: '18.3.1',\n lib: () => ReactDOM,\n shareConfig: {\n singleton: true,\n requiredVersion: `^18.3.1`,\n },\n },\n 'react-router-dom': {\n version: '6.30.4',\n lib: () => ReactRouterDOM,\n shareConfig: {\n singleton: true,\n requiredVersion: '^6.26.0',\n },\n },\n '@tanstack/react-query': {\n version: '4.44.0',\n lib: () => ReactQuery,\n shareConfig: {\n singleton: true,\n requiredVersion: '^4.39.1',\n },\n },\n 'react-hook-form': {\n version: '7.87.0',\n lib: () => ReactHookForm,\n shareConfig: {\n singleton: true,\n requiredVersion: '^7.87.0',\n },\n },\n '@emotion/react': {\n version: '11.14.0',\n lib: () => EmotionReact,\n shareConfig: {\n singleton: true,\n requiredVersion: '^11.11.3',\n },\n },\n '@emotion/styled': {\n version: '11.14.1',\n lib: () => EmotionStyled,\n shareConfig: {\n singleton: true,\n requiredVersion: '^11.11.0',\n },\n },\n '@perses-dev/spec': {\n version: '0.3.0-beta.8',\n lib: () => getHostSharedModule('@perses-dev/spec'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.3.0-beta.8',\n },\n },\n '@perses-dev/client': {\n version: '0.55.0-beta.10',\n lib: () => getHostSharedModule('@perses-dev/client'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.55.0-beta.10',\n },\n },\n '@perses-dev/components': {\n version: '0.55.0-beta.10',\n lib: () => getHostSharedModule('@perses-dev/components'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.55.0-beta.10',\n },\n },\n '@perses-dev/plugin-system': {\n version: '0.55.0-beta.10',\n lib: () => getHostSharedModule('@perses-dev/plugin-system'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.55.0-beta.10',\n },\n },\n '@perses-dev/explore': {\n version: '0.55.0-beta.10',\n lib: () => getHostSharedModule('@perses-dev/explore'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.55.0-beta.10',\n },\n },\n '@perses-dev/dashboards': {\n version: '0.55.0-beta.10',\n lib: () => getHostSharedModule('@perses-dev/dashboards'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.55.0-beta.10',\n },\n },\n // Below are the shared modules that are used by the plugins and are loaded asynchronously on demand using get rather than lib.\n // This is to avoid loading the modules if they are not used by the plugin.\n echarts: {\n version: '5.5.0',\n get: createSharedModuleLoader(() => import('echarts')),\n shareConfig: {\n singleton: true,\n requiredVersion: '^5.5.0',\n },\n },\n 'date-fns': {\n version: '4.2.1',\n get: createSharedModuleLoader(() => import('date-fns')),\n shareConfig: {\n singleton: true,\n requiredVersion: '^4.1.0',\n },\n },\n 'date-fns-tz': {\n version: '3.2.0',\n get: createSharedModuleLoader(() => import('date-fns-tz')),\n shareConfig: {\n singleton: true,\n requiredVersion: '^3.2.0',\n },\n },\n lodash: {\n version: '4.18.1',\n get: createSharedModuleLoader(() => import('lodash')),\n shareConfig: {\n singleton: true,\n requiredVersion: '^4.17.21',\n },\n },\n '@hookform/resolvers/zod': {\n version: '5.9.1',\n get: createSharedModuleLoader(() => import('@hookform/resolvers/zod')),\n shareConfig: {\n singleton: true,\n requiredVersion: '^5.9.1',\n },\n },\n 'use-resize-observer': {\n version: '9.1.0',\n get: createSharedModuleLoader(() => import('use-resize-observer')),\n shareConfig: {\n singleton: true,\n requiredVersion: '^9.1.0',\n },\n },\n 'mdi-material-ui': {\n version: '7.9.4',\n get: createSharedModuleLoader(() => import('mdi-material-ui')),\n shareConfig: {\n singleton: true,\n requiredVersion: '^7.4.0',\n },\n },\n immer: {\n version: '10.2.0',\n get: createSharedModuleLoader(() => import('immer')),\n shareConfig: {\n singleton: true,\n requiredVersion: '^10.1.1',\n },\n },\n },\n });\n\n instance = pluginRuntime;\n\n return instance;\n }\n return instance;\n};\n\nfunction getModuleFederationRemoteName(name: string, registry?: string, version?: string): string {\n return `${name}:${registry ?? ''}:${version ?? ''}`;\n}\n\nconst registerRemote = (name: string, registry?: string, version?: string, baseURL?: string): void => {\n const pluginRuntime = getPluginRuntime();\n const registryName = getModuleFederationRemoteName(name, registry, version);\n\n const existingRemote = pluginRuntime.options.remotes.find((remote) => remote.name === registryName);\n if (!existingRemote) {\n const nameVersionRegistry = [name, version, registry].filter(Boolean).join('~');\n const prefix = baseURL || '/plugins';\n const remoteEntryURL = `${prefix}/${nameVersionRegistry}/mf-manifest.json`;\n\n pluginRuntime.registerRemotes([\n {\n name: registryName,\n entry: remoteEntryURL,\n alias: registryName,\n },\n ]);\n }\n};\n\nexport const loadPlugin = async (target: {\n moduleName: string;\n pluginName: string;\n registry?: string;\n version?: string;\n baseURL?: string;\n}): Promise<RemotePluginModule | null> => {\n const { moduleName, pluginName, registry, version, baseURL } = target;\n registerRemote(moduleName, registry, version, baseURL);\n\n const pluginRuntime = getPluginRuntime();\n const registryName = getModuleFederationRemoteName(moduleName, registry, version);\n return pluginRuntime.loadRemote<RemotePluginModule>(`${registryName}/${pluginName}`);\n};\n\nexport function usePluginRuntime({ plugin }: { plugin: PersesPlugin }): {\n pluginRuntime: ModuleFederation;\n loadPlugin: () => Promise<RemotePluginModule | null>;\n} {\n return {\n pluginRuntime: getPluginRuntime(),\n loadPlugin: (): Promise<RemotePluginModule | null> => {\n const { moduleName, name: pluginName, registry, version, baseURL } = plugin;\n return loadPlugin({ moduleName, pluginName, registry, version, baseURL });\n },\n };\n}\n"],"names":["EmotionReact","EmotionStyled","createInstance","ReactQuery","React","ReactDOM","ReactHookForm","ReactRouterDOM","instance","createSharedModuleLoader","loadModule","module","hostSharedModules","Map","registerHostSharedModules","modules","name","Object","entries","set","getHostSharedModule","get","Error","getPluginRuntime","pluginRuntime","remotes","shared","react","version","lib","shareConfig","singleton","requiredVersion","echarts","lodash","immer","getModuleFederationRemoteName","registry","registerRemote","baseURL","registryName","existingRemote","options","find","remote","nameVersionRegistry","filter","Boolean","join","prefix","remoteEntryURL","registerRemotes","entry","alias","loadPlugin","target","moduleName","pluginName","loadRemote","usePluginRuntime","plugin"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,YAAYA,kBAAkB,iBAAiB;AAC/C,YAAYC,mBAAmB,kBAAkB;AAEjD,SAASC,cAAc,QAAQ,sCAAsC;AACrE,YAAYC,gBAAgB,wBAAwB;AACpD,OAAOC,WAAW,QAAQ;AAC1B,OAAOC,cAAc,YAAY;AACjC,YAAYC,mBAAmB,kBAAkB;AACjD,YAAYC,oBAAoB,mBAAmB;AAInD,IAAIC,WAAoC;AAExC,SAASC,yBAAkCC,UAAkC;IAC3E,OAAO;QACL,MAAMC,SAAS,MAAMD;QACrB,OAAO,IAAMC;IACf;AACF;AAaA,MAAMC,oBAAoB,IAAIC;AAE9B;;;CAGC,GACD,OAAO,SAASC,0BAA0BC,OAA0B;IAClE,KAAK,MAAM,CAACC,MAAML,OAAO,IAAIM,OAAOC,OAAO,CAACH,SAAoD;QAC9FH,kBAAkBO,GAAG,CAACH,MAAML;IAC9B;AACF;AAEA,SAASS,oBAAoBJ,IAA0B;IACrD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UAAU,EAAEC,UAAU,EAAEpB,QAAQ,EAAET,OAAO,EAAEW,OAAO,EAAE,GAAGgB;IAC/DjB,eAAekB,YAAYnB,UAAUT,SAASW;IAE9C,MAAMf,gBAAgBD;IACtB,MAAMiB,eAAeJ,8BAA8BoB,YAAYnB,UAAUT;IACzE,OAAOJ,cAAckC,UAAU,CAAqB,GAAGlB,aAAa,CAAC,EAAEiB,YAAY;AACrF,EAAE;AAEF,OAAO,SAASE,iBAAiB,EAAEC,MAAM,EAA4B;IAInE,OAAO;QACLpC,eAAeD;QACf+B,YAAY;YACV,MAAM,EAAEE,UAAU,EAAExC,MAAMyC,UAAU,EAAEpB,QAAQ,EAAET,OAAO,EAAEW,OAAO,EAAE,GAAGqB;YACrE,OAAON,WAAW;gBAAEE;gBAAYC;gBAAYpB;gBAAUT;gBAASW;YAAQ;QACzE;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../src/remote/PluginRuntime.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport * as EmotionReact from '@emotion/react';\nimport * as EmotionStyled from '@emotion/styled';\nimport type { ModuleFederation } from '@module-federation/enhanced/runtime';\nimport { createInstance } from '@module-federation/enhanced/runtime';\nimport * as ReactQuery from '@tanstack/react-query';\nimport React from 'react';\nimport ReactDOM from 'react-dom';\nimport * as ReactHookForm from 'react-hook-form';\nimport * as ReactRouterDOM from 'react-router-dom';\n\nimport type { PersesPlugin, RemotePluginModule } from './PersesPlugin.types';\n\nlet instance: ModuleFederation | null = null;\n\nfunction createSharedModuleLoader<TModule>(loadModule: () => Promise<TModule>): () => Promise<() => TModule> {\n return async () => {\n const module = await loadModule();\n return () => module;\n };\n}\n\nexport interface HostSharedModules {\n '@perses-dev/spec': unknown;\n '@perses-dev/client': unknown;\n '@perses-dev/components': unknown;\n '@perses-dev/plugin-system': unknown;\n '@perses-dev/explore': unknown;\n '@perses-dev/dashboards': unknown;\n}\n\ntype HostSharedModuleName = keyof HostSharedModules;\n\nconst hostSharedModules = new Map<HostSharedModuleName, unknown>();\n\n/*\n * Shared singletons must be provided to Module Federation *synchronously* (via `lib`) so the host's\n * copy wins singleton negotiation to avoid loader deadlocks or multiple instances.\n */\nexport function registerHostSharedModules(modules: HostSharedModules): void {\n for (const [name, module] of Object.entries(modules) as Array<[HostSharedModuleName, unknown]>) {\n hostSharedModules.set(name, module);\n }\n}\n\nfunction getHostSharedModule(name: HostSharedModuleName): unknown {\n const module = hostSharedModules.get(name);\n if (!module) {\n throw new Error(\n `Shared module \"${name}\" was not registered before a plugin tried to consume it. ` +\n `Call registerHostSharedModules() during app bootstrap.`,\n );\n }\n return module;\n}\n\nconst getPluginRuntime = (): ModuleFederation => {\n if (instance === null) {\n const pluginRuntime = createInstance({\n name: '@perses/perses-ui-host',\n remotes: [], // all remotes are loaded dynamically\n shared: {\n react: {\n version: React.version,\n lib: () => React,\n shareConfig: {\n singleton: true,\n requiredVersion: `^${React.version}`,\n },\n },\n 'react-dom': {\n version: '18.3.1',\n lib: () => ReactDOM,\n shareConfig: {\n singleton: true,\n requiredVersion: `^18.3.1`,\n },\n },\n 'react-router-dom': {\n version: '6.30.4',\n lib: () => ReactRouterDOM,\n shareConfig: {\n singleton: true,\n requiredVersion: '^6.26.0',\n },\n },\n '@tanstack/react-query': {\n version: '4.44.0',\n lib: () => ReactQuery,\n shareConfig: {\n singleton: true,\n requiredVersion: '^4.39.1',\n },\n },\n 'react-hook-form': {\n version: '7.87.0',\n lib: () => ReactHookForm,\n shareConfig: {\n singleton: true,\n requiredVersion: '^7.87.0',\n },\n },\n '@emotion/react': {\n version: '11.14.0',\n lib: () => EmotionReact,\n shareConfig: {\n singleton: true,\n requiredVersion: '^11.11.3',\n },\n },\n '@emotion/styled': {\n version: '11.14.1',\n lib: () => EmotionStyled,\n shareConfig: {\n singleton: true,\n requiredVersion: '^11.11.0',\n },\n },\n '@perses-dev/spec': {\n version: '0.3.0-beta.8',\n lib: () => getHostSharedModule('@perses-dev/spec'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.3.0-beta.8',\n },\n },\n '@perses-dev/client': {\n version: '0.55.0-beta.12',\n lib: () => getHostSharedModule('@perses-dev/client'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.55.0-beta.12',\n },\n },\n '@perses-dev/components': {\n version: '0.55.0-beta.12',\n lib: () => getHostSharedModule('@perses-dev/components'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.55.0-beta.12',\n },\n },\n '@perses-dev/plugin-system': {\n version: '0.55.0-beta.12',\n lib: () => getHostSharedModule('@perses-dev/plugin-system'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.55.0-beta.12',\n },\n },\n '@perses-dev/explore': {\n version: '0.55.0-beta.12',\n lib: () => getHostSharedModule('@perses-dev/explore'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.55.0-beta.12',\n },\n },\n '@perses-dev/dashboards': {\n version: '0.55.0-beta.12',\n lib: () => getHostSharedModule('@perses-dev/dashboards'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.55.0-beta.12',\n },\n },\n // Below are the shared modules that are used by the plugins and are loaded asynchronously on demand using get rather than lib.\n // This is to avoid loading the modules if they are not used by the plugin.\n echarts: {\n version: '5.5.0',\n get: createSharedModuleLoader(() => import('echarts')),\n shareConfig: {\n singleton: true,\n requiredVersion: '^5.5.0',\n },\n },\n 'date-fns': {\n version: '4.2.1',\n get: createSharedModuleLoader(() => import('date-fns')),\n shareConfig: {\n singleton: true,\n requiredVersion: '^4.1.0',\n },\n },\n 'date-fns-tz': {\n version: '3.2.0',\n get: createSharedModuleLoader(() => import('date-fns-tz')),\n shareConfig: {\n singleton: true,\n requiredVersion: '^3.2.0',\n },\n },\n lodash: {\n version: '4.18.1',\n get: createSharedModuleLoader(() => import('lodash')),\n shareConfig: {\n singleton: true,\n requiredVersion: '^4.17.21',\n },\n },\n '@hookform/resolvers/zod': {\n version: '5.9.1',\n get: createSharedModuleLoader(() => import('@hookform/resolvers/zod')),\n shareConfig: {\n singleton: true,\n requiredVersion: '^5.9.1',\n },\n },\n 'use-resize-observer': {\n version: '9.1.0',\n get: createSharedModuleLoader(() => import('use-resize-observer')),\n shareConfig: {\n singleton: true,\n requiredVersion: '^9.1.0',\n },\n },\n 'mdi-material-ui': {\n version: '7.9.4',\n get: createSharedModuleLoader(() => import('mdi-material-ui')),\n shareConfig: {\n singleton: true,\n requiredVersion: '^7.4.0',\n },\n },\n immer: {\n version: '10.2.0',\n get: createSharedModuleLoader(() => import('immer')),\n shareConfig: {\n singleton: true,\n requiredVersion: '^10.1.1',\n },\n },\n },\n });\n\n instance = pluginRuntime;\n\n return instance;\n }\n return instance;\n};\n\nfunction getModuleFederationRemoteName(name: string, registry?: string, version?: string): string {\n return `${name}:${registry ?? ''}:${version ?? ''}`;\n}\n\nconst registerRemote = (name: string, registry?: string, version?: string, baseURL?: string): void => {\n const pluginRuntime = getPluginRuntime();\n const registryName = getModuleFederationRemoteName(name, registry, version);\n\n const existingRemote = pluginRuntime.options.remotes.find((remote) => remote.name === registryName);\n if (!existingRemote) {\n const nameVersionRegistry = [name, version, registry].filter(Boolean).join('~');\n const prefix = baseURL || '/plugins';\n const remoteEntryURL = `${prefix}/${nameVersionRegistry}/mf-manifest.json`;\n\n pluginRuntime.registerRemotes([\n {\n name: registryName,\n entry: remoteEntryURL,\n alias: registryName,\n },\n ]);\n }\n};\n\nexport const loadPlugin = async (target: {\n moduleName: string;\n pluginName: string;\n registry?: string;\n version?: string;\n baseURL?: string;\n}): Promise<RemotePluginModule | null> => {\n const { moduleName, pluginName, registry, version, baseURL } = target;\n registerRemote(moduleName, registry, version, baseURL);\n\n const pluginRuntime = getPluginRuntime();\n const registryName = getModuleFederationRemoteName(moduleName, registry, version);\n return pluginRuntime.loadRemote<RemotePluginModule>(`${registryName}/${pluginName}`);\n};\n\nexport function usePluginRuntime({ plugin }: { plugin: PersesPlugin }): {\n pluginRuntime: ModuleFederation;\n loadPlugin: () => Promise<RemotePluginModule | null>;\n} {\n return {\n pluginRuntime: getPluginRuntime(),\n loadPlugin: (): Promise<RemotePluginModule | null> => {\n const { moduleName, name: pluginName, registry, version, baseURL } = plugin;\n return loadPlugin({ moduleName, pluginName, registry, version, baseURL });\n },\n };\n}\n"],"names":["EmotionReact","EmotionStyled","createInstance","ReactQuery","React","ReactDOM","ReactHookForm","ReactRouterDOM","instance","createSharedModuleLoader","loadModule","module","hostSharedModules","Map","registerHostSharedModules","modules","name","Object","entries","set","getHostSharedModule","get","Error","getPluginRuntime","pluginRuntime","remotes","shared","react","version","lib","shareConfig","singleton","requiredVersion","echarts","lodash","immer","getModuleFederationRemoteName","registry","registerRemote","baseURL","registryName","existingRemote","options","find","remote","nameVersionRegistry","filter","Boolean","join","prefix","remoteEntryURL","registerRemotes","entry","alias","loadPlugin","target","moduleName","pluginName","loadRemote","usePluginRuntime","plugin"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,YAAYA,kBAAkB,iBAAiB;AAC/C,YAAYC,mBAAmB,kBAAkB;AAEjD,SAASC,cAAc,QAAQ,sCAAsC;AACrE,YAAYC,gBAAgB,wBAAwB;AACpD,OAAOC,WAAW,QAAQ;AAC1B,OAAOC,cAAc,YAAY;AACjC,YAAYC,mBAAmB,kBAAkB;AACjD,YAAYC,oBAAoB,mBAAmB;AAInD,IAAIC,WAAoC;AAExC,SAASC,yBAAkCC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MY;YAASS;SAAS,CAACS,MAAM,CAACC,SAASC,IAAI,CAAC;QAC3E,MAAMC,SAASV,WAAW;QAC1B,MAAMW,iBAAiB,GAAGD,OAAO,CAAC,EAAEJ,oBAAoB,iBAAiB,CAAC;QAE1ErB,cAAc2B,eAAe,CAAC;YAC5B;gBACEnC,MAAMwB;gBACNY,OAAOF;gBACPG,OAAOb;YACT;SACD;IACH;AACF;AAEA,OAAO,MAAMc,aAAa,OAAOC;IAO/B,MAAM,EAAEC,UAAU,EAAEC,UAAU,EAAEpB,QAAQ,EAAET,OAAO,EAAEW,OAAO,EAAE,GAAGgB;IAC/DjB,eAAekB,YAAYnB,UAAUT,SAASW;IAE9C,MAAMf,gBAAgBD;IACtB,MAAMiB,eAAeJ,8BAA8BoB,YAAYnB,UAAUT;IACzE,OAAOJ,cAAckC,UAAU,CAAqB,GAAGlB,aAAa,CAAC,EAAEiB,YAAY;AACrF,EAAE;AAEF,OAAO,SAASE,iBAAiB,EAAEC,MAAM,EAA4B;IAInE,OAAO;QACLpC,eAAeD;QACf+B,YAAY;YACV,MAAM,EAAEE,UAAU,EAAExC,MAAMyC,UAAU,EAAEpB,QAAQ,EAAET,OAAO,EAAEW,OAAO,EAAE,GAAGqB;YACrE,OAAON,WAAW;gBAAEE;gBAAYC;gBAAYpB;gBAAUT;gBAASW;YAAQ;QACzE;IACF;AACF"}
|
|
@@ -4,8 +4,10 @@ import React from 'react';
|
|
|
4
4
|
export interface TimeRangeProvidersProps {
|
|
5
5
|
initialTimeRange: TimeRangeValue;
|
|
6
6
|
initialRefreshInterval?: DurationString;
|
|
7
|
+
/** Seed for useTimeZoneParams when URL ?tz= is absent (default: local). */
|
|
8
|
+
initialTimeZone?: string;
|
|
7
9
|
children?: React.ReactNode;
|
|
8
10
|
}
|
|
9
|
-
export declare function TimeRangeProviderWithQueryParams({ initialTimeRange, initialRefreshInterval, children, }: TimeRangeProvidersProps): ReactElement;
|
|
11
|
+
export declare function TimeRangeProviderWithQueryParams({ initialTimeRange, initialRefreshInterval, initialTimeZone, children, }: TimeRangeProvidersProps): ReactElement;
|
|
10
12
|
export declare function TimeRangeProviderBasic({ initialTimeRange, initialRefreshInterval, children, }: TimeRangeProvidersProps): ReactElement;
|
|
11
13
|
//# sourceMappingURL=TimeRangeProviders.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TimeRangeProviders.d.ts","sourceRoot":"","sources":["../../../src/runtime/TimeRangeProvider/TimeRangeProviders.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,KAAK,MAAM,OAAO,CAAC;AAK1B,MAAM,WAAW,uBAAuB;IACtC,gBAAgB,EAAE,cAAc,CAAC;IACjC,sBAAsB,CAAC,EAAE,cAAc,CAAC;IACxC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED,wBAAgB,gCAAgC,CAAC,EAC/C,gBAAgB,EAChB,sBAAsB,EACtB,QAAQ,GACT,EAAE,uBAAuB,GAAG,YAAY,CAexC;AAED,wBAAgB,sBAAsB,CAAC,EACrC,gBAAgB,EAChB,sBAAsB,EACtB,QAAQ,GACT,EAAE,uBAAuB,GAAG,YAAY,CAcxC"}
|
|
1
|
+
{"version":3,"file":"TimeRangeProviders.d.ts","sourceRoot":"","sources":["../../../src/runtime/TimeRangeProvider/TimeRangeProviders.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,KAAK,MAAM,OAAO,CAAC;AAK1B,MAAM,WAAW,uBAAuB;IACtC,gBAAgB,EAAE,cAAc,CAAC;IACjC,sBAAsB,CAAC,EAAE,cAAc,CAAC;IACxC,2EAA2E;IAC3E,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED,wBAAgB,gCAAgC,CAAC,EAC/C,gBAAgB,EAChB,sBAAsB,EACtB,eAAyB,EACzB,QAAQ,GACT,EAAE,uBAAuB,GAAG,YAAY,CAexC;AAED,wBAAgB,sBAAsB,CAAC,EACrC,gBAAgB,EAChB,sBAAsB,EACtB,QAAQ,GACT,EAAE,uBAAuB,GAAG,YAAY,CAcxC"}
|
|
@@ -15,10 +15,10 @@ import { TimeZoneProvider } from "@perses-dev/components";
|
|
|
15
15
|
import React from "react";
|
|
16
16
|
import { useSetRefreshIntervalParams, useTimeRangeParams, useTimeZoneParams } from "./query-params.js";
|
|
17
17
|
import { TimeRangeProvider } from "./TimeRangeProvider.js";
|
|
18
|
-
export function TimeRangeProviderWithQueryParams({ initialTimeRange, initialRefreshInterval, children }) {
|
|
18
|
+
export function TimeRangeProviderWithQueryParams({ initialTimeRange, initialRefreshInterval, initialTimeZone = 'local', children }) {
|
|
19
19
|
const { timeRange, setTimeRange } = useTimeRangeParams(initialTimeRange);
|
|
20
20
|
const { refreshInterval, setRefreshInterval } = useSetRefreshIntervalParams(initialRefreshInterval);
|
|
21
|
-
const { timeZone } = useTimeZoneParams(
|
|
21
|
+
const { timeZone } = useTimeZoneParams(initialTimeZone);
|
|
22
22
|
return /*#__PURE__*/ _jsx(TimeRangeProvider, {
|
|
23
23
|
timeRange: timeRange,
|
|
24
24
|
refreshInterval: refreshInterval,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/runtime/TimeRangeProvider/TimeRangeProviders.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { TimeZoneProvider } from '@perses-dev/components';\nimport type { DurationString, TimeRangeValue } from '@perses-dev/spec';\nimport type { ReactElement } from 'react';\nimport React from 'react';\n\nimport { useSetRefreshIntervalParams, useTimeRangeParams, useTimeZoneParams } from './query-params';\nimport { TimeRangeProvider } from './TimeRangeProvider';\n\nexport interface TimeRangeProvidersProps {\n initialTimeRange: TimeRangeValue;\n initialRefreshInterval?: DurationString;\n children?: React.ReactNode;\n}\n\nexport function TimeRangeProviderWithQueryParams({\n initialTimeRange,\n initialRefreshInterval,\n children,\n}: TimeRangeProvidersProps): ReactElement {\n const { timeRange, setTimeRange } = useTimeRangeParams(initialTimeRange);\n const { refreshInterval, setRefreshInterval } = useSetRefreshIntervalParams(initialRefreshInterval);\n const { timeZone } = useTimeZoneParams(
|
|
1
|
+
{"version":3,"sources":["../../../src/runtime/TimeRangeProvider/TimeRangeProviders.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { TimeZoneProvider } from '@perses-dev/components';\nimport type { DurationString, TimeRangeValue } from '@perses-dev/spec';\nimport type { ReactElement } from 'react';\nimport React from 'react';\n\nimport { useSetRefreshIntervalParams, useTimeRangeParams, useTimeZoneParams } from './query-params';\nimport { TimeRangeProvider } from './TimeRangeProvider';\n\nexport interface TimeRangeProvidersProps {\n initialTimeRange: TimeRangeValue;\n initialRefreshInterval?: DurationString;\n /** Seed for useTimeZoneParams when URL ?tz= is absent (default: local). */\n initialTimeZone?: string;\n children?: React.ReactNode;\n}\n\nexport function TimeRangeProviderWithQueryParams({\n initialTimeRange,\n initialRefreshInterval,\n initialTimeZone = 'local',\n children,\n}: TimeRangeProvidersProps): ReactElement {\n const { timeRange, setTimeRange } = useTimeRangeParams(initialTimeRange);\n const { refreshInterval, setRefreshInterval } = useSetRefreshIntervalParams(initialRefreshInterval);\n const { timeZone } = useTimeZoneParams(initialTimeZone);\n\n return (\n <TimeRangeProvider\n timeRange={timeRange}\n refreshInterval={refreshInterval}\n setTimeRange={setTimeRange}\n setRefreshInterval={setRefreshInterval}\n >\n <TimeZoneProvider timeZone={timeZone}>{children}</TimeZoneProvider>\n </TimeRangeProvider>\n );\n}\n\nexport function TimeRangeProviderBasic({\n initialTimeRange,\n initialRefreshInterval,\n children,\n}: TimeRangeProvidersProps): ReactElement {\n const [timeRange, setTimeRange] = React.useState<TimeRangeValue>(initialTimeRange);\n const [refreshInterval, setRefreshInterval] = React.useState<DurationString | undefined>(initialRefreshInterval);\n\n return (\n <TimeRangeProvider\n timeRange={timeRange}\n refreshInterval={refreshInterval}\n setTimeRange={setTimeRange}\n setRefreshInterval={setRefreshInterval}\n >\n {children}\n </TimeRangeProvider>\n );\n}\n"],"names":["TimeZoneProvider","React","useSetRefreshIntervalParams","useTimeRangeParams","useTimeZoneParams","TimeRangeProvider","TimeRangeProviderWithQueryParams","initialTimeRange","initialRefreshInterval","initialTimeZone","children","timeRange","setTimeRange","refreshInterval","setRefreshInterval","timeZone","TimeRangeProviderBasic","useState"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,gBAAgB,QAAQ,yBAAyB;AAG1D,OAAOC,WAAW,QAAQ;AAE1B,SAASC,2BAA2B,EAAEC,kBAAkB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,qBAAqB,EAAE,GAAG,KAAK,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"alerts-queries.d.ts","sourceRoot":"","sources":["../../src/runtime/alerts-queries.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACjF,OAAO,KAAK,EAAY,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAStE,MAAM,MAAM,qBAAqB,CAAC,UAAU,GAAG,WAAW,IAAI,eAAe,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC;AACzG,eAAO,MAAM,gBAAgB,gBAAgB,CAAC;AAE9C;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,qBAAqB,EAAE,GAAG,KAAK,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAsCxG"}
|
|
@@ -24,7 +24,9 @@ export const ALERTS_QUERY_KEY = 'AlertsQuery';
|
|
|
24
24
|
const { getPlugin } = usePluginRegistry();
|
|
25
25
|
const context = useAlertsQueryContext();
|
|
26
26
|
const pluginLoaderResponse = usePlugins('AlertsQuery', definitions.map((d)=>({
|
|
27
|
-
kind: d.spec.plugin.kind
|
|
27
|
+
kind: d.spec.plugin.kind,
|
|
28
|
+
version: d.spec.plugin.metadata?.version,
|
|
29
|
+
registry: d.spec.plugin.metadata?.registry
|
|
28
30
|
})));
|
|
29
31
|
return useQueries({
|
|
30
32
|
queries: definitions.map((definition, idx)=>{
|
|
@@ -45,7 +47,9 @@ export const ALERTS_QUERY_KEY = 'AlertsQuery';
|
|
|
45
47
|
queryFn: async ({ signal })=>{
|
|
46
48
|
const plugin = await getPlugin({
|
|
47
49
|
kind: ALERTS_QUERY_KEY,
|
|
48
|
-
name: alertsQueryKind
|
|
50
|
+
name: alertsQueryKind,
|
|
51
|
+
version: definition.spec.plugin.metadata?.version,
|
|
52
|
+
registry: definition.spec.plugin.metadata?.registry
|
|
49
53
|
});
|
|
50
54
|
const data = await plugin.getAlertsData(definition.spec.plugin.spec, context, signal);
|
|
51
55
|
return data;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/runtime/alerts-queries.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport type { AlertsData, QueryDefinition, UnknownSpec } from '@perses-dev/spec';\nimport type { QueryKey, UseQueryResult } from '@tanstack/react-query';\nimport { useQueries } from '@tanstack/react-query';\n\nimport type { AlertsQueryContext, AlertsQueryPlugin } from '../model';\nimport { useDatasourceStore } from './datasources';\nimport { usePluginRegistry, usePlugins } from './plugin-registry';\nimport { filterVariableStateMap, getVariableValuesKey } from './utils';\nimport { useAllVariableValues } from './variables';\n\nexport type AlertsQueryDefinition<PluginSpec = UnknownSpec> = QueryDefinition<'AlertsQuery', PluginSpec>;\nexport const ALERTS_QUERY_KEY = 'AlertsQuery';\n\n/**\n * Run an alerts query using an AlertsQuery plugin and return the results.\n * Alerts represent current state and are NOT time-range dependent.\n * @param definitions: dashboard definition for an alerts query\n */\nexport function useAlertsQueries(definitions: AlertsQueryDefinition[]): Array<UseQueryResult<AlertsData>> {\n const { getPlugin } = usePluginRegistry();\n const context = useAlertsQueryContext();\n\n const pluginLoaderResponse = usePlugins(\n 'AlertsQuery',\n definitions.map((d) => ({
|
|
1
|
+
{"version":3,"sources":["../../src/runtime/alerts-queries.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport type { AlertsData, QueryDefinition, UnknownSpec } from '@perses-dev/spec';\nimport type { QueryKey, UseQueryResult } from '@tanstack/react-query';\nimport { useQueries } from '@tanstack/react-query';\n\nimport type { AlertsQueryContext, AlertsQueryPlugin } from '../model';\nimport { useDatasourceStore } from './datasources';\nimport { usePluginRegistry, usePlugins } from './plugin-registry';\nimport { filterVariableStateMap, getVariableValuesKey } from './utils';\nimport { useAllVariableValues } from './variables';\n\nexport type AlertsQueryDefinition<PluginSpec = UnknownSpec> = QueryDefinition<'AlertsQuery', PluginSpec>;\nexport const ALERTS_QUERY_KEY = 'AlertsQuery';\n\n/**\n * Run an alerts query using an AlertsQuery plugin and return the results.\n * Alerts represent current state and are NOT time-range dependent.\n * @param definitions: dashboard definition for an alerts query\n */\nexport function useAlertsQueries(definitions: AlertsQueryDefinition[]): Array<UseQueryResult<AlertsData>> {\n const { getPlugin } = usePluginRegistry();\n const context = useAlertsQueryContext();\n\n const pluginLoaderResponse = usePlugins(\n 'AlertsQuery',\n definitions.map((d) => ({\n kind: d.spec.plugin.kind,\n version: d.spec.plugin.metadata?.version,\n registry: d.spec.plugin.metadata?.registry,\n })),\n );\n\n return useQueries({\n queries: definitions.map((definition, idx) => {\n const plugin = pluginLoaderResponse[idx]?.data;\n const { queryEnabled, queryKey } = getQueryOptions({ context, definition, plugin });\n const alertsQueryKind = definition?.spec?.plugin?.kind;\n return {\n enabled: queryEnabled,\n queryKey: queryKey,\n refetchOnMount: false,\n refetchOnWindowFocus: false,\n refetchOnReconnect: false,\n staleTime: 60_000,\n queryFn: async ({ signal }: { signal?: AbortSignal }): Promise<AlertsData> => {\n const plugin = await getPlugin({\n kind: ALERTS_QUERY_KEY,\n name: alertsQueryKind,\n version: definition.spec.plugin.metadata?.version,\n registry: definition.spec.plugin.metadata?.registry,\n });\n const data = await plugin.getAlertsData(definition.spec.plugin.spec, context, signal);\n return data;\n },\n };\n }),\n });\n}\n\nfunction getQueryOptions({\n plugin,\n definition,\n context,\n}: {\n plugin?: AlertsQueryPlugin;\n definition: AlertsQueryDefinition;\n context: AlertsQueryContext;\n}): {\n queryKey: QueryKey;\n queryEnabled: boolean;\n} {\n const { variableState } = context;\n\n const dependencies = plugin?.dependsOn ? plugin.dependsOn(definition.spec.plugin.spec, context) : {};\n const variableDependencies = dependencies?.variables;\n\n const filteredVariabledState = filterVariableStateMap(variableState, variableDependencies);\n const variablesValueKey = getVariableValuesKey(filteredVariabledState);\n // Note: no absoluteTimeRange in query key since alerts are current state\n const queryKey = ['query', ALERTS_QUERY_KEY, definition, variablesValueKey] as const;\n\n let waitToLoad = false;\n if (variableDependencies) {\n waitToLoad = variableDependencies.some((v) => variableState[v]?.loading);\n }\n\n const queryEnabled = plugin !== undefined && !waitToLoad;\n return {\n queryKey,\n queryEnabled,\n };\n}\n\nfunction useAlertsQueryContext(): AlertsQueryContext {\n const variableState = useAllVariableValues();\n const datasourceStore = useDatasourceStore();\n\n return {\n variableState,\n datasourceStore,\n };\n}\n"],"names":["useQueries","useDatasourceStore","usePluginRegistry","usePlugins","filterVariableStateMap","getVariableValuesKey","useAllVariableValues","ALERTS_QUERY_KEY","useAlertsQueries","definitions","getPlugin","context","useAlertsQueryContext","pluginLoaderResponse","map","d","kind","spec","plugin","version","metadata","registry","queries","definition","idx","data","queryEnabled","queryKey","getQueryOptions","alertsQueryKind","enabled","refetchOnMount","refetchOnWindowFocus","refetchOnReconnect","staleTime","queryFn","signal","name","getAlertsData","variableState","dependencies","dependsOn","variableDependencies","variables","filteredVariabledState","variablesValueKey","waitToLoad","some","v","loading","undefined","datasourceStore"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6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E,WAAWN,IAAI,CAACC,MAAM,CAACE,QAAQ,EAAEC;oBAC7C;oBACA,MAAMI,OAAO,MAAMP,OAAOoB,aAAa,CAACf,WAAWN,IAAI,CAACC,MAAM,CAACD,IAAI,EAAEN,SAASyB;oBAC9E,OAAOX;gBACT;YACF;QACF;IACF;AACF;AAEA,SAASG,gBAAgB,EACvBV,MAAM,EACNK,UAAU,EACVZ,OAAO,EAKR;IAIC,MAAM,EAAE4B,aAAa,EAAE,GAAG5B;IAE1B,MAAM6B,eAAetB,QAAQuB,YAAYvB,OAAOuB,SAAS,CAAClB,WAAWN,IAAI,CAACC,MAAM,CAACD,IAAI,EAAEN,WAAW,CAAC;IACnG,MAAM+B,uBAAuBF,cAAcG;IAE3C,MAAMC,yBAAyBxC,uBAAuBmC,eAAeG;IACrE,MAAMG,oBAAoBxC,qBAAqBuC;IAC/C,yEAAyE;IACzE,MAAMjB,WAAW;QAAC;QAASpB;QAAkBgB;QAAYsB;KAAkB;IAE3E,IAAIC,aAAa;IACjB,IAAIJ,sBAAsB;QACxBI,aAAaJ,qBAAqBK,IAAI,CAAC,CAACC,IAAMT,aAAa,CAACS,EAAE,EAAEC;IAClE;IAEA,MAAMvB,eAAeR,WAAWgC,aAAa,CAACJ;IAC9C,OAAO;QACLnB;QACAD;IACF;AACF;AAEA,SAASd;IACP,MAAM2B,gBAAgBjC;IACtB,MAAM6C,kBAAkBlD;IAExB,OAAO;QACLsC;QACAY;IACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"annotations.d.ts","sourceRoot":"","sources":["../../src/runtime/annotations.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,KAAK,EAAY,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAUtE,eAAO,MAAM,cAAc,eAAe,CAAC;AA+C3C,wBAAgB,cAAc,CAAC,WAAW,EAAE,cAAc,EAAE,GAAG,KAAK,CAAC,cAAc,CAAC,cAAc,EAAE,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"annotations.d.ts","sourceRoot":"","sources":["../../src/runtime/annotations.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,KAAK,EAAY,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAUtE,eAAO,MAAM,cAAc,eAAe,CAAC;AA+C3C,wBAAgB,cAAc,CAAC,WAAW,EAAE,cAAc,EAAE,GAAG,KAAK,CAAC,cAAc,CAAC,cAAc,EAAE,CAAC,CAAC,CAuCrG;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,cAAc,GAAG,cAAc,CAAC,cAAc,EAAE,CAAC,CAyCxF"}
|
|
@@ -53,7 +53,9 @@ export function useAnnotations(definitions) {
|
|
|
53
53
|
const { getPlugin } = usePluginRegistry();
|
|
54
54
|
const context = useAnnotationContext();
|
|
55
55
|
const pluginLoaderResponse = usePlugins('Annotation', definitions.map((d)=>({
|
|
56
|
-
kind: d.plugin.kind
|
|
56
|
+
kind: d.plugin.kind,
|
|
57
|
+
version: d.plugin.metadata?.version,
|
|
58
|
+
registry: d.plugin.metadata?.registry
|
|
57
59
|
})));
|
|
58
60
|
// useQueries() handles data fetching from query plugins
|
|
59
61
|
return useQueries({
|
|
@@ -75,7 +77,9 @@ export function useAnnotations(definitions) {
|
|
|
75
77
|
queryFn: async ({ signal })=>{
|
|
76
78
|
const plugin = await getPlugin({
|
|
77
79
|
kind: ANNOTATION_KEY,
|
|
78
|
-
name: annotationKind
|
|
80
|
+
name: annotationKind,
|
|
81
|
+
version: definition.plugin.metadata?.version,
|
|
82
|
+
registry: definition.plugin.metadata?.registry
|
|
79
83
|
});
|
|
80
84
|
const data = await plugin.getAnnotationData(definition.plugin.spec, context, signal);
|
|
81
85
|
return data;
|
|
@@ -85,7 +89,10 @@ export function useAnnotations(definitions) {
|
|
|
85
89
|
});
|
|
86
90
|
}
|
|
87
91
|
export function useAnnotationData(spec) {
|
|
88
|
-
const { data: annotationPlugin } = usePlugin('Annotation', spec.plugin.kind
|
|
92
|
+
const { data: annotationPlugin } = usePlugin('Annotation', spec.plugin.kind, {
|
|
93
|
+
version: spec.plugin.metadata?.version,
|
|
94
|
+
registry: spec.plugin.metadata?.registry
|
|
95
|
+
});
|
|
89
96
|
const datasourceStore = useDatasourceStore();
|
|
90
97
|
const allVariables = useAllVariableValues();
|
|
91
98
|
const { absoluteTimeRange: timeRange } = useTimeRange();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/runtime/annotations.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport type { AnnotationData, AnnotationSpec } from '@perses-dev/spec';\nimport type { QueryKey, UseQueryResult } from '@tanstack/react-query';\nimport { useQueries, useQuery } from '@tanstack/react-query';\n\nimport type { AnnotationContext, AnnotationPlugin } from '../model';\nimport { useDatasourceStore } from './datasources';\nimport { usePlugin, usePluginRegistry, usePlugins } from './plugin-registry';\nimport { useTimeRange } from './TimeRangeProvider';\nimport { filterVariableStateMap, getVariableValuesKey } from './utils';\nimport { useAllVariableValues } from './variables';\n\nexport const ANNOTATION_KEY = 'Annotation';\n\nfunction useAnnotationContext(): AnnotationContext {\n const { absoluteTimeRange } = useTimeRange();\n const variableState = useAllVariableValues();\n const datasourceStore = useDatasourceStore();\n\n return {\n variableState,\n datasourceStore,\n absoluteTimeRange,\n };\n}\n\nfunction getQueryOptions({\n plugin,\n definition,\n context,\n}: {\n plugin?: AnnotationPlugin;\n definition: AnnotationSpec;\n context: AnnotationContext;\n}): {\n queryKey: QueryKey;\n queryEnabled: boolean;\n} {\n const { variableState, absoluteTimeRange } = context;\n\n const dependencies = plugin?.dependsOn ? plugin.dependsOn(definition.plugin.spec, context) : {};\n const variableDependencies = dependencies?.variables;\n\n const filteredVariableState = filterVariableStateMap(variableState, variableDependencies);\n const variablesValueKey = getVariableValuesKey(filteredVariableState);\n const queryKey = [ANNOTATION_KEY, definition, absoluteTimeRange, variablesValueKey] as const;\n\n let waitToLoad = false;\n if (variableDependencies) {\n waitToLoad = variableDependencies.some((v) => variableState[v]?.loading);\n }\n\n const queryEnabled = plugin !== undefined && !waitToLoad;\n return {\n queryKey,\n queryEnabled,\n };\n}\n\nexport function useAnnotations(definitions: AnnotationSpec[]): Array<UseQueryResult<AnnotationData[]>> {\n const { getPlugin } = usePluginRegistry();\n const context = useAnnotationContext();\n\n const pluginLoaderResponse = usePlugins(\n 'Annotation',\n definitions.map((d) => ({
|
|
1
|
+
{"version":3,"sources":["../../src/runtime/annotations.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport type { AnnotationData, AnnotationSpec } from '@perses-dev/spec';\nimport type { QueryKey, UseQueryResult } from '@tanstack/react-query';\nimport { useQueries, useQuery } from '@tanstack/react-query';\n\nimport type { AnnotationContext, AnnotationPlugin } from '../model';\nimport { useDatasourceStore } from './datasources';\nimport { usePlugin, usePluginRegistry, usePlugins } from './plugin-registry';\nimport { useTimeRange } from './TimeRangeProvider';\nimport { filterVariableStateMap, getVariableValuesKey } from './utils';\nimport { useAllVariableValues } from './variables';\n\nexport const ANNOTATION_KEY = 'Annotation';\n\nfunction useAnnotationContext(): AnnotationContext {\n const { absoluteTimeRange } = useTimeRange();\n const variableState = useAllVariableValues();\n const datasourceStore = useDatasourceStore();\n\n return {\n variableState,\n datasourceStore,\n absoluteTimeRange,\n };\n}\n\nfunction getQueryOptions({\n plugin,\n definition,\n context,\n}: {\n plugin?: AnnotationPlugin;\n definition: AnnotationSpec;\n context: AnnotationContext;\n}): {\n queryKey: QueryKey;\n queryEnabled: boolean;\n} {\n const { variableState, absoluteTimeRange } = context;\n\n const dependencies = plugin?.dependsOn ? plugin.dependsOn(definition.plugin.spec, context) : {};\n const variableDependencies = dependencies?.variables;\n\n const filteredVariableState = filterVariableStateMap(variableState, variableDependencies);\n const variablesValueKey = getVariableValuesKey(filteredVariableState);\n const queryKey = [ANNOTATION_KEY, definition, absoluteTimeRange, variablesValueKey] as const;\n\n let waitToLoad = false;\n if (variableDependencies) {\n waitToLoad = variableDependencies.some((v) => variableState[v]?.loading);\n }\n\n const queryEnabled = plugin !== undefined && !waitToLoad;\n return {\n queryKey,\n queryEnabled,\n };\n}\n\nexport function useAnnotations(definitions: AnnotationSpec[]): Array<UseQueryResult<AnnotationData[]>> {\n const { getPlugin } = usePluginRegistry();\n const context = useAnnotationContext();\n\n const pluginLoaderResponse = usePlugins(\n 'Annotation',\n definitions.map((d) => ({\n kind: d.plugin.kind,\n version: d.plugin.metadata?.version,\n registry: d.plugin.metadata?.registry,\n })),\n );\n\n // useQueries() handles data fetching from query plugins\n return useQueries({\n queries: definitions.map((definition, idx) => {\n const plugin = pluginLoaderResponse[idx]?.data;\n const { queryEnabled, queryKey } = getQueryOptions({ context, definition, plugin });\n const annotationKind = definition?.plugin?.kind;\n return {\n enabled: queryEnabled,\n queryKey: queryKey,\n refetchOnMount: false,\n refetchOnWindowFocus: false,\n refetchOnReconnect: false,\n staleTime: Infinity,\n queryFn: async ({ signal }: { signal?: AbortSignal }): Promise<AnnotationData[]> => {\n const plugin = await getPlugin({\n kind: ANNOTATION_KEY,\n name: annotationKind,\n version: definition.plugin.metadata?.version,\n registry: definition.plugin.metadata?.registry,\n });\n const data = await plugin.getAnnotationData(definition.plugin.spec, context, signal);\n return data;\n },\n };\n }),\n });\n}\n\nexport function useAnnotationData(spec: AnnotationSpec): UseQueryResult<AnnotationData[]> {\n const { data: annotationPlugin } = usePlugin('Annotation', spec.plugin.kind, {\n version: spec.plugin.metadata?.version,\n registry: spec.plugin.metadata?.registry,\n });\n\n const datasourceStore = useDatasourceStore();\n const allVariables = useAllVariableValues();\n const { absoluteTimeRange: timeRange } = useTimeRange();\n const variablePluginCtx = { absoluteTimeRange: timeRange, datasourceStore, variableState: allVariables };\n\n let dependsOnVariables: string[] = Object.keys(allVariables); // Default to all variables\n if (annotationPlugin?.dependsOn) {\n const dependencies = annotationPlugin.dependsOn(spec.plugin.spec, variablePluginCtx);\n dependsOnVariables = dependencies.variables ? dependencies.variables : dependsOnVariables;\n }\n\n const variables = useAllVariableValues(dependsOnVariables);\n\n let waitToLoad = false;\n if (dependsOnVariables) {\n waitToLoad = dependsOnVariables.some((v) => variables[v]?.loading);\n }\n\n const variablesValueKey = getVariableValuesKey(variables);\n\n return useQuery({\n queryKey: ['annotation', spec, timeRange, variablesValueKey],\n queryFn: async ({ signal }) => {\n const resp = await annotationPlugin?.getAnnotationData(\n spec.plugin.spec,\n { ...variablePluginCtx, variableState: variables },\n signal,\n );\n if (!resp?.length) {\n return [];\n }\n return resp;\n },\n enabled: !!annotationPlugin || waitToLoad,\n });\n}\n"],"names":["useQueries","useQuery","useDatasourceStore","usePlugin","usePluginRegistry","usePlugins","useTimeRange","filterVariableStateMap","getVariableValuesKey","useAllVariableValues","ANNOTATION_KEY","useAnnotationContext","absoluteTimeRange","variableState","datasourceStore","getQueryOptions","plugin","definition","context","dependencies","dependsOn","spec","variableDependencies","variables","filteredVariableState","variablesValueKey","queryKey","waitToLoad","some","v","loading","queryEnabled","undefined","useAnnotations","definitions","getPlugin","pluginLoaderResponse","map","d","kind","version","metadata","registry","queries","idx","data","annotationKind","enabled","refetchOnMount","refetchOnWindowFocus","refetchOnReconnect","staleTime","Infinity","queryFn","signal","name","getAnnotationData","useAnnotationData","annotationPlugin","allVariables","timeRange","variablePluginCtx","dependsOnVariables","Object","keys","resp","length"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,SAASA,UAAU,EAAEC,QAAQ,QAAQ,wBAAwB;AAG7D,SAASC,kBAAkB,QAAQ,mBAAgB;AACnD,SAASC,SAAS,EAAEC,iBAAiB,EAAEC,UAAU,QAAQ,uBAAoB;AAC7E,SAASC,YAAY,QAAQ,+BAAsB;AACnD,SAASC,sBAAsB,EAAEC,oBAAoB,QAAQ,aAAU;AACvE,SAASC,oBAAoB,QAAQ,iBAAc;AAEnD,OAAO,MAAMC,iBAAiB,aAAa;AAE3C,SAASC;IACP,MAAM,EAAEC,iBAAiB,EAAE,GAAGN;IAC9B,MAAMO,gBAAgBJ;IACtB,MAAMK,kBAAkBZ;IAExB,OAAO;QACLW;QACAC;QACAF;IACF;AACF;AAEA,SAASG,gBAAgB,EACvBC,MAAM,EACNC,UAAU,EACVC,OAAO,EAKR;IAIC,MAAM,EAAEL,aAAa,EAAED,iBAAiB,EAAE,GAAGM;IAE7C,MAAMC,eAAeH,QAAQI,YAAYJ,OAAOI,SAAS,CAACH,WAAWD,MAAM,CAACK,IAAI,EAAEH,WAAW,CAAC;IAC9F,MAAMI,uBAAuBH,cAAcI;IAE3C,MAAMC,wBAAwBjB,uBAAuBM,eAAeS;IACpE,MAAMG,oBAAoBjB,qBAAqBgB;IAC/C,MAAME,WAAW;QAAChB;QAAgBO;QAAYL;QAAmBa;KAAkB;IAEnF,IAAIE,aAAa;IACjB,IAAIL,sBA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":"log-queries.d.ts","sourceRoot":"","sources":["../../src/runtime/log-queries.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAG5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAM3D,MAAM,MAAM,kBAAkB,CAAC,UAAU,GAAG,WAAW,IAAI,eAAe,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;AACnG,eAAO,MAAM,aAAa,aAAa,CAAC;AAExC,wBAAgB,aAAa,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"log-queries.d.ts","sourceRoot":"","sources":["../../src/runtime/log-queries.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAG5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAM3D,MAAM,MAAM,kBAAkB,CAAC,UAAU,GAAG,WAAW,IAAI,eAAe,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;AACnG,eAAO,MAAM,aAAa,aAAa,CAAC;AAExC,wBAAgB,aAAa,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC,CAsCtG"}
|
|
@@ -46,7 +46,9 @@ export function useLogQueries(definitions) {
|
|
|
46
46
|
queryFn: async ({ signal })=>{
|
|
47
47
|
const plugin = await getPlugin({
|
|
48
48
|
kind: LOG_QUERY_KEY,
|
|
49
|
-
name: logQueryKind
|
|
49
|
+
name: logQueryKind,
|
|
50
|
+
version: definition.spec.plugin.metadata?.version,
|
|
51
|
+
registry: definition.spec.plugin.metadata?.registry
|
|
50
52
|
});
|
|
51
53
|
const data = await plugin.getLogData(definition.spec.plugin.spec, context, signal);
|
|
52
54
|
return data;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/runtime/log-queries.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport type { QueryDefinition, UnknownSpec } from '@perses-dev/spec';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQueries } from '@tanstack/react-query';\n\nimport type { LogQueryResult } from '../model/log-queries';\nimport { useDatasourceStore } from './datasources';\nimport { usePluginRegistry } from './plugin-registry';\nimport { useTimeRange } from './TimeRangeProvider';\nimport { useVariableValues } from './variables';\n\nexport type LogQueryDefinition<PluginSpec = UnknownSpec> = QueryDefinition<'LogQuery', PluginSpec>;\nexport const LOG_QUERY_KEY = 'LogQuery';\n\nexport function useLogQueries(definitions: LogQueryDefinition[]): Array<UseQueryResult<LogQueryResult>> {\n const { getPlugin } = usePluginRegistry();\n const datasourceStore = useDatasourceStore();\n const { absoluteTimeRange } = useTimeRange();\n const variableValues = useVariableValues();\n\n const context = {\n timeRange: absoluteTimeRange,\n variableState: variableValues,\n datasourceStore,\n refreshKey: '',\n };\n\n return useQueries({\n queries: definitions.map((definition) => {\n const queryKey = ['query', LOG_QUERY_KEY, definition, absoluteTimeRange, variableValues] as const;\n const logQueryKind = definition?.spec?.plugin?.kind;\n return {\n queryKey: queryKey,\n refetchOnMount: false,\n refetchOnWindowFocus: false,\n refetchOnReconnect: false,\n staleTime: Infinity,\n queryFn: async ({ signal }: { signal?: AbortSignal }): Promise<LogQueryResult> => {\n const plugin = await getPlugin({
|
|
1
|
+
{"version":3,"sources":["../../src/runtime/log-queries.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport type { QueryDefinition, UnknownSpec } from '@perses-dev/spec';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQueries } from '@tanstack/react-query';\n\nimport type { LogQueryResult } from '../model/log-queries';\nimport { useDatasourceStore } from './datasources';\nimport { usePluginRegistry } from './plugin-registry';\nimport { useTimeRange } from './TimeRangeProvider';\nimport { useVariableValues } from './variables';\n\nexport type LogQueryDefinition<PluginSpec = UnknownSpec> = QueryDefinition<'LogQuery', PluginSpec>;\nexport const LOG_QUERY_KEY = 'LogQuery';\n\nexport function useLogQueries(definitions: LogQueryDefinition[]): Array<UseQueryResult<LogQueryResult>> {\n const { getPlugin } = usePluginRegistry();\n const datasourceStore = useDatasourceStore();\n const { absoluteTimeRange } = useTimeRange();\n const variableValues = useVariableValues();\n\n const context = {\n timeRange: absoluteTimeRange,\n variableState: variableValues,\n datasourceStore,\n refreshKey: '',\n };\n\n return useQueries({\n queries: definitions.map((definition) => {\n const queryKey = ['query', LOG_QUERY_KEY, definition, absoluteTimeRange, variableValues] as const;\n const logQueryKind = definition?.spec?.plugin?.kind;\n return {\n queryKey: queryKey,\n refetchOnMount: false,\n refetchOnWindowFocus: false,\n refetchOnReconnect: false,\n staleTime: Infinity,\n queryFn: async ({ signal }: { signal?: AbortSignal }): Promise<LogQueryResult> => {\n const plugin = await getPlugin({\n kind: LOG_QUERY_KEY,\n name: logQueryKind,\n version: definition.spec.plugin.metadata?.version,\n registry: definition.spec.plugin.metadata?.registry,\n });\n const data = await plugin.getLogData(definition.spec.plugin.spec, context, signal);\n return data;\n },\n\n structuralSharing: false,\n };\n }),\n });\n}\n"],"names":["useQueries","useDatasourceStore","usePluginRegistry","useTimeRange","useVariableValues","LOG_QUERY_KEY","useLogQueries","definitions","getPlugin","datasourceStore","absoluteTimeRange","variableValues","context","timeRange","variableState","refreshKey","queries","map","definition","queryKey","logQueryKind","spec","plugin","kind","refetchOnMount","refetchOnWindowFocus","refetchOnReconnect","staleTime","Infinity","queryFn","signal","name","version","metadata","registry","data","getLogData","structuralSharing"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,SAASA,UAAU,QAAQ,wBAAwB;AAGnD,SAASC,kBAAkB,QAAQ,mBAAgB;AACnD,SAASC,iBAAiB,QAAQ,uBAAoB;AACtD,SAASC,YAAY,QAAQ,+BAAsB;AACnD,SAASC,iBAAiB,QAAQ,iBAAc;AAGhD,OAAO,MAAMC,gBAAgB,WAAW;AAExC,OAAO,SAASC,cAAcC,WAAiC;IAC7D,MAAM,EAAEC,SAAS,EAAE,GAAGN;IACtB,MAAMO,kBAAkBR;IACxB,MAAM,EAAES,iBAAiB,EAAE,GAAGP;IAC9B,MAAMQ,iBAAiBP;IAEvB,MAAMQ,UAAU;QACdC,WAAWH;QACXI,eAAeH;QACfF;QACAM,YAAY;IACd;IAEA,OAAOf,WAAW;QAChBgB,SAAST,YAAYU,GAAG,CAAC,CAACC;YACxB,MAAMC,WAAW;gBAAC;gBAASd;gBAAea;gBAAYR;gBAAmBC;aAAe;YACxF,MAAMS,eAAeF,YAAYG,MAAMC,QAAQC;YAC/C,OAAO;gBACLJ,UAAUA;gBACVK,gBAAgB;gBAChBC,sBAAsB;gBACtBC,oBAAoB;gBACpBC,WAAWC;gBACXC,SAAS,OAAO,EAAEC,MAAM,EAA4B;oBAClD,MAAMR,SAAS,MAAMd,UAAU;wBAC7Be,MAAMlB;wBACN0B,MAAMX;wBACNY,SAASd,WAAWG,IAAI,CAACC,MAAM,CAACW,QAAQ,EAAED;wBAC1CE,UAAUhB,WAAWG,IAAI,CAACC,MAAM,CAACW,QAAQ,EAAEC;oBAC7C;oBACA,MAAMC,OAAO,MAAMb,OAAOc,UAAU,CAAClB,WAAWG,IAAI,CAACC,MAAM,CAACD,IAAI,EAAET,SAASkB;oBAC3E,OAAOK;gBACT;gBAEAE,mBAAmB;YACrB;QACF;IACF;AACF"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { BuiltinVariableDefinition } from '@perses-dev/spec';
|
|
1
|
+
import type { BuiltinVariableDefinition, PluginDefinitionMetadata } from '@perses-dev/spec';
|
|
2
2
|
import type { UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
|
|
3
3
|
import type { DefaultPluginKinds, PluginImplementation, PluginMetadataWithModule, PluginType, PluginCompoundKey } from '../model';
|
|
4
4
|
export interface PluginRegistryContextType {
|
|
5
5
|
getPlugin<T extends PluginType>(compoundKey: PluginCompoundKey<T>): Promise<PluginImplementation<T>>;
|
|
6
|
-
listPluginMetadata(pluginTypes
|
|
6
|
+
listPluginMetadata(pluginTypes?: PluginType[]): Promise<PluginMetadataWithModule[]>;
|
|
7
7
|
defaultPluginKinds?: DefaultPluginKinds;
|
|
8
8
|
}
|
|
9
9
|
export declare const PluginRegistryContext: import("react").Context<PluginRegistryContextType | undefined>;
|
|
@@ -12,22 +12,36 @@ export declare const PluginRegistryContext: import("react").Context<PluginRegist
|
|
|
12
12
|
* be using `usePlugin` or `useListPluginMetadata` instead.
|
|
13
13
|
*/
|
|
14
14
|
export declare function usePluginRegistry(): PluginRegistryContextType;
|
|
15
|
-
type
|
|
15
|
+
type UsePluginQueryKey = [string, PluginType | undefined, string, string, string];
|
|
16
|
+
type UsePluginOptions<T extends PluginType> = Omit<UseQueryOptions<PluginImplementation<T>, Error, PluginImplementation<T>, UsePluginQueryKey>, 'queryKey' | 'queryFn'> & {
|
|
17
|
+
/** Pin resolution to a specific plugin version. When omitted, the latest available version is used. */
|
|
18
|
+
version?: string;
|
|
19
|
+
/** Pin resolution to a specific plugin registry. */
|
|
20
|
+
registry?: string;
|
|
21
|
+
};
|
|
16
22
|
/**
|
|
17
23
|
* Loads a plugin and returns the plugin implementation, along with loading/error state.
|
|
24
|
+
*
|
|
25
|
+
* When `options.version` is provided, the plugin is resolved with an exact version match: if that version is not
|
|
26
|
+
* installed, the query fails instead of silently falling back to the latest available version.
|
|
18
27
|
*/
|
|
19
28
|
export declare function usePlugin<T extends PluginType>(pluginType: T | undefined, kind: string, options?: UsePluginOptions<T>): UseQueryResult<PluginImplementation<T>, Error>;
|
|
20
29
|
/**
|
|
21
|
-
*
|
|
30
|
+
* A plugin reference to load, optionally pinned to a specific version/registry.
|
|
22
31
|
*/
|
|
23
|
-
export
|
|
32
|
+
export interface UsePluginsItem extends PluginDefinitionMetadata {
|
|
24
33
|
kind: string;
|
|
25
|
-
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Loads a list of plugins and returns the plugin implementation, along with loading/error state.
|
|
37
|
+
*/
|
|
38
|
+
export declare function usePlugins<T extends PluginType>(pluginType: T, plugins: UsePluginsItem[]): Array<UseQueryResult<PluginImplementation<T>>>;
|
|
26
39
|
type UseListPluginMetadataOptions = Omit<UseQueryOptions<PluginMetadataWithModule[], Error, PluginMetadataWithModule[], [string, string[]]>, 'queryKey' | 'queryFn'>;
|
|
27
40
|
/**
|
|
28
|
-
* Gets a list of plugin metadata for the specified plugin
|
|
41
|
+
* Gets a list of plugin metadata for the specified plugin types and returns it, along with loading/error state. When
|
|
42
|
+
* `pluginTypes` is omitted, the metadata of every installed plugin is returned, whatever its type.
|
|
29
43
|
*/
|
|
30
|
-
export declare function useListPluginMetadata(pluginTypes
|
|
44
|
+
export declare function useListPluginMetadata(pluginTypes?: PluginType[], options?: UseListPluginMetadataOptions): UseQueryResult<PluginMetadataWithModule[]>;
|
|
31
45
|
export declare function usePluginBuiltinVariableDefinitions(): UseQueryResult<BuiltinVariableDefinition[]>;
|
|
32
46
|
export {};
|
|
33
47
|
//# 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":"AAaA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"plugin-registry.d.ts","sourceRoot":"","sources":["../../src/runtime/plugin-registry.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAC5F,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAI7E,OAAO,KAAK,EACV,kBAAkB,EAClB,oBAAoB,EACpB,wBAAwB,EACxB,UAAU,EACV,iBAAiB,EAClB,MAAM,UAAU,CAAC;AAElB,MAAM,WAAW,yBAAyB;IACxC,SAAS,CAAC,CAAC,SAAS,UAAU,EAAE,WAAW,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC;IACrG,kBAAkB,CAAC,WAAW,CAAC,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,wBAAwB,EAAE,CAAC,CAAC;IACpF,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;CACzC;AAED,eAAO,MAAM,qBAAqB,gEAAkE,CAAC;AAErG;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,yBAAyB,CAM7D;AAED,KAAK,iBAAiB,GAAG,CAAC,MAAM,EAAE,UAAU,GAAG,SAAS,EAAE,MAAM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,cAAc,CAAC,yBAAyB,EAAE,CAAC,CAkBjG"}
|
|
@@ -25,63 +25,99 @@ export const PluginRegistryContext = createContext(undefined);
|
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
27
|
* Loads a plugin and returns the plugin implementation, along with loading/error state.
|
|
28
|
+
*
|
|
29
|
+
* When `options.version` is provided, the plugin is resolved with an exact version match: if that version is not
|
|
30
|
+
* installed, the query fails instead of silently falling back to the latest available version.
|
|
28
31
|
*/ export function usePlugin(pluginType, kind, options) {
|
|
32
|
+
const { version, registry, ...queryOptions } = options ?? {};
|
|
29
33
|
// We never want to ask for a plugin when the kind isn't set yet, so disable those queries automatically
|
|
30
|
-
|
|
31
|
-
...
|
|
32
|
-
enabled: (
|
|
34
|
+
const useQueryOptions = {
|
|
35
|
+
...queryOptions,
|
|
36
|
+
enabled: (queryOptions.enabled ?? true) && pluginType !== undefined && kind !== ''
|
|
33
37
|
};
|
|
34
38
|
const { getPlugin } = usePluginRegistry();
|
|
35
39
|
return useQuery({
|
|
36
40
|
queryKey: [
|
|
37
41
|
'getPlugin',
|
|
38
42
|
pluginType,
|
|
39
|
-
kind
|
|
43
|
+
kind,
|
|
44
|
+
version ?? '',
|
|
45
|
+
registry ?? ''
|
|
40
46
|
],
|
|
41
47
|
queryFn: ()=>getPlugin({
|
|
42
48
|
kind: pluginType,
|
|
43
|
-
name: kind
|
|
49
|
+
name: kind,
|
|
50
|
+
version,
|
|
51
|
+
registry
|
|
44
52
|
}),
|
|
45
|
-
...
|
|
53
|
+
...useQueryOptions
|
|
46
54
|
});
|
|
47
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Full identity of a plugin to load. Two definitions pinned to different versions (or registries) of the same kind are
|
|
58
|
+
* distinct plugins and must be loaded independently.
|
|
59
|
+
*/ function getUsePluginsItemIdentity(plugin) {
|
|
60
|
+
return `${plugin.kind}:${plugin.version ?? ''}:${plugin.registry ?? ''}`;
|
|
61
|
+
}
|
|
48
62
|
/**
|
|
49
63
|
* Loads a list of plugins and returns the plugin implementation, along with loading/error state.
|
|
50
64
|
*/ export function usePlugins(pluginType, plugins) {
|
|
51
65
|
const { getPlugin } = usePluginRegistry();
|
|
52
|
-
// useQueries() does not support queries with duplicate keys, therefore we de-duplicate the
|
|
66
|
+
// useQueries() does not support queries with duplicate keys, therefore we de-duplicate the plugins before running useQueries()
|
|
53
67
|
// This resolves the following warning in the JS console: "[QueriesObserver]: Duplicate Queries found. This might result in unexpected behavior."
|
|
54
68
|
// https://github.com/TanStack/query/issues/8224#issuecomment-2523554831
|
|
55
69
|
// https://github.com/TanStack/query/issues/4187#issuecomment-1256336901
|
|
56
|
-
const
|
|
57
|
-
|
|
70
|
+
const uniquePlugins = new Map();
|
|
71
|
+
for (const p of plugins){
|
|
72
|
+
const key = getUsePluginsItemIdentity(p);
|
|
73
|
+
if (!uniquePlugins.has(key)) {
|
|
74
|
+
uniquePlugins.set(key, p);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const uniqueKeys = [
|
|
78
|
+
...uniquePlugins.keys()
|
|
79
|
+
];
|
|
80
|
+
const uniqueValues = [
|
|
81
|
+
...uniquePlugins.values()
|
|
58
82
|
];
|
|
59
83
|
const result = useQueries({
|
|
60
|
-
queries:
|
|
84
|
+
queries: uniqueValues.map((p)=>{
|
|
61
85
|
return {
|
|
62
86
|
queryKey: [
|
|
63
87
|
'getPlugin',
|
|
64
88
|
pluginType,
|
|
65
|
-
kind
|
|
89
|
+
p.kind,
|
|
90
|
+
p.version ?? '',
|
|
91
|
+
p.registry ?? ''
|
|
66
92
|
],
|
|
67
93
|
queryFn: ()=>getPlugin({
|
|
68
94
|
kind: pluginType,
|
|
69
|
-
name: kind
|
|
95
|
+
name: p.kind,
|
|
96
|
+
version: p.version,
|
|
97
|
+
registry: p.registry
|
|
70
98
|
})
|
|
71
99
|
};
|
|
72
100
|
})
|
|
73
101
|
});
|
|
74
|
-
// Re-assemble array in original order
|
|
75
|
-
|
|
102
|
+
// Re-assemble array in original order. Index lookups go through a Map so this stays linear on large panels.
|
|
103
|
+
const indexByIdentity = new Map(uniqueKeys.map((key, index)=>[
|
|
104
|
+
key,
|
|
105
|
+
index
|
|
106
|
+
]));
|
|
107
|
+
return plugins.map((p)=>result[indexByIdentity.get(getUsePluginsItemIdentity(p))]);
|
|
76
108
|
}
|
|
77
109
|
/**
|
|
78
|
-
* Gets a list of plugin metadata for the specified plugin
|
|
110
|
+
* Gets a list of plugin metadata for the specified plugin types and returns it, along with loading/error state. When
|
|
111
|
+
* `pluginTypes` is omitted, the metadata of every installed plugin is returned, whatever its type.
|
|
79
112
|
*/ export function useListPluginMetadata(pluginTypes, options) {
|
|
80
113
|
const { listPluginMetadata } = usePluginRegistry();
|
|
81
114
|
return useQuery({
|
|
115
|
+
// `['*']` marks the "every plugin type" query so it gets its own cache entry.
|
|
82
116
|
queryKey: [
|
|
83
117
|
'listPluginMetadata',
|
|
84
|
-
pluginTypes
|
|
118
|
+
pluginTypes ?? [
|
|
119
|
+
'*'
|
|
120
|
+
]
|
|
85
121
|
],
|
|
86
122
|
queryFn: ()=>listPluginMetadata(pluginTypes),
|
|
87
123
|
...options
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/runtime/plugin-registry.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport type { BuiltinVariableDefinition } from '@perses-dev/spec';\nimport type { UseQueryOptions, UseQueryResult } from '@tanstack/react-query';\nimport { useQueries, useQuery } from '@tanstack/react-query';\nimport { createContext, useContext } from 'react';\n\nimport type {\n DefaultPluginKinds,\n PluginImplementation,\n PluginMetadataWithModule,\n PluginType,\n PluginCompoundKey,\n} from '../model';\n\nexport interface PluginRegistryContextType {\n getPlugin<T extends PluginType>(compoundKey: PluginCompoundKey<T>): Promise<PluginImplementation<T>>;\n listPluginMetadata(pluginTypes: PluginType[]): Promise<PluginMetadataWithModule[]>;\n defaultPluginKinds?: DefaultPluginKinds;\n}\n\nexport const PluginRegistryContext = createContext<PluginRegistryContextType | undefined>(undefined);\n\n/**\n * Use the PluginRegistry context directly. This is meant as an escape hatch for custom async flows. You should probably\n * be using `usePlugin` or `useListPluginMetadata` instead.\n */\nexport function usePluginRegistry(): PluginRegistryContextType {\n const ctx = useContext(PluginRegistryContext);\n if (ctx === undefined) {\n throw new Error('PluginRegistryContext not found. Did you forget a provider?');\n }\n return ctx;\n}\n\n// Allows consumers to pass useQuery options from react-query when loading a plugin\ntype UsePluginOptions<T extends PluginType> = Omit<\n UseQueryOptions<PluginImplementation<T>, Error, PluginImplementation<T>, [string, PluginType | undefined, string]>,\n 'queryKey' | 'queryFn'\n>;\n\n/**\n * Loads a plugin and returns the plugin implementation, along with loading/error state.\n */\nexport function usePlugin<T extends PluginType>(\n pluginType: T | undefined,\n kind: string,\n options?: UsePluginOptions<T>,\n): UseQueryResult<PluginImplementation<T>, Error> {\n // We never want to ask for a plugin when the kind isn't set yet, so disable those queries automatically\n options = {\n ...options,\n enabled: (options?.enabled ?? true) && pluginType !== undefined && kind !== '',\n };\n const { getPlugin } = usePluginRegistry();\n return useQuery({\n queryKey: ['getPlugin', pluginType, kind],\n queryFn: () => getPlugin({ kind: pluginType!, name: kind }),\n ...options,\n });\n}\n\n/**\n * Loads a list of plugins and returns the plugin implementation, along with loading/error state.\n */\nexport function usePlugins<T extends PluginType>(\n pluginType: T,\n plugins: Array<{ kind: string }>,\n): Array<UseQueryResult<PluginImplementation<T>>> {\n const { getPlugin } = usePluginRegistry();\n\n // useQueries() does not support queries with duplicate keys, therefore we de-duplicate the plugin kinds before running useQueries()\n // This resolves the following warning in the JS console: \"[QueriesObserver]: Duplicate Queries found. This might result in unexpected behavior.\"\n // https://github.com/TanStack/query/issues/8224#issuecomment-2523554831\n // https://github.com/TanStack/query/issues/4187#issuecomment-1256336901\n const kinds = [...new Set(plugins.map((p) => p.kind))];\n\n const result: Array<UseQueryResult<PluginImplementation<T>>> = useQueries({\n queries: kinds.map((kind) => {\n return {\n queryKey: ['getPlugin', pluginType, kind],\n queryFn: () => getPlugin({ kind: pluginType, name: kind }),\n };\n }),\n });\n\n // Re-assemble array in original order\n return plugins.map((p) => result[kinds.indexOf(p.kind)]!);\n}\n\n// Allow consumers to pass useQuery options from react-query when listing metadata\ntype UseListPluginMetadataOptions = Omit<\n UseQueryOptions<PluginMetadataWithModule[], Error, PluginMetadataWithModule[], [string, string[]]>,\n 'queryKey' | 'queryFn'\n>;\n\n/**\n * Gets a list of plugin metadata for the specified plugin type and returns it, along with loading/error state.\n */\nexport function useListPluginMetadata(\n pluginTypes: PluginType[],\n options?: UseListPluginMetadataOptions,\n): UseQueryResult<PluginMetadataWithModule[]> {\n const { listPluginMetadata } = usePluginRegistry();\n return useQuery({\n queryKey: ['listPluginMetadata', pluginTypes],\n queryFn: () => listPluginMetadata(pluginTypes),\n ...options,\n });\n}\n\nexport function usePluginBuiltinVariableDefinitions(): UseQueryResult<BuiltinVariableDefinition[]> {\n const { getPlugin, listPluginMetadata } = usePluginRegistry();\n\n return useQuery({\n queryKey: ['usePluginBuiltinVariableDefinitions'],\n queryFn: async () => {\n const datasources = await listPluginMetadata(['Datasource']);\n const datasourceNames = new Set(datasources.map((datasource) => datasource.spec.name));\n const result: BuiltinVariableDefinition[] = [];\n for (const name of datasourceNames) {\n const plugin = await getPlugin({ kind: 'Datasource', name });\n if (plugin.getBuiltinVariableDefinitions) {\n plugin.getBuiltinVariableDefinitions().forEach((definition) => result.push(definition));\n }\n }\n return result;\n },\n });\n}\n"],"names":["useQueries","useQuery","createContext","useContext","PluginRegistryContext","undefined","usePluginRegistry","ctx","Error","usePlugin","pluginType","kind","options","enabled","getPlugin","queryKey","queryFn","name","usePlugins","plugins","kinds","Set","map","p","result","queries","indexOf","useListPluginMetadata","pluginTypes","listPluginMetadata","usePluginBuiltinVariableDefinitions","datasources","datasourceNames","datasource","spec","plugin","getBuiltinVariableDefinitions","forEach","definition","push"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,SAASA,UAAU,EAAEC,QAAQ,QAAQ,wBAAwB;AAC7D,SAASC,aAAa,EAAEC,UAAU,QAAQ,QAAQ;AAgBlD,OAAO,MAAMC,wBAAwBF,cAAqDG,WAAW;AAErG;;;CAGC,GACD,OAAO,SAASC;IACd,MAAMC,MAAMJ,WAAWC;IACvB,IAAIG,QAAQF,WAAW;QACrB,MAAM,IAAIG,MAAM;IAClB;IACA,OAAOD;AACT;AAQA;;CAEC,GACD,OAAO,SAASE,UACdC,UAAyB,EACzBC,IAAY,EACZC,OAA6B;IAE7B,wGAAwG;IACxGA,UAAU;QACR,GAAGA,OAAO;QACVC,SAAS,AAACD,CAAAA,SAASC,WAAW,IAAG,KAAMH,eAAeL,aAAaM,SAAS;IAC9E;IACA,MAAM,EAAEG,SAAS,EAAE,GAAGR;IACtB,OAAOL,SAAS;QACdc,UAAU;YAAC;YAAaL;YAAYC;SAAK;QACzCK,SAAS,IAAMF,UAAU;gBAAEH,MAAMD;gBAAaO,MAAMN;YAAK;QACzD,GAAGC,OAAO;IACZ;AACF;AAEA;;CAEC,GACD,OAAO,SAASM,WACdR,UAAa,EACbS,OAAgC;IAEhC,MAAM,EAAEL,SAAS,EAAE,GAAGR;IAEtB,oIAAoI;IACpI,iJAAiJ;IACjJ,wEAAwE;IACxE,wEAAwE;IACxE,MAAMc,QAAQ;WAAI,IAAIC,IAAIF,QAAQG,GAAG,CAAC,CAACC,IAAMA,EAAEZ,IAAI;KAAG;IAEtD,MAAMa,SAAyDxB,WAAW;QACxEyB,SAASL,MAAME,GAAG,CAAC,CAACX;YAClB,OAAO;gBACLI,UAAU;oBAAC;oBAAaL;oBAAYC;iBAAK;gBACzCK,SAAS,IAAMF,UAAU;wBAAEH,MAAMD;wBAAYO,MAAMN;oBAAK;YAC1D;QACF;IACF;IAEA,sCAAsC;IACtC,OAAOQ,QAAQG,GAAG,CAAC,CAACC,IAAMC,MAAM,CAACJ,MAAMM,OAAO,CAACH,EAAEZ,IAAI,EAAE;AACzD;AAQA;;CAEC,GACD,OAAO,SAASgB,sBACdC,WAAyB,EACzBhB,OAAsC;IAEtC,MAAM,EAAEiB,kBAAkB,EAAE,GAAGvB;IAC/B,OAAOL,SAAS;QACdc,UAAU;YAAC;YAAsBa;SAAY;QAC7CZ,SAAS,IAAMa,mBAAmBD;QAClC,GAAGhB,OAAO;IACZ;AACF;AAEA,OAAO,SAASkB;IACd,MAAM,EAAEhB,SAAS,EAAEe,kBAAkB,EAAE,GAAGvB;IAE1C,OAAOL,SAAS;QACdc,UAAU;YAAC;SAAsC;QACjDC,SAAS;YACP,MAAMe,cAAc,MAAMF,mBAAmB;gBAAC;aAAa;YAC3D,MAAMG,kBAAkB,IAAIX,IAAIU,YAAYT,GAAG,CAAC,CAACW,aAAeA,WAAWC,IAAI,CAACjB,IAAI;YACpF,MAAMO,SAAsC,EAAE;YAC9C,KAAK,MAAMP,QAAQe,gBAAiB;gBAClC,MAAMG,SAAS,MAAMrB,UAAU;oBAAEH,MAAM;oBAAcM;gBAAK;gBAC1D,IAAIkB,OAAOC,6BAA6B,EAAE;oBACxCD,OAAOC,6BAA6B,GAAGC,OAAO,CAAC,CAACC,aAAed,OAAOe,IAAI,CAACD;gBAC7E;YACF;YACA,OAAOd;QACT;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../src/runtime/plugin-registry.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport type { BuiltinVariableDefinition, PluginDefinitionMetadata } from '@perses-dev/spec';\nimport type { UseQueryOptions, UseQueryResult } from '@tanstack/react-query';\nimport { useQueries, useQuery } from '@tanstack/react-query';\nimport { createContext, useContext } from 'react';\n\nimport type {\n DefaultPluginKinds,\n PluginImplementation,\n PluginMetadataWithModule,\n PluginType,\n PluginCompoundKey,\n} from '../model';\n\nexport interface PluginRegistryContextType {\n getPlugin<T extends PluginType>(compoundKey: PluginCompoundKey<T>): Promise<PluginImplementation<T>>;\n listPluginMetadata(pluginTypes?: PluginType[]): Promise<PluginMetadataWithModule[]>;\n defaultPluginKinds?: DefaultPluginKinds;\n}\n\nexport const PluginRegistryContext = createContext<PluginRegistryContextType | undefined>(undefined);\n\n/**\n * Use the PluginRegistry context directly. This is meant as an escape hatch for custom async flows. You should probably\n * be using `usePlugin` or `useListPluginMetadata` instead.\n */\nexport function usePluginRegistry(): PluginRegistryContextType {\n const ctx = useContext(PluginRegistryContext);\n if (ctx === undefined) {\n throw new Error('PluginRegistryContext not found. Did you forget a provider?');\n }\n return ctx;\n}\n\ntype UsePluginQueryKey = [string, PluginType | undefined, string, string, string];\n\n// Allows consumers to pass useQuery options from react-query when loading a plugin\ntype UsePluginOptions<T extends PluginType> = Omit<\n UseQueryOptions<PluginImplementation<T>, Error, PluginImplementation<T>, UsePluginQueryKey>,\n 'queryKey' | 'queryFn'\n> & {\n /** Pin resolution to a specific plugin version. When omitted, the latest available version is used. */\n version?: string;\n /** Pin resolution to a specific plugin registry. */\n registry?: string;\n};\n\n/**\n * Loads a plugin and returns the plugin implementation, along with loading/error state.\n *\n * When `options.version` is provided, the plugin is resolved with an exact version match: if that version is not\n * installed, the query fails instead of silently falling back to the latest available version.\n */\nexport function usePlugin<T extends PluginType>(\n pluginType: T | undefined,\n kind: string,\n options?: UsePluginOptions<T>,\n): UseQueryResult<PluginImplementation<T>, Error> {\n const { version, registry, ...queryOptions } = options ?? {};\n // We never want to ask for a plugin when the kind isn't set yet, so disable those queries automatically\n const useQueryOptions = {\n ...queryOptions,\n enabled: (queryOptions.enabled ?? true) && pluginType !== undefined && kind !== '',\n };\n const { getPlugin } = usePluginRegistry();\n return useQuery({\n queryKey: ['getPlugin', pluginType, kind, version ?? '', registry ?? ''],\n queryFn: () => getPlugin({ kind: pluginType!, name: kind, version, registry }),\n ...useQueryOptions,\n });\n}\n\n/**\n * A plugin reference to load, optionally pinned to a specific version/registry.\n */\nexport interface UsePluginsItem extends PluginDefinitionMetadata {\n kind: string;\n}\n\n/**\n * Full identity of a plugin to load. Two definitions pinned to different versions (or registries) of the same kind are\n * distinct plugins and must be loaded independently.\n */\nfunction getUsePluginsItemIdentity(plugin: UsePluginsItem): string {\n return `${plugin.kind}:${plugin.version ?? ''}:${plugin.registry ?? ''}`;\n}\n\n/**\n * Loads a list of plugins and returns the plugin implementation, along with loading/error state.\n */\nexport function usePlugins<T extends PluginType>(\n pluginType: T,\n plugins: UsePluginsItem[],\n): Array<UseQueryResult<PluginImplementation<T>>> {\n const { getPlugin } = usePluginRegistry();\n\n // useQueries() does not support queries with duplicate keys, therefore we de-duplicate the plugins before running useQueries()\n // This resolves the following warning in the JS console: \"[QueriesObserver]: Duplicate Queries found. This might result in unexpected behavior.\"\n // https://github.com/TanStack/query/issues/8224#issuecomment-2523554831\n // https://github.com/TanStack/query/issues/4187#issuecomment-1256336901\n const uniquePlugins = new Map<string, UsePluginsItem>();\n for (const p of plugins) {\n const key = getUsePluginsItemIdentity(p);\n if (!uniquePlugins.has(key)) {\n uniquePlugins.set(key, p);\n }\n }\n const uniqueKeys = [...uniquePlugins.keys()];\n const uniqueValues = [...uniquePlugins.values()];\n\n const result: Array<UseQueryResult<PluginImplementation<T>>> = useQueries({\n queries: uniqueValues.map((p) => {\n return {\n queryKey: ['getPlugin', pluginType, p.kind, p.version ?? '', p.registry ?? ''],\n queryFn: () => getPlugin({ kind: pluginType, name: p.kind, version: p.version, registry: p.registry }),\n };\n }),\n });\n\n // Re-assemble array in original order. Index lookups go through a Map so this stays linear on large panels.\n const indexByIdentity = new Map(uniqueKeys.map((key, index) => [key, index]));\n return plugins.map((p) => result[indexByIdentity.get(getUsePluginsItemIdentity(p))!]!);\n}\n\n// Allow consumers to pass useQuery options from react-query when listing metadata\ntype UseListPluginMetadataOptions = Omit<\n UseQueryOptions<PluginMetadataWithModule[], Error, PluginMetadataWithModule[], [string, string[]]>,\n 'queryKey' | 'queryFn'\n>;\n\n/**\n * Gets a list of plugin metadata for the specified plugin types and returns it, along with loading/error state. When\n * `pluginTypes` is omitted, the metadata of every installed plugin is returned, whatever its type.\n */\nexport function useListPluginMetadata(\n pluginTypes?: PluginType[],\n options?: UseListPluginMetadataOptions,\n): UseQueryResult<PluginMetadataWithModule[]> {\n const { listPluginMetadata } = usePluginRegistry();\n return useQuery({\n // `['*']` marks the \"every plugin type\" query so it gets its own cache entry.\n queryKey: ['listPluginMetadata', pluginTypes ?? ['*']],\n queryFn: () => listPluginMetadata(pluginTypes),\n ...options,\n });\n}\n\nexport function usePluginBuiltinVariableDefinitions(): UseQueryResult<BuiltinVariableDefinition[]> {\n const { getPlugin, listPluginMetadata } = usePluginRegistry();\n\n return useQuery({\n queryKey: ['usePluginBuiltinVariableDefinitions'],\n queryFn: async () => {\n const datasources = await listPluginMetadata(['Datasource']);\n const datasourceNames = new Set(datasources.map((datasource) => datasource.spec.name));\n const result: BuiltinVariableDefinition[] = [];\n for (const name of datasourceNames) {\n const plugin = await getPlugin({ kind: 'Datasource', name });\n if (plugin.getBuiltinVariableDefinitions) {\n plugin.getBuiltinVariableDefinitions().forEach((definition) => result.push(definition));\n }\n }\n return result;\n },\n });\n}\n"],"names":["useQueries","useQuery","createContext","useContext","PluginRegistryContext","undefined","usePluginRegistry","ctx","Error","usePlugin","pluginType","kind","options","version","registry","queryOptions","useQueryOptions","enabled","getPlugin","queryKey","queryFn","name","getUsePluginsItemIdentity","plugin","usePlugins","plugins","uniquePlugins","Map","p","key","has","set","uniqueKeys","keys","uniqueValues","values","result","queries","map","indexByIdentity","index","get","useListPluginMetadata","pluginTypes","listPluginMetadata","usePluginBuiltinVariableDefinitions","datasources","datasourceNames","Set","datasource","spec","getBuiltinVariableDefinitions","forEach","definition","push"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,SAASA,UAAU,EAAEC,QAAQ,QAAQ,wBAAwB;AAC7D,SAASC,aAAa,EAAEC,UAAU,QAAQ,QAAQ;AAgBlD,OAAO,MAAMC,wBAAwBF,cAAqDG,WAAW;AAErG;;;CAGC,GACD,OAAO,SAASC;IACd,MAAMC,MAAMJ,WAAWC;IACvB,IAAIG,QAAQF,WAAW;QACrB,MAAM,IAAIG,MAAM;IAClB;IACA,OAAOD;AACT;AAeA;;;;;CAKC,GACD,OAAO,SAASE,UACdC,UAAyB,EACzBC,IAAY,EACZC,OAA6B;IAE7B,MAAM,EAAEC,OAAO,EAAEC,QAAQ,EAAE,GAAGC,cAAc,GAAGH,WAAW,CAAC;IAC3D,wGAAwG;IACxG,MAAMI,kBAAkB;QACtB,GAAGD,YAAY;QACfE,SAAS,AAACF,CAAAA,aAAaE,OAAO,IAAI,IAAG,KAAMP,eAAeL,aAAaM,SAAS;IAClF;IACA,MAAM,EAAEO,SAAS,EAAE,GAAGZ;IACtB,OAAOL,SAAS;QACdkB,UAAU;YAAC;YAAaT;YAAYC;YAAME,WAAW;YAAI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AC,CAAC;AAC3G,eAAO,MAAM,iBAAiB,iBAAiB,CAAC;AAEhD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,sBAAsB,EAAE,GAAG,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"profile-queries.d.ts","sourceRoot":"","sources":["../../src/runtime/profile-queries.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAClF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAM5D,MAAM,MAAM,sBAAsB,CAAC,UAAU,GAAG,WAAW,IAAI,eAAe,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;AAC3G,eAAO,MAAM,iBAAiB,iBAAiB,CAAC;AAEhD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,sBAAsB,EAAE,GAAG,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC,CAqC3G"}
|