@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.
Files changed (74) hide show
  1. package/dist/components/MultiQueryEditor/MultiQueryEditor.d.ts.map +1 -1
  2. package/dist/components/MultiQueryEditor/MultiQueryEditor.js +16 -1
  3. package/dist/components/MultiQueryEditor/MultiQueryEditor.js.map +1 -1
  4. package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts.map +1 -1
  5. package/dist/components/PanelSpecEditor/PanelSpecEditor.js +4 -1
  6. package/dist/components/PanelSpecEditor/PanelSpecEditor.js.map +1 -1
  7. package/dist/components/PluginEditor/plugin-editor-api.d.ts +7 -1
  8. package/dist/components/PluginEditor/plugin-editor-api.d.ts.map +1 -1
  9. package/dist/components/PluginEditor/plugin-editor-api.js +6 -1
  10. package/dist/components/PluginEditor/plugin-editor-api.js.map +1 -1
  11. package/dist/components/PluginKindSelect/PluginKindSelect.d.ts +14 -0
  12. package/dist/components/PluginKindSelect/PluginKindSelect.d.ts.map +1 -1
  13. package/dist/components/PluginKindSelect/PluginKindSelect.js +187 -23
  14. package/dist/components/PluginKindSelect/PluginKindSelect.js.map +1 -1
  15. package/dist/components/PluginRegistry/PluginRegistry.d.ts.map +1 -1
  16. package/dist/components/PluginRegistry/PluginRegistry.js +67 -4
  17. package/dist/components/PluginRegistry/PluginRegistry.js.map +1 -1
  18. package/dist/components/PluginRegistry/plugin-indexes.d.ts +1 -0
  19. package/dist/components/PluginRegistry/plugin-indexes.d.ts.map +1 -1
  20. package/dist/components/PluginRegistry/plugin-indexes.js +6 -1
  21. package/dist/components/PluginRegistry/plugin-indexes.js.map +1 -1
  22. package/dist/components/PluginSpecEditor/PluginSpecEditor.d.ts.map +1 -1
  23. package/dist/components/PluginSpecEditor/PluginSpecEditor.js +6 -2
  24. package/dist/components/PluginSpecEditor/PluginSpecEditor.js.map +1 -1
  25. package/dist/components/Variables/variable-model.d.ts.map +1 -1
  26. package/dist/components/Variables/variable-model.js +7 -2
  27. package/dist/components/Variables/variable-model.js.map +1 -1
  28. package/dist/model/plugins.d.ts +11 -0
  29. package/dist/model/plugins.d.ts.map +1 -1
  30. package/dist/model/plugins.js.map +1 -1
  31. package/dist/remote/PluginRuntime.js +10 -10
  32. package/dist/remote/PluginRuntime.js.map +1 -1
  33. package/dist/runtime/TimeRangeProvider/TimeRangeProviders.d.ts +3 -1
  34. package/dist/runtime/TimeRangeProvider/TimeRangeProviders.d.ts.map +1 -1
  35. package/dist/runtime/TimeRangeProvider/TimeRangeProviders.js +2 -2
  36. package/dist/runtime/TimeRangeProvider/TimeRangeProviders.js.map +1 -1
  37. package/dist/runtime/alerts-queries.d.ts.map +1 -1
  38. package/dist/runtime/alerts-queries.js +6 -2
  39. package/dist/runtime/alerts-queries.js.map +1 -1
  40. package/dist/runtime/annotations.d.ts.map +1 -1
  41. package/dist/runtime/annotations.js +10 -3
  42. package/dist/runtime/annotations.js.map +1 -1
  43. package/dist/runtime/log-queries.d.ts.map +1 -1
  44. package/dist/runtime/log-queries.js +3 -1
  45. package/dist/runtime/log-queries.js.map +1 -1
  46. package/dist/runtime/plugin-registry.d.ts +22 -8
  47. package/dist/runtime/plugin-registry.d.ts.map +1 -1
  48. package/dist/runtime/plugin-registry.js +52 -16
  49. package/dist/runtime/plugin-registry.js.map +1 -1
  50. package/dist/runtime/profile-queries.d.ts.map +1 -1
  51. package/dist/runtime/profile-queries.js +3 -1
  52. package/dist/runtime/profile-queries.js.map +1 -1
  53. package/dist/runtime/silences-queries.d.ts.map +1 -1
  54. package/dist/runtime/silences-queries.js +6 -2
  55. package/dist/runtime/silences-queries.js.map +1 -1
  56. package/dist/runtime/time-series-queries.d.ts.map +1 -1
  57. package/dist/runtime/time-series-queries.js +10 -3
  58. package/dist/runtime/time-series-queries.js.map +1 -1
  59. package/dist/runtime/trace-queries.d.ts.map +1 -1
  60. package/dist/runtime/trace-queries.js +6 -2
  61. package/dist/runtime/trace-queries.js.map +1 -1
  62. package/dist/runtime/variables.d.ts +6 -0
  63. package/dist/runtime/variables.d.ts.map +1 -1
  64. package/dist/runtime/variables.js +17 -1
  65. package/dist/runtime/variables.js.map +1 -1
  66. package/dist/utils/index.d.ts +1 -0
  67. package/dist/utils/index.d.ts.map +1 -1
  68. package/dist/utils/index.js +1 -0
  69. package/dist/utils/index.js.map +1 -1
  70. package/dist/utils/plugin-versions.d.ts +18 -0
  71. package/dist/utils/plugin-versions.d.ts.map +1 -0
  72. package/dist/utils/plugin-versions.js +52 -0
  73. package/dist/utils/plugin-versions.js.map +1 -0
  74. package/package.json +5 -4
@@ -46,7 +46,9 @@ export const PROFILE_QUERY_KEY = 'ProfileQuery';
46
46
  queryFn: async ({ signal })=>{
47
47
  const plugin = await getPlugin({
48
48
  kind: PROFILE_QUERY_KEY,
49
- name: profileQueryKind
49
+ name: profileQueryKind,
50
+ version: definition.spec.plugin.metadata?.version,
51
+ registry: definition.spec.plugin.metadata?.registry
50
52
  });
51
53
  const data = await plugin.getProfileData(definition.spec.plugin.spec, context, signal);
52
54
  return data;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/runtime/profile-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, ProfileData } from '@perses-dev/spec';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQueries } from '@tanstack/react-query';\n\nimport { useDatasourceStore } from './datasources';\nimport { usePluginRegistry } from './plugin-registry';\nimport { useTimeRange } from './TimeRangeProvider';\nexport type ProfileQueryDefinition<PluginSpec = UnknownSpec> = QueryDefinition<'ProfileQuery', PluginSpec>;\nexport const PROFILE_QUERY_KEY = 'ProfileQuery';\n\n/**\n * Run a profile query using a ProfileQuery plugin and return the results\n * @param definitions: dashboard defintion for a profile query\n */\nexport function useProfileQueries(definitions: ProfileQueryDefinition[]): Array<UseQueryResult<ProfileData>> {\n const { getPlugin } = usePluginRegistry();\n const datasourceStore = useDatasourceStore();\n const { absoluteTimeRange } = useTimeRange();\n\n const context = {\n datasourceStore,\n absoluteTimeRange,\n };\n\n // useQueries() handles data fetching from query plugins (e.g. traceQL queries, promQL queries)\n // https://tanstack.com/query/v4/docs/react/reference/useQuery\n return useQueries({\n queries: definitions.map((definition) => {\n const queryKey = ['query', PROFILE_QUERY_KEY, definition, absoluteTimeRange] as const; // `queryKey` watches and reruns `queryFn` if keys in the array change\n const profileQueryKind = 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<ProfileData> => {\n const plugin = await getPlugin({ kind: PROFILE_QUERY_KEY, name: profileQueryKind });\n const data = await plugin.getProfileData(definition.spec.plugin.spec, context, signal);\n return data;\n },\n\n structuralSharing: false,\n };\n }),\n });\n}\n"],"names":["useQueries","useDatasourceStore","usePluginRegistry","useTimeRange","PROFILE_QUERY_KEY","useProfileQueries","definitions","getPlugin","datasourceStore","absoluteTimeRange","context","queries","map","definition","queryKey","profileQueryKind","spec","plugin","kind","refetchOnMount","refetchOnWindowFocus","refetchOnReconnect","staleTime","Infinity","queryFn","signal","name","data","getProfileData","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;AAEnD,SAASC,kBAAkB,QAAQ,mBAAgB;AACnD,SAASC,iBAAiB,QAAQ,uBAAoB;AACtD,SAASC,YAAY,QAAQ,+BAAsB;AAEnD,OAAO,MAAMC,oBAAoB,eAAe;AAEhD;;;CAGC,GACD,OAAO,SAASC,kBAAkBC,WAAqC;IACrE,MAAM,EAAEC,SAAS,EAAE,GAAGL;IACtB,MAAMM,kBAAkBP;IACxB,MAAM,EAAEQ,iBAAiB,EAAE,GAAGN;IAE9B,MAAMO,UAAU;QACdF;QACAC;IACF;IAEA,+FAA+F;IAC/F,8DAA8D;IAC9D,OAAOT,WAAW;QAChBW,SAASL,YAAYM,GAAG,CAAC,CAACC;YACxB,MAAMC,WAAW;gBAAC;gBAASV;gBAAmBS;gBAAYJ;aAAkB,EAAW,sEAAsE;YAC7J,MAAMM,mBAAmBF,YAAYG,MAAMC,QAAQC;YACnD,OAAO;gBACLJ,UAAUA;gBACVK,gBAAgB;gBAChBC,sBAAsB;gBACtBC,oBAAoB;gBACpBC,WAAWC;gBACXC,SAAS,OAAO,EAAEC,MAAM,EAA4B;oBAClD,MAAMR,SAAS,MAAMV,UAAU;wBAAEW,MAAMd;wBAAmBsB,MAAMX;oBAAiB;oBACjF,MAAMY,OAAO,MAAMV,OAAOW,cAAc,CAACf,WAAWG,IAAI,CAACC,MAAM,CAACD,IAAI,EAAEN,SAASe;oBAC/E,OAAOE;gBACT;gBAEAE,mBAAmB;YACrB;QACF;IACF;AACF"}
1
+ {"version":3,"sources":["../../src/runtime/profile-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, ProfileData } from '@perses-dev/spec';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQueries } from '@tanstack/react-query';\n\nimport { useDatasourceStore } from './datasources';\nimport { usePluginRegistry } from './plugin-registry';\nimport { useTimeRange } from './TimeRangeProvider';\nexport type ProfileQueryDefinition<PluginSpec = UnknownSpec> = QueryDefinition<'ProfileQuery', PluginSpec>;\nexport const PROFILE_QUERY_KEY = 'ProfileQuery';\n\n/**\n * Run a profile query using a ProfileQuery plugin and return the results\n * @param definitions: dashboard defintion for a profile query\n */\nexport function useProfileQueries(definitions: ProfileQueryDefinition[]): Array<UseQueryResult<ProfileData>> {\n const { getPlugin } = usePluginRegistry();\n const datasourceStore = useDatasourceStore();\n const { absoluteTimeRange } = useTimeRange();\n\n const context = {\n datasourceStore,\n absoluteTimeRange,\n };\n\n // useQueries() handles data fetching from query plugins (e.g. traceQL queries, promQL queries)\n // https://tanstack.com/query/v4/docs/react/reference/useQuery\n return useQueries({\n queries: definitions.map((definition) => {\n const queryKey = ['query', PROFILE_QUERY_KEY, definition, absoluteTimeRange] as const; // `queryKey` watches and reruns `queryFn` if keys in the array change\n const profileQueryKind = 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<ProfileData> => {\n const plugin = await getPlugin({\n kind: PROFILE_QUERY_KEY,\n name: profileQueryKind,\n version: definition.spec.plugin.metadata?.version,\n registry: definition.spec.plugin.metadata?.registry,\n });\n const data = await plugin.getProfileData(definition.spec.plugin.spec, context, signal);\n return data;\n },\n\n structuralSharing: false,\n };\n }),\n });\n}\n"],"names":["useQueries","useDatasourceStore","usePluginRegistry","useTimeRange","PROFILE_QUERY_KEY","useProfileQueries","definitions","getPlugin","datasourceStore","absoluteTimeRange","context","queries","map","definition","queryKey","profileQueryKind","spec","plugin","kind","refetchOnMount","refetchOnWindowFocus","refetchOnReconnect","staleTime","Infinity","queryFn","signal","name","version","metadata","registry","data","getProfileData","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;AAEnD,SAASC,kBAAkB,QAAQ,mBAAgB;AACnD,SAASC,iBAAiB,QAAQ,uBAAoB;AACtD,SAASC,YAAY,QAAQ,+BAAsB;AAEnD,OAAO,MAAMC,oBAAoB,eAAe;AAEhD;;;CAGC,GACD,OAAO,SAASC,kBAAkBC,WAAqC;IACrE,MAAM,EAAEC,SAAS,EAAE,GAAGL;IACtB,MAAMM,kBAAkBP;IACxB,MAAM,EAAEQ,iBAAiB,EAAE,GAAGN;IAE9B,MAAMO,UAAU;QACdF;QACAC;IACF;IAEA,+FAA+F;IAC/F,8DAA8D;IAC9D,OAAOT,WAAW;QAChBW,SAASL,YAAYM,GAAG,CAAC,CAACC;YACxB,MAAMC,WAAW;gBAAC;gBAASV;gBAAmBS;gBAAYJ;aAAkB,EAAW,sEAAsE;YAC7J,MAAMM,mBAAmBF,YAAYG,MAAMC,QAAQC;YACnD,OAAO;gBACLJ,UAAUA;gBACVK,gBAAgB;gBAChBC,sBAAsB;gBACtBC,oBAAoB;gBACpBC,WAAWC;gBACXC,SAAS,OAAO,EAAEC,MAAM,EAA4B;oBAClD,MAAMR,SAAS,MAAMV,UAAU;wBAC7BW,MAAMd;wBACNsB,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,cAAc,CAAClB,WAAWG,IAAI,CAACC,MAAM,CAACD,IAAI,EAAEN,SAASe;oBAC/E,OAAOK;gBACT;gBAEAE,mBAAmB;YACrB;QACF;IACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"silences-queries.d.ts","sourceRoot":"","sources":["../../src/runtime/silences-queries.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACnF,OAAO,KAAK,EAAY,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAStE,MAAM,MAAM,uBAAuB,CAAC,UAAU,GAAG,WAAW,IAAI,eAAe,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;AAC7G,eAAO,MAAM,kBAAkB,kBAAkB,CAAC;AAElD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,uBAAuB,EAAE,GAAG,KAAK,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC,CA6B9G"}
1
+ {"version":3,"file":"silences-queries.d.ts","sourceRoot":"","sources":["../../src/runtime/silences-queries.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACnF,OAAO,KAAK,EAAY,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAStE,MAAM,MAAM,uBAAuB,CAAC,UAAU,GAAG,WAAW,IAAI,eAAe,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;AAC7G,eAAO,MAAM,kBAAkB,kBAAkB,CAAC;AAElD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,uBAAuB,EAAE,GAAG,KAAK,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC,CAsC9G"}
@@ -24,7 +24,9 @@ export const SILENCES_QUERY_KEY = 'SilencesQuery';
24
24
  const { getPlugin } = usePluginRegistry();
25
25
  const context = useSilencesQueryContext();
26
26
  const pluginLoaderResponse = usePlugins('SilencesQuery', 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 SILENCES_QUERY_KEY = 'SilencesQuery';
45
47
  queryFn: async ({ signal })=>{
46
48
  const plugin = await getPlugin({
47
49
  kind: SILENCES_QUERY_KEY,
48
- name: silencesQueryKind
50
+ name: silencesQueryKind,
51
+ version: definition.spec.plugin.metadata?.version,
52
+ registry: definition.spec.plugin.metadata?.registry
49
53
  });
50
54
  const data = await plugin.getSilencesData(definition.spec.plugin.spec, context, signal);
51
55
  return data;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/runtime/silences-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 { SilencesData, QueryDefinition, UnknownSpec } from '@perses-dev/spec';\nimport type { QueryKey, UseQueryResult } from '@tanstack/react-query';\nimport { useQueries } from '@tanstack/react-query';\n\nimport type { SilencesQueryContext, SilencesQueryPlugin } from '../model';\nimport { useDatasourceStore } from './datasources';\nimport { usePluginRegistry, usePlugins } from './plugin-registry';\nimport { filterVariableStateMap, getVariableValuesKey } from './utils';\nimport { useAllVariableValues } from './variables';\n\nexport type SilencesQueryDefinition<PluginSpec = UnknownSpec> = QueryDefinition<'SilencesQuery', PluginSpec>;\nexport const SILENCES_QUERY_KEY = 'SilencesQuery';\n\n/**\n * Run a silences query using a SilencesQuery plugin and return the results.\n * Silences represent current state and are NOT time-range dependent.\n * @param definitions: dashboard definition for a silences query\n */\nexport function useSilencesQueries(definitions: SilencesQueryDefinition[]): Array<UseQueryResult<SilencesData>> {\n const { getPlugin } = usePluginRegistry();\n const context = useSilencesQueryContext();\n\n const pluginLoaderResponse = usePlugins(\n 'SilencesQuery',\n definitions.map((d) => ({ kind: d.spec.plugin.kind })),\n );\n\n return useQueries({\n queries: definitions.map((definition, idx) => {\n const plugin = pluginLoaderResponse[idx]?.data;\n const { queryEnabled, queryKey } = getQueryOptions({ context, definition, plugin });\n const silencesQueryKind = 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<SilencesData> => {\n const plugin = await getPlugin({ kind: SILENCES_QUERY_KEY, name: silencesQueryKind });\n const data = await plugin.getSilencesData(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?: SilencesQueryPlugin;\n definition: SilencesQueryDefinition;\n context: SilencesQueryContext;\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 silences are current state\n const queryKey = ['query', SILENCES_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 useSilencesQueryContext(): SilencesQueryContext {\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","SILENCES_QUERY_KEY","useSilencesQueries","definitions","getPlugin","context","useSilencesQueryContext","pluginLoaderResponse","map","d","kind","spec","plugin","queries","definition","idx","data","queryEnabled","queryKey","getQueryOptions","silencesQueryKind","enabled","refetchOnMount","refetchOnWindowFocus","refetchOnReconnect","staleTime","queryFn","signal","name","getSilencesData","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,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,EAAEC,UAAU,QAAQ,uBAAoB;AAClE,SAASC,sBAAsB,EAAEC,oBAAoB,QAAQ,aAAU;AACvE,SAASC,oBAAoB,QAAQ,iBAAc;AAGnD,OAAO,MAAMC,qBAAqB,gBAAgB;AAElD;;;;CAIC,GACD,OAAO,SAASC,mBAAmBC,WAAsC;IACvE,MAAM,EAAEC,SAAS,EAAE,GAAGR;IACtB,MAAMS,UAAUC;IAEhB,MAAMC,uBAAuBV,WAC3B,iBACAM,YAAYK,GAAG,CAAC,CAACC,IAAO,CAAA;YAAEC,MAAMD,EAAEE,IAAI,CAACC,MAAM,CAACF,IAAI;QAAC,CAAA;IAGrD,OAAOhB,WAAW;QAChBmB,SAASV,YAAYK,GAAG,CAAC,CAACM,YAAYC;YACpC,MAAMH,SAASL,oBAAoB,CAACQ,IAAI,EAAEC;YAC1C,MAAM,EAAEC,YA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esContent":["// 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 { SilencesData, QueryDefinition, UnknownSpec } from '@perses-dev/spec';\nimport type { QueryKey, UseQueryResult } from '@tanstack/react-query';\nimport { useQueries } from '@tanstack/react-query';\n\nimport type { SilencesQueryContext, SilencesQueryPlugin } from '../model';\nimport { useDatasourceStore } from './datasources';\nimport { usePluginRegistry, usePlugins } from './plugin-registry';\nimport { filterVariableStateMap, getVariableValuesKey } from './utils';\nimport { useAllVariableValues } from './variables';\n\nexport type SilencesQueryDefinition<PluginSpec = UnknownSpec> = QueryDefinition<'SilencesQuery', PluginSpec>;\nexport const SILENCES_QUERY_KEY = 'SilencesQuery';\n\n/**\n * Run a silences query using a SilencesQuery plugin and return the results.\n * Silences represent current state and are NOT time-range dependent.\n * @param definitions: dashboard definition for a silences query\n */\nexport function useSilencesQueries(definitions: SilencesQueryDefinition[]): Array<UseQueryResult<SilencesData>> {\n const { getPlugin } = usePluginRegistry();\n const context = useSilencesQueryContext();\n\n const pluginLoaderResponse = usePlugins(\n 'SilencesQuery',\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 silencesQueryKind = 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<SilencesData> => {\n const plugin = await getPlugin({\n kind: SILENCES_QUERY_KEY,\n name: silencesQueryKind,\n version: definition.spec.plugin.metadata?.version,\n registry: definition.spec.plugin.metadata?.registry,\n });\n const data = await plugin.getSilencesData(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?: SilencesQueryPlugin;\n definition: SilencesQueryDefinition;\n context: SilencesQueryContext;\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 silences are current state\n const queryKey = ['query', SILENCES_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 useSilencesQueryContext(): SilencesQueryContext {\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","SILENCES_QUERY_KEY","useSilencesQueries","definitions","getPlugin","context","useSilencesQueryContext","pluginLoaderResponse","map","d","kind","spec","plugin","version","metadata","registry","queries","definition","idx","data","queryEnabled","queryKey","getQueryOptions","silencesQueryKind","enabled","refetchOnMount","refetchOnWindowFocus","refetchOnReconnect","staleTime","queryFn","signal","name","getSilencesData","variableState","dependencies","dependsOn","variableDependencies","variables","filteredVariabledState","variablesValueKey","waitToLoad","some","v","loading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AU;wBAC7BM,MAAMT;wBACN8B,MAAMR;wBACNV,SAASI,WAAWN,IAAI,CAACC,MAAM,CAACE,QAAQ,EAAED;wBAC1CE,UAAUE,WAAWN,IAAI,CAACC,MAAM,CAACE,QAAQ,EAAEC;oBAC7C;oBACA,MAAMI,OAAO,MAAMP,OAAOoB,eAAe,CAACf,WAAWN,IAAI,CAACC,MAAM,CAACD,IAAI,EAAEN,SAASyB;oBAChF,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,2EAA2E;IAC3E,MAAMjB,WAAW;QAAC;QAASpB;QAAoBgB;QAAYsB;KAAkB;IAE7E,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":"time-series-queries.d.ts","sourceRoot":"","sources":["../../src/runtime/time-series-queries.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,cAAc,EAAE,yBAAyB,EAAe,MAAM,kBAAkB,CAAC;AAC/F,OAAO,KAAK,EAAS,UAAU,EAAY,oBAAoB,EAA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C;AA+CvD;;GAEG;AACH,eAAO,MAAM,kBAAkB,eACjB,yBAAyB,YAC3B,yBAAyB,iBACpB,oBAAoB,CAAC,cAAc,CAAC,KAClD,cAAc,CAAC,cAAc,CAoB/B,CAAC;AAEF;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,yBAAyB,EAAE,EACxC,OAAO,CAAC,EAAE,yBAAyB,EACnC,YAAY,CAAC,EAAE,IAAI,CAAC,oBAAoB,EAAE,UAAU,CAAC,GACpD,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC,CAyCvC;AAiBD;;GAEG;AACH,wBAAgB,0BAA0B,IAAI,mBAAmB,EAAE,CAIlE;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,UAAU,GAAG,mBAAmB,EAAE,CAWnF"}
@@ -47,7 +47,10 @@ function getQueryOptions({ plugin, definition, context }) {
47
47
  /**
48
48
  * Runs a time series query using a plugin and returns the results.
49
49
  */ export const useTimeSeriesQuery = (definition, options, queryOptions)=>{
50
- const { data: plugin } = usePlugin(TIME_SERIES_QUERY_KEY, definition.spec.plugin.kind);
50
+ const { data: plugin } = usePlugin(TIME_SERIES_QUERY_KEY, definition.spec.plugin.kind, {
51
+ version: definition.spec.plugin.metadata?.version,
52
+ registry: definition.spec.plugin.metadata?.registry
53
+ });
51
54
  const context = useTimeSeriesQueryContext();
52
55
  const { queryEnabled, queryKey } = getQueryOptions({
53
56
  plugin,
@@ -81,7 +84,9 @@ function getQueryOptions({ plugin, definition, context }) {
81
84
  suggestedStepMs: options?.suggestedStepMs
82
85
  };
83
86
  const pluginLoaderResponse = usePlugins(TIME_SERIES_QUERY_KEY, definitions.map((d)=>({
84
- kind: d.spec.plugin.kind
87
+ kind: d.spec.plugin.kind,
88
+ version: d.spec.plugin.metadata?.version,
89
+ registry: d.spec.plugin.metadata?.registry
85
90
  })));
86
91
  return useQueries({
87
92
  queries: definitions.map((definition, idx)=>{
@@ -102,7 +107,9 @@ function getQueryOptions({ plugin, definition, context }) {
102
107
  queryFn: async ({ signal })=>{
103
108
  const plugin = await getPlugin({
104
109
  kind: TIME_SERIES_QUERY_KEY,
105
- name: definition.spec.plugin.kind
110
+ name: definition.spec.plugin.kind,
111
+ version: definition.spec.plugin.metadata?.version,
112
+ registry: definition.spec.plugin.metadata?.registry
106
113
  });
107
114
  const data = await plugin.getTimeSeriesData(definition.spec.plugin.spec, context, signal);
108
115
  return data;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/runtime/time-series-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 { TimeSeriesData, TimeSeriesQueryDefinition, UnknownSpec } from '@perses-dev/spec';\nimport type { Query, QueryCache, QueryKey, QueryObserverOptions, UseQueryResult } from '@tanstack/react-query';\nimport { useQueries, useQuery, useQueryClient } from '@tanstack/react-query';\n\nimport type { TimeSeriesDataQuery, TimeSeriesQueryContext, TimeSeriesQueryMode, TimeSeriesQueryPlugin } 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 interface UseTimeSeriesQueryOptions {\n suggestedStepMs?: number;\n mode?: TimeSeriesQueryMode;\n}\n\nexport const TIME_SERIES_QUERY_KEY = 'TimeSeriesQuery';\n\nfunction getQueryOptions({\n plugin,\n definition,\n context,\n}: {\n plugin?: TimeSeriesQueryPlugin;\n definition: TimeSeriesQueryDefinition;\n context: TimeSeriesQueryContext;\n}): {\n queryKey: QueryKey;\n queryEnabled: boolean;\n} {\n const { timeRange, suggestedStepMs, mode, variableState } = context;\n\n const dependencies = plugin?.dependsOn ? plugin.dependsOn(definition.spec.plugin.spec, context) : {};\n const variableDependencies = dependencies?.variables;\n\n // Determine queryKey\n const filteredVariabledState = filterVariableStateMap(variableState, variableDependencies);\n const variablesValueKey = getVariableValuesKey(filteredVariabledState);\n\n const queryKey = [\n 'query',\n TIME_SERIES_QUERY_KEY,\n definition,\n timeRange,\n variablesValueKey,\n suggestedStepMs,\n mode,\n ] as const;\n\n // Determine queryEnabled\n let waitToLoad = false;\n if (variableDependencies) {\n waitToLoad = variableDependencies.some((v) => variableState[v]?.loading);\n }\n\n const queryEnabled = plugin !== undefined && !waitToLoad;\n\n return {\n queryKey,\n queryEnabled,\n };\n}\n\n/**\n * Runs a time series query using a plugin and returns the results.\n */\nexport const useTimeSeriesQuery = (\n definition: TimeSeriesQueryDefinition,\n options?: UseTimeSeriesQueryOptions,\n queryOptions?: QueryObserverOptions<TimeSeriesData>,\n): UseQueryResult<TimeSeriesData> => {\n const { data: plugin } = usePlugin(TIME_SERIES_QUERY_KEY, definition.spec.plugin.kind);\n const context = useTimeSeriesQueryContext();\n const { queryEnabled, queryKey } = getQueryOptions({ plugin, definition, context });\n return useQuery({\n enabled: (queryOptions?.enabled ?? true) || queryEnabled,\n queryKey: queryKey,\n queryFn: ({ signal }) => {\n // The 'enabled' option should prevent this from happening, but make TypeScript happy by checking\n if (plugin === undefined) {\n throw new Error('Expected plugin to be loaded');\n }\n // Keep options out of query key so we don't re-run queries because suggested step changes\n const ctx: TimeSeriesQueryContext = { ...context, suggestedStepMs: options?.suggestedStepMs };\n return plugin.getTimeSeriesData(definition.spec.plugin.spec, ctx, signal);\n },\n });\n};\n\n/**\n * Runs multiple time series queries using plugins and returns the results.\n */\nexport function useTimeSeriesQueries(\n definitions: TimeSeriesQueryDefinition[],\n options?: UseTimeSeriesQueryOptions,\n queryOptions?: Omit<QueryObserverOptions, 'queryKey'>,\n): Array<UseQueryResult<TimeSeriesData>> {\n const { getPlugin } = usePluginRegistry();\n const context = {\n ...useTimeSeriesQueryContext(),\n mode: options?.mode,\n suggestedStepMs: options?.suggestedStepMs,\n };\n\n const pluginLoaderResponse = usePlugins(\n TIME_SERIES_QUERY_KEY,\n definitions.map((d) => ({ kind: d.spec.plugin.kind })),\n );\n return useQueries({\n queries: definitions.map((definition, idx) => {\n const plugin = pluginLoaderResponse[idx]?.data;\n const { queryEnabled, queryKey } = getQueryOptions({ plugin, definition, context });\n return {\n ...queryOptions,\n enabled: (queryOptions?.enabled ?? true) && queryEnabled,\n refetchOnMount: false,\n refetchOnWindowFocus: false,\n refetchOnReconnect: false,\n staleTime: Infinity,\n queryKey: queryKey,\n queryFn: async ({ signal }: { signal: AbortSignal }): Promise<TimeSeriesData> => {\n const plugin = await getPlugin({ kind: TIME_SERIES_QUERY_KEY, name: definition.spec.plugin.kind });\n const data = await plugin.getTimeSeriesData(definition.spec.plugin.spec, context, signal);\n return data;\n },\n } as QueryObserverOptions;\n }),\n }) as Array<UseQueryResult<TimeSeriesData>>;\n}\n\n/**\n * Build the time series query context object from data available at runtime\n */\nfunction useTimeSeriesQueryContext(): TimeSeriesQueryContext {\n const { absoluteTimeRange } = useTimeRange();\n const variableState = useAllVariableValues();\n const datasourceStore = useDatasourceStore();\n\n return {\n timeRange: absoluteTimeRange,\n variableState,\n datasourceStore,\n };\n}\n\n/**\n * Get active time series queries for query results summary\n */\nexport function useActiveTimeSeriesQueries(): TimeSeriesDataQuery[] {\n const queryClient = useQueryClient();\n const queryCache = queryClient.getQueryCache();\n return getActiveTimeSeriesQueries(queryCache);\n}\n\n/**\n * Filter all cached queries down to only active time series queries\n */\nexport function getActiveTimeSeriesQueries(cache: QueryCache): TimeSeriesDataQuery[] {\n const queries: TimeSeriesDataQuery[] = [];\n\n for (const query of cache.findAll({ type: 'active' })) {\n const firstPart = query.queryKey?.[0] as UnknownSpec;\n if (firstPart?.kind && (firstPart.kind as string).startsWith(TIME_SERIES_QUERY_KEY)) {\n queries.push(query as Query<TimeSeriesData, unknown, TimeSeriesData, QueryKey>);\n }\n }\n\n return queries;\n}\n"],"names":["useQueries","useQuery","useQueryClient","useDatasourceStore","usePlugin","usePluginRegistry","usePlugins","useTimeRange","filterVariableStateMap","getVariableValuesKey","useAllVariableValues","TIME_SERIES_QUERY_KEY","getQueryOptions","plugin","definition","context","timeRange","suggestedStepMs","mode","variableState","dependencies","dependsOn","spec","variableDependencies","variables","filteredVariabledState","variablesValueKey","queryKey","waitToLoad","some","v","loading","queryEnabled","undefined","useTimeSeriesQuery","options","queryOptions","data","kind","useTimeSeriesQueryContext","enabled","queryFn","signal","Error","ctx","getTimeSeriesData","useTimeSeriesQueries","definitions","getPlugin","pluginLoaderResponse","map","d","queries","idx","refetchOnMount","refetchOnWindowFocus","refetchOnReconnect","staleTime","Infinity","name","absoluteTimeRange","datasourceStore","useActiveTimeSeriesQueries","queryClient","queryCache","getQueryCache","getActiveTimeSeriesQueries","cache","query","findAll","type","firstPart","startsWith","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,EAAEC,cAAc,QAAQ,wBAAwB;AAG7E,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;AAOnD,OAAO,MAAMC,wBAAwB,kBAAkB;AAEvD,SAASC,gBAAgB,EACvBC,MAAM,EACNC,UAAU,EACVC,OAAO,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ACLa,WAAW4C;QACXzC;QACA0C;IACF;AACF;AAEA;;CAEC,GACD,OAAO,SAASC;IACd,MAAMC,cAAc7D;IACpB,MAAM8D,aAAaD,YAAYE,aAAa;IAC5C,OAAOC,2BAA2BF;AACpC;AAEA;;CAEC,GACD,OAAO,SAASE,2BAA2BC,KAAiB;IAC1D,MAAMf,UAAiC,EAAE;IAEzC,KAAK,MAAMgB,SAASD,MAAME,OAAO,CAAC;QAAEC,MAAM;IAAS,GAAI;QACrD,MAAMC,YAAYH,MAAMzC,QAAQ,EAAE,CAAC,EAAE;QACrC,IAAI4C,WAAWjC,QAAQ,AAACiC,UAAUjC,IAAI,CAAYkC,UAAU,CAAC7D,wBAAwB;YACnFyC,QAAQqB,IAAI,CAACL;QACf;IACF;IAEA,OAAOhB;AACT"}
1
+ {"version":3,"sources":["../../src/runtime/time-series-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 { TimeSeriesData, TimeSeriesQueryDefinition, UnknownSpec } from '@perses-dev/spec';\nimport type { Query, QueryCache, QueryKey, QueryObserverOptions, UseQueryResult } from '@tanstack/react-query';\nimport { useQueries, useQuery, useQueryClient } from '@tanstack/react-query';\n\nimport type { TimeSeriesDataQuery, TimeSeriesQueryContext, TimeSeriesQueryMode, TimeSeriesQueryPlugin } 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 interface UseTimeSeriesQueryOptions {\n suggestedStepMs?: number;\n mode?: TimeSeriesQueryMode;\n}\n\nexport const TIME_SERIES_QUERY_KEY = 'TimeSeriesQuery';\n\nfunction getQueryOptions({\n plugin,\n definition,\n context,\n}: {\n plugin?: TimeSeriesQueryPlugin;\n definition: TimeSeriesQueryDefinition;\n context: TimeSeriesQueryContext;\n}): {\n queryKey: QueryKey;\n queryEnabled: boolean;\n} {\n const { timeRange, suggestedStepMs, mode, variableState } = context;\n\n const dependencies = plugin?.dependsOn ? plugin.dependsOn(definition.spec.plugin.spec, context) : {};\n const variableDependencies = dependencies?.variables;\n\n // Determine queryKey\n const filteredVariabledState = filterVariableStateMap(variableState, variableDependencies);\n const variablesValueKey = getVariableValuesKey(filteredVariabledState);\n\n const queryKey = [\n 'query',\n TIME_SERIES_QUERY_KEY,\n definition,\n timeRange,\n variablesValueKey,\n suggestedStepMs,\n mode,\n ] as const;\n\n // Determine queryEnabled\n let waitToLoad = false;\n if (variableDependencies) {\n waitToLoad = variableDependencies.some((v) => variableState[v]?.loading);\n }\n\n const queryEnabled = plugin !== undefined && !waitToLoad;\n\n return {\n queryKey,\n queryEnabled,\n };\n}\n\n/**\n * Runs a time series query using a plugin and returns the results.\n */\nexport const useTimeSeriesQuery = (\n definition: TimeSeriesQueryDefinition,\n options?: UseTimeSeriesQueryOptions,\n queryOptions?: QueryObserverOptions<TimeSeriesData>,\n): UseQueryResult<TimeSeriesData> => {\n const { data: plugin } = usePlugin(TIME_SERIES_QUERY_KEY, definition.spec.plugin.kind, {\n version: definition.spec.plugin.metadata?.version,\n registry: definition.spec.plugin.metadata?.registry,\n });\n const context = useTimeSeriesQueryContext();\n const { queryEnabled, queryKey } = getQueryOptions({ plugin, definition, context });\n return useQuery({\n enabled: (queryOptions?.enabled ?? true) || queryEnabled,\n queryKey: queryKey,\n queryFn: ({ signal }) => {\n // The 'enabled' option should prevent this from happening, but make TypeScript happy by checking\n if (plugin === undefined) {\n throw new Error('Expected plugin to be loaded');\n }\n // Keep options out of query key so we don't re-run queries because suggested step changes\n const ctx: TimeSeriesQueryContext = { ...context, suggestedStepMs: options?.suggestedStepMs };\n return plugin.getTimeSeriesData(definition.spec.plugin.spec, ctx, signal);\n },\n });\n};\n\n/**\n * Runs multiple time series queries using plugins and returns the results.\n */\nexport function useTimeSeriesQueries(\n definitions: TimeSeriesQueryDefinition[],\n options?: UseTimeSeriesQueryOptions,\n queryOptions?: Omit<QueryObserverOptions, 'queryKey'>,\n): Array<UseQueryResult<TimeSeriesData>> {\n const { getPlugin } = usePluginRegistry();\n const context = {\n ...useTimeSeriesQueryContext(),\n mode: options?.mode,\n suggestedStepMs: options?.suggestedStepMs,\n };\n\n const pluginLoaderResponse = usePlugins(\n TIME_SERIES_QUERY_KEY,\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 return useQueries({\n queries: definitions.map((definition, idx) => {\n const plugin = pluginLoaderResponse[idx]?.data;\n const { queryEnabled, queryKey } = getQueryOptions({ plugin, definition, context });\n return {\n ...queryOptions,\n enabled: (queryOptions?.enabled ?? true) && queryEnabled,\n refetchOnMount: false,\n refetchOnWindowFocus: false,\n refetchOnReconnect: false,\n staleTime: Infinity,\n queryKey: queryKey,\n queryFn: async ({ signal }: { signal: AbortSignal }): Promise<TimeSeriesData> => {\n const plugin = await getPlugin({\n kind: TIME_SERIES_QUERY_KEY,\n name: definition.spec.plugin.kind,\n version: definition.spec.plugin.metadata?.version,\n registry: definition.spec.plugin.metadata?.registry,\n });\n const data = await plugin.getTimeSeriesData(definition.spec.plugin.spec, context, signal);\n return data;\n },\n } as QueryObserverOptions;\n }),\n }) as Array<UseQueryResult<TimeSeriesData>>;\n}\n\n/**\n * Build the time series query context object from data available at runtime\n */\nfunction useTimeSeriesQueryContext(): TimeSeriesQueryContext {\n const { absoluteTimeRange } = useTimeRange();\n const variableState = useAllVariableValues();\n const datasourceStore = useDatasourceStore();\n\n return {\n timeRange: absoluteTimeRange,\n variableState,\n datasourceStore,\n };\n}\n\n/**\n * Get active time series queries for query results summary\n */\nexport function useActiveTimeSeriesQueries(): TimeSeriesDataQuery[] {\n const queryClient = useQueryClient();\n const queryCache = queryClient.getQueryCache();\n return getActiveTimeSeriesQueries(queryCache);\n}\n\n/**\n * Filter all cached queries down to only active time series queries\n */\nexport function getActiveTimeSeriesQueries(cache: QueryCache): TimeSeriesDataQuery[] {\n const queries: TimeSeriesDataQuery[] = [];\n\n for (const query of cache.findAll({ type: 'active' })) {\n const firstPart = query.queryKey?.[0] as UnknownSpec;\n if (firstPart?.kind && (firstPart.kind as string).startsWith(TIME_SERIES_QUERY_KEY)) {\n queries.push(query as Query<TimeSeriesData, unknown, TimeSeriesData, QueryKey>);\n }\n }\n\n return queries;\n}\n"],"names":["useQueries","useQuery","useQueryClient","useDatasourceStore","usePlugin","usePluginRegistry","usePlugins","useTimeRange","filterVariableStateMap","getVariableValuesKey","useAllVariableValues","TIME_SERIES_QUERY_KEY","getQueryOptions","plugin","definition","context","timeRange","suggestedStepMs","mode","variableState","dependencies","dependsOn","spec","variableDependencies","variables","filteredVariabledState","variablesValueKey","queryKey","waitToLoad","some","v","loading","queryEnabled","undefined","useTimeSeriesQuery","options","queryOptions","data","kind","version","metadata","registry","useTimeSeriesQueryContext","enabled","queryFn","signal","Error","ctx","getTimeSeriesData","useTimeSeriesQueries","definitions","getPlugin","pluginLoaderResponse","map","d","queries","idx","refetchOnMount","refetchOnWindowFocus","refetchOnReconnect","staleTime","Infinity","name","absoluteTimeRange","datasourceStore","useActiveTimeSeriesQueries","queryClient","queryCache","getQueryCache","getActiveTimeSeriesQueries","cache","query","findAll","type","firstPart","startsWith","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,i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AAI,CAACL;QACf;IACF;IAEA,OAAOhB;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"trace-queries.d.ts","sourceRoot":"","sources":["../../src/runtime/trace-queries.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAChF,OAAO,KAAK,EAAY,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAStE,MAAM,MAAM,oBAAoB,CAAC,UAAU,GAAG,WAAW,IAAI,eAAe,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;AACvG,eAAO,MAAM,eAAe,eAAe,CAAC;AAE5C;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,WAAW,EAAE,oBAAoB,EAAE,GAAG,KAAK,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,CA+BrG"}
1
+ {"version":3,"file":"trace-queries.d.ts","sourceRoot":"","sources":["../../src/runtime/trace-queries.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAChF,OAAO,KAAK,EAAY,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAStE,MAAM,MAAM,oBAAoB,CAAC,UAAU,GAAG,WAAW,IAAI,eAAe,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;AACvG,eAAO,MAAM,eAAe,eAAe,CAAC;AAE5C;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,WAAW,EAAE,oBAAoB,EAAE,GAAG,KAAK,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,CAwCrG"}
@@ -25,7 +25,9 @@ export const TRACE_QUERY_KEY = 'TraceQuery';
25
25
  const { getPlugin } = usePluginRegistry();
26
26
  const context = useTraceQueryContext();
27
27
  const pluginLoaderResponse = usePlugins('TraceQuery', definitions.map((d)=>({
28
- kind: d.spec.plugin.kind
28
+ kind: d.spec.plugin.kind,
29
+ version: d.spec.plugin.metadata?.version,
30
+ registry: d.spec.plugin.metadata?.registry
29
31
  })));
30
32
  // useQueries() handles data fetching from query plugins (e.g. traceQL queries, promQL queries)
31
33
  // https://tanstack.com/query/v4/docs/react/reference/useQuery
@@ -48,7 +50,9 @@ export const TRACE_QUERY_KEY = 'TraceQuery';
48
50
  queryFn: async ({ signal })=>{
49
51
  const plugin = await getPlugin({
50
52
  kind: TRACE_QUERY_KEY,
51
- name: traceQueryKind
53
+ name: traceQueryKind,
54
+ version: definition.spec.plugin.metadata?.version,
55
+ registry: definition.spec.plugin.metadata?.registry
52
56
  });
53
57
  const data = await plugin.getTraceData(definition.spec.plugin.spec, context, signal);
54
58
  return data;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/runtime/trace-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, TraceData } from '@perses-dev/spec';\nimport type { QueryKey, UseQueryResult } from '@tanstack/react-query';\nimport { useQueries } from '@tanstack/react-query';\n\nimport type { TraceQueryContext, TraceQueryPlugin } from '../model';\nimport { useDatasourceStore } from './datasources';\nimport { usePluginRegistry, usePlugins } from './plugin-registry';\nimport { useTimeRange } from './TimeRangeProvider';\nimport { filterVariableStateMap, getVariableValuesKey } from './utils';\nimport { useAllVariableValues } from './variables';\nexport type TraceQueryDefinition<PluginSpec = UnknownSpec> = QueryDefinition<'TraceQuery', PluginSpec>;\nexport const TRACE_QUERY_KEY = 'TraceQuery';\n\n/**\n * Run a trace query using a TraceQuery plugin and return the results\n * @param definitions: dashboard defintion for a trace query, written in Trace Query Language (TraceQL)\n * Documentation for TraceQL: https://grafana.com/docs/tempo/latest/traceql/\n */\nexport function useTraceQueries(definitions: TraceQueryDefinition[]): Array<UseQueryResult<TraceData>> {\n const { getPlugin } = usePluginRegistry();\n const context = useTraceQueryContext();\n\n const pluginLoaderResponse = usePlugins(\n 'TraceQuery',\n definitions.map((d) => ({ kind: d.spec.plugin.kind })),\n );\n\n // useQueries() handles data fetching from query plugins (e.g. traceQL queries, promQL queries)\n // https://tanstack.com/query/v4/docs/react/reference/useQuery\n return useQueries({\n queries: definitions.map((definition, idx) => {\n const plugin = pluginLoaderResponse[idx]?.data;\n const { queryEnabled, queryKey } = getQueryOptions({ context, definition, plugin });\n const traceQueryKind = definition?.spec?.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<TraceData> => {\n const plugin = await getPlugin({ kind: TRACE_QUERY_KEY, name: traceQueryKind });\n const data = await plugin.getTraceData(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?: TraceQueryPlugin;\n definition: TraceQueryDefinition;\n context: TraceQueryContext;\n}): {\n queryKey: QueryKey;\n queryEnabled: boolean;\n} {\n const { variableState, absoluteTimeRange } = 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 const queryKey = ['query', TRACE_QUERY_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\nfunction useTraceQueryContext(): TraceQueryContext {\n const { absoluteTimeRange } = useTimeRange();\n const variableState = useAllVariableValues();\n const datasourceStore = useDatasourceStore();\n\n return {\n variableState,\n datasourceStore,\n absoluteTimeRange,\n };\n}\n"],"names":["useQueries","useDatasourceStore","usePluginRegistry","usePlugins","useTimeRange","filterVariableStateMap","getVariableValuesKey","useAllVariableValues","TRACE_QUERY_KEY","useTraceQueries","definitions","getPlugin","context","useTraceQueryContext","pluginLoaderResponse","map","d","kind","spec","plugin","queries","definition","idx","data","queryEnabled","queryKey","getQueryOptions","traceQueryKind","enabled","refetchOnMount","refetchOnWindowFocus","refetchOnReconnect","staleTime","Infinity","queryFn","signal","name","getTraceData","variableState","absoluteTimeRange","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,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,EAAEC,UAAU,QAAQ,uBAAoB;AAClE,SAASC,YAAY,QAAQ,+BAAsB;AACnD,SAASC,sBAAsB,EAAEC,oBAAoB,QAAQ,aAAU;AACvE,SAASC,oBAAoB,QAAQ,iBAAc;AAEnD,OAAO,MAAMC,kBAAkB,aAAa;AAE5C;;;;CAIC,GACD,OAAO,SAASC,gBAAgBC,WAAmC;IACjE,MAAM,EAAEC,SAAS,EAAE,GAAGT;IACtB,MAAMU,UAAUC;IAEhB,MAAMC,uBAAuBX,WAC3B,cACAO,YAAYK,GAAG,CAAC,CAACC,IAAO,CAAA;YAAEC,MAAMD,EAAEE,IAAI,CAACC,MAAM,CAACF,IAAI;QAAC,C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Aa,CAACJ;IAC9C,OAAO;QACLrB;QACAD;IACF;AACF;AAEA,SAASX;IACP,MAAM,EAAE0B,iBAAiB,EAAE,GAAGnC;IAC9B,MAAMkC,gBAAgB/B;IACtB,MAAM4C,kBAAkBlD;IAExB,OAAO;QACLqC;QACAa;QACAZ;IACF;AACF"}
1
+ {"version":3,"sources":["../../src/runtime/trace-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, TraceData } from '@perses-dev/spec';\nimport type { QueryKey, UseQueryResult } from '@tanstack/react-query';\nimport { useQueries } from '@tanstack/react-query';\n\nimport type { TraceQueryContext, TraceQueryPlugin } from '../model';\nimport { useDatasourceStore } from './datasources';\nimport { usePluginRegistry, usePlugins } from './plugin-registry';\nimport { useTimeRange } from './TimeRangeProvider';\nimport { filterVariableStateMap, getVariableValuesKey } from './utils';\nimport { useAllVariableValues } from './variables';\nexport type TraceQueryDefinition<PluginSpec = UnknownSpec> = QueryDefinition<'TraceQuery', PluginSpec>;\nexport const TRACE_QUERY_KEY = 'TraceQuery';\n\n/**\n * Run a trace query using a TraceQuery plugin and return the results\n * @param definitions: dashboard defintion for a trace query, written in Trace Query Language (TraceQL)\n * Documentation for TraceQL: https://grafana.com/docs/tempo/latest/traceql/\n */\nexport function useTraceQueries(definitions: TraceQueryDefinition[]): Array<UseQueryResult<TraceData>> {\n const { getPlugin } = usePluginRegistry();\n const context = useTraceQueryContext();\n\n const pluginLoaderResponse = usePlugins(\n 'TraceQuery',\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 // useQueries() handles data fetching from query plugins (e.g. traceQL queries, promQL queries)\n // https://tanstack.com/query/v4/docs/react/reference/useQuery\n return useQueries({\n queries: definitions.map((definition, idx) => {\n const plugin = pluginLoaderResponse[idx]?.data;\n const { queryEnabled, queryKey } = getQueryOptions({ context, definition, plugin });\n const traceQueryKind = definition?.spec?.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<TraceData> => {\n const plugin = await getPlugin({\n kind: TRACE_QUERY_KEY,\n name: traceQueryKind,\n version: definition.spec.plugin.metadata?.version,\n registry: definition.spec.plugin.metadata?.registry,\n });\n const data = await plugin.getTraceData(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?: TraceQueryPlugin;\n definition: TraceQueryDefinition;\n context: TraceQueryContext;\n}): {\n queryKey: QueryKey;\n queryEnabled: boolean;\n} {\n const { variableState, absoluteTimeRange } = 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 const queryKey = ['query', TRACE_QUERY_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\nfunction useTraceQueryContext(): TraceQueryContext {\n const { absoluteTimeRange } = useTimeRange();\n const variableState = useAllVariableValues();\n const datasourceStore = useDatasourceStore();\n\n return {\n variableState,\n datasourceStore,\n absoluteTimeRange,\n };\n}\n"],"names":["useQueries","useDatasourceStore","usePluginRegistry","usePlugins","useTimeRange","filterVariableStateMap","getVariableValuesKey","useAllVariableValues","TRACE_QUERY_KEY","useTraceQueries","definitions","getPlugin","context","useTraceQueryContext","pluginLoaderResponse","map","d","kind","spec","plugin","version","metadata","registry","queries","definition","idx","data","queryEnabled","queryKey","getQueryOptions","traceQueryKind","enabled","refetchOnMount","refetchOnWindowFocus","refetchOnReconnect","staleTime","Infinity","queryFn","signal","name","getTraceData","variableState","absoluteTimeRange","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,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,EAAEC,UAAU,QAAQ,uBAAoB;AAClE,SAASC,YAAY,QAAQ,+BAAsB;AACnD,SAASC,sBAAsB,EAAEC,oBAAoB,QAAQ,aAAU;AACvE,SAASC,oBAAoB,QAAQ,iBAAc;AAEnD,OAAO,MAAMC,kBAAkB,aAAa;AAE5C;;;;CAIC,GACD,OAAO,SAASC,gBAAgBC,WAAmC;IACjE,MAAM,EAAEC,SAAS,EAAE,GAAGT;IACtB,MAAMU,UAAUC;IAEhB,MAAMC,uBAAuBX,WAC3B,cACAO,YAAYK,GAAG,CAAC,CAACC,IAAO,CAAA;YACtBC,MAAMD,EAAEE,IAAI,CAACC,MAAM,CAACF,IAAI;YACxBG,SAASJ,EAAEE,IAAI,CAACC,MAAM,CAACE,QAAQ,EAAED;YACjCE,UAAUN,EAAEE,IAAI,CAACC,MAAM,CAACE,QAAQ,EAAE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,sBAAsB;QACxBI,aAAaJ,qBAAqBK,IAAI,CAAC,CAACC,IAAMV,aAAa,CAACU,EAAE,EAAEC;IAClE;IAEA,MAAMzB,eAAeR,WAAWkC,aAAa,CAACJ;IAC9C,OAAO;QACLrB;QACAD;IACF;AACF;AAEA,SAASd;IACP,MAAM,EAAE6B,iBAAiB,EAAE,GAAGtC;IAC9B,MAAMqC,gBAAgBlC;IACtB,MAAM+C,kBAAkBrD;IAExB,OAAO;QACLwC;QACAa;QACAZ;IACF;AACF"}
@@ -58,4 +58,10 @@ export declare function useVariableValues(names?: string[]): VariableStateMap;
58
58
  export declare function useAllVariableValues(names?: string[]): VariableStateMap;
59
59
  export declare function replaceVariablesInString(text: string, variableValues: VariableStateMap, extraVariables?: Record<string, string>): string;
60
60
  export declare function useReplaceVariablesInString(str: string | undefined): string | undefined;
61
+ /**
62
+ * Convenience hook for replacing variables in a URL, including those nested
63
+ * inside percent-encoded query parameters (e.g. Explore `data=%24var`).
64
+ * Prefer this over {@link useReplaceVariablesInString} for link hrefs.
65
+ */
66
+ export declare function useReplaceVariablesInUrl(url: string | undefined): string | undefined;
61
67
  //# sourceMappingURL=variables.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"variables.d.ts","sourceRoot":"","sources":["../../src/runtime/variables.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE9F,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAMlC,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,gBAAgB,EAAE,CAAC;AAEhE;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;GAEG;AACH,qBAAa,qBAAqB;IAChC;;;OAGG;IACH,CAAC,SAAS,CAAC,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AAG,MAAM,GAAG,SAAS,CAKvF;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAQpF"}
@@ -10,7 +10,7 @@
10
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
- import { parseVariables, replaceVariables } from "@perses-dev/components";
13
+ import { parseVariables, replaceVariables, replaceVariablesInUrl } from "@perses-dev/components";
14
14
  import { immerable } from "immer";
15
15
  import { createContext, useContext, useMemo } from "react";
16
16
  import { useBuiltinVariableValues } from "./builtin-variables.js";
@@ -133,5 +133,21 @@ export function useReplaceVariablesInString(str) {
133
133
  if (!str) return undefined;
134
134
  return replaceVariables(str, variableValues);
135
135
  }
136
+ /**
137
+ * Convenience hook for replacing variables in a URL, including those nested
138
+ * inside percent-encoded query parameters (e.g. Explore `data=%24var`).
139
+ * Prefer this over {@link useReplaceVariablesInString} for link hrefs.
140
+ */ export function useReplaceVariablesInUrl(url) {
141
+ const variableValues = useAllVariableValues();
142
+ return useMemo(()=>{
143
+ if (url === undefined || url === '') {
144
+ return url;
145
+ }
146
+ return replaceVariablesInUrl(url, variableValues);
147
+ }, [
148
+ url,
149
+ variableValues
150
+ ]);
151
+ }
136
152
 
137
153
  //# sourceMappingURL=variables.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/runtime/variables.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 { VariableOption, VariableState, VariableStateMap } from '@perses-dev/components';\nimport { parseVariables, replaceVariables } from '@perses-dev/components';\nimport { immerable } from 'immer';\nimport { createContext, useContext, useMemo } from 'react';\n\nimport { useBuiltinVariableValues } from './builtin-variables';\n\n// Re-export types from @perses-dev/components for backwards compatibility\nexport type { VariableOption, VariableState, VariableStateMap };\n\n/**\n * Structure used as key in the {@link VariableStoreStateMap}.\n */\nexport type VariableStateKey = {\n /**\n * name of the variable we want to access in the state.\n */\n name: string;\n /**\n * source of the variable we want to access in the state.\n * Defined only for external variables.\n */\n source?: string;\n};\n\n/**\n * A state map with two entry keys, materialized by {@link VariableStateKey} structure.\n */\nexport class VariableStoreStateMap {\n /**\n * \"Immerable\" is mandatory to be able to use this class in an immer context.\n * Ref: https://docs.pmnd.rs/zustand/integrations/immer-middleware#gotchas\n */\n [immerable] = true;\n\n private readonly DEFAULT_LOCAL_SOURCE_NAME = '';\n private readonly _state: Record<string, Record<string, VariableState>> = {};\n\n /**\n * Get variable state by key.\n * @param key\n */\n get(key: VariableStateKey): VariableState | undefined {\n return this._sourceStatesOrEmpty(key.source)[key.name];\n }\n\n /**\n * Set variable state by key.\n * @param key\n * @param value\n */\n set(key: VariableStateKey, value: VariableState): VariableState | undefined {\n const sourceName = this._sourceName(key.source);\n if (!this._state[sourceName]) {\n this._state[sourceName] = {};\n }\n this._sourceStatesOrEmpty(key.source)[key.name] = value;\n return value;\n }\n\n /**\n * Check presence of variable state by key.\n * @param key\n */\n has(key: VariableStateKey): boolean {\n return this._sourceStatesOrEmpty(key.source)[key.name] !== undefined;\n }\n\n /**\n * Delete variable state by key.\n * @param key\n */\n delete(key: VariableStateKey): boolean {\n const result = this.has(key);\n const sourceName = this._sourceName(key.source);\n const sourceStates = this._state[sourceName];\n\n // Delete var from source state\n if (sourceStates) {\n delete sourceStates[key.name];\n }\n\n // Delete source state from state if empty\n if (Object.keys(sourceStates ?? {})?.length === 0) {\n delete this._state[sourceName];\n }\n return result;\n }\n\n private _sourceName(source: string | undefined): string {\n return source ?? this.DEFAULT_LOCAL_SOURCE_NAME;\n }\n\n private _sourceStatesOrEmpty(source: string | undefined): Record<string, VariableState> {\n return this._state[this._sourceName(source)] ?? {};\n }\n}\n\nexport type VariableSrv = {\n state: VariableStateMap;\n};\n\nexport const VariableContext = createContext<VariableSrv | undefined>(undefined);\n\nfunction useVariableContext(): VariableSrv {\n const ctx = useContext(VariableContext);\n if (ctx === undefined) {\n throw new Error('No VariableContext found. Did you forget a Provider?');\n }\n return ctx;\n}\n\nexport function useVariableValues(names?: string[]): VariableStateMap {\n const { state } = useVariableContext();\n\n const values = useMemo(() => {\n const values: VariableStateMap = {};\n names?.forEach((name) => {\n const s = state[name];\n if (s) {\n values[name] = s;\n }\n });\n return values;\n }, [state, names]);\n\n if (names === undefined) {\n return state;\n }\n\n return values;\n}\n\n// useAllVariableValues wraps user-defined variables with built-in variables\nexport function useAllVariableValues(names?: string[]): VariableStateMap {\n const variableValues = useVariableValues(names);\n const builtinVariableValues = useBuiltinVariableValues(names);\n\n return useMemo(() => {\n return { ...variableValues, ...builtinVariableValues } as VariableStateMap;\n }, [variableValues, builtinVariableValues]);\n}\n\n// Simple wrapper around replaceVariables() with support for extra string variables.\nexport function replaceVariablesInString(\n text: string,\n variableValues: VariableStateMap,\n extraVariables?: Record<string, string>,\n): string {\n const vars = { ...variableValues }; // shallow clone to avoid modifying the original object\n for (const [key, value] of Object.entries(extraVariables ?? {})) {\n vars[key] = { value, loading: false };\n }\n return replaceVariables(text, vars);\n}\n\n// Convenience hook for replacing variables in a string\nexport function useReplaceVariablesInString(str: string | undefined): string | undefined {\n const variablesInString = str ? parseVariables(str) : [];\n const variableValues = useAllVariableValues(variablesInString);\n if (!str) return undefined;\n return replaceVariables(str, variableValues);\n}\n"],"names":["parseVariables","replaceVariables","immerable","createContext","useContext","useMemo","useBuiltinVariableValues","VariableStoreStateMap","DEFAULT_LOCAL_SOURCE_NAME","_state","get","key","_sourceStatesOrEmpty","source","name","set","value","sourceName","_sourceName","has","undefined","delete","result","sourceStates","Object","keys","length","VariableContext","useVariableContext","ctx","Error","useVariableValues","names","state","values","forEach","s","useAllVariableValues","variableValues","builtinVariableValues","replaceVariablesInString","text","extraVariables","vars","entries","loading","useReplaceVariablesInString","str","variablesInString"],"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;AAGjC,SAASA,cAAc,EAAEC,gBAAgB,QAAQ,yBAAyB;AAC1E,SAASC,SAAS,QAAQ,QAAQ;AAClC,SAASC,aAAa,EAAEC,UAAU,EAAEC,OAAO,QAAQ,QAAQ;AAE3D,SAASC,wBAAwB,QAAQ,yBAAsB;AAoB/D;;CAEC,GACD,OAAO,MAAMC;IACX;;;GAGC,GACD,CAACL,UAAU,GAAG,KAAK;IAEFM,4BAA4B,GAAG;IAC/BC,SAAwD,CAAC,EAAE;IAE5E;;;GAGC,GACDC,IAAIC,GAAqB,EAA6B;QACpD,OAAO,IAAI,CAACC,oBAAoB,CAACD,IAAIE,MAAM,CAAC,CAACF,IAAIG,IAAI,CAAC;IACxD;IAEA;;;;GAIC,GACDC,IAAIJ,GAAqB,EAAEK,KAAoB,EAA6B;QAC1E,MAAMC,aAAa,IAAI,CAACC,WAAW,CAACP,IAAIE,MAAM;QAC9C,IAAI,CAAC,IAAI,CAACJ,MAAM,CAACQ,WAAW,EAAE;YAC5B,IAAI,CAACR,MAAM,CAACQ,WAAW,GAAG,CAAC;QAC7B;QACA,IAAI,CAACL,oBAAoB,CAACD,IAAIE,MAAM,CAAC,CAACF,IAAIG,IAAI,CAAC,GAAGE;QAClD,OAAOA;IACT;IAEA;;;GAGC,GACDG,IAAIR,GAAqB,EAAW;QAClC,OAAO,IAAI,CAACC,oBAAoB,CAACD,IAAIE,MAAM,CAAC,CAACF,IAAIG,IAAI,CAAC,KAAKM;IAC7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AAiBP,kBAAkBC;IACzC,MAAMO,wBAAwBjC,yBAAyB0B;IAEvD,OAAO3B,QAAQ;QACb,OAAO;YAAE,GAAGiC,cAAc;YAAE,GAAGC,qBAAqB;QAAC;IACvD,GAAG;QAACD;QAAgBC;KAAsB;AAC5C;AAEA,oFAAoF;AACpF,OAAO,SAASC,yBACdC,IAAY,EACZH,cAAgC,EAChCI,cAAuC;IAEvC,MAAMC,OAAO;QAAE,GAAGL,cAAc;IAAC,GAAG,uDAAuD;IAC3F,KAAK,MAAM,CAAC3B,KAAKK,MAAM,IAAIQ,OAAOoB,OAAO,CAACF,kBAAkB,CAAC,GAAI;QAC/DC,IAAI,CAAChC,IAAI,GAAG;YAAEK;YAAO6B,SAAS;QAAM;IACtC;IACA,OAAO5C,iBAAiBwC,MAAME;AAChC;AAEA,uDAAuD;AACvD,OAAO,SAASG,4BAA4BC,GAAuB;IACjE,MAAMC,oBAAoBD,MAAM/C,eAAe+C,OAAO,EAAE;IACxD,MAAMT,iBAAiBD,qBAAqBW;IAC5C,IAAI,CAACD,KAAK,OAAO3B;IACjB,OAAOnB,iBAAiB8C,KAAKT;AAC/B"}
1
+ {"version":3,"sources":["../../src/runtime/variables.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 { VariableOption, VariableState, VariableStateMap } from '@perses-dev/components';\nimport { parseVariables, replaceVariables, replaceVariablesInUrl } from '@perses-dev/components';\nimport { immerable } from 'immer';\nimport { createContext, useContext, useMemo } from 'react';\n\nimport { useBuiltinVariableValues } from './builtin-variables';\n\n// Re-export types from @perses-dev/components for backwards compatibility\nexport type { VariableOption, VariableState, VariableStateMap };\n\n/**\n * Structure used as key in the {@link VariableStoreStateMap}.\n */\nexport type VariableStateKey = {\n /**\n * name of the variable we want to access in the state.\n */\n name: string;\n /**\n * source of the variable we want to access in the state.\n * Defined only for external variables.\n */\n source?: string;\n};\n\n/**\n * A state map with two entry keys, materialized by {@link VariableStateKey} structure.\n */\nexport class VariableStoreStateMap {\n /**\n * \"Immerable\" is mandatory to be able to use this class in an immer context.\n * Ref: https://docs.pmnd.rs/zustand/integrations/immer-middleware#gotchas\n */\n [immerable] = true;\n\n private readonly DEFAULT_LOCAL_SOURCE_NAME = '';\n private readonly _state: Record<string, Record<string, VariableState>> = {};\n\n /**\n * Get variable state by key.\n * @param key\n */\n get(key: VariableStateKey): VariableState | undefined {\n return this._sourceStatesOrEmpty(key.source)[key.name];\n }\n\n /**\n * Set variable state by key.\n * @param key\n * @param value\n */\n set(key: VariableStateKey, value: VariableState): VariableState | undefined {\n const sourceName = this._sourceName(key.source);\n if (!this._state[sourceName]) {\n this._state[sourceName] = {};\n }\n this._sourceStatesOrEmpty(key.source)[key.name] = value;\n return value;\n }\n\n /**\n * Check presence of variable state by key.\n * @param key\n */\n has(key: VariableStateKey): boolean {\n return this._sourceStatesOrEmpty(key.source)[key.name] !== undefined;\n }\n\n /**\n * Delete variable state by key.\n * @param key\n */\n delete(key: VariableStateKey): boolean {\n const result = this.has(key);\n const sourceName = this._sourceName(key.source);\n const sourceStates = this._state[sourceName];\n\n // Delete var from source state\n if (sourceStates) {\n delete sourceStates[key.name];\n }\n\n // Delete source state from state if empty\n if (Object.keys(sourceStates ?? {})?.length === 0) {\n delete this._state[sourceName];\n }\n return result;\n }\n\n private _sourceName(source: string | undefined): string {\n return source ?? this.DEFAULT_LOCAL_SOURCE_NAME;\n }\n\n private _sourceStatesOrEmpty(source: string | undefined): Record<string, VariableState> {\n return this._state[this._sourceName(source)] ?? {};\n }\n}\n\nexport type VariableSrv = {\n state: VariableStateMap;\n};\n\nexport const VariableContext = createContext<VariableSrv | undefined>(undefined);\n\nfunction useVariableContext(): VariableSrv {\n const ctx = useContext(VariableContext);\n if (ctx === undefined) {\n throw new Error('No VariableContext found. Did you forget a Provider?');\n }\n return ctx;\n}\n\nexport function useVariableValues(names?: string[]): VariableStateMap {\n const { state } = useVariableContext();\n\n const values = useMemo(() => {\n const values: VariableStateMap = {};\n names?.forEach((name) => {\n const s = state[name];\n if (s) {\n values[name] = s;\n }\n });\n return values;\n }, [state, names]);\n\n if (names === undefined) {\n return state;\n }\n\n return values;\n}\n\n// useAllVariableValues wraps user-defined variables with built-in variables\nexport function useAllVariableValues(names?: string[]): VariableStateMap {\n const variableValues = useVariableValues(names);\n const builtinVariableValues = useBuiltinVariableValues(names);\n\n return useMemo(() => {\n return { ...variableValues, ...builtinVariableValues } as VariableStateMap;\n }, [variableValues, builtinVariableValues]);\n}\n\n// Simple wrapper around replaceVariables() with support for extra string variables.\nexport function replaceVariablesInString(\n text: string,\n variableValues: VariableStateMap,\n extraVariables?: Record<string, string>,\n): string {\n const vars = { ...variableValues }; // shallow clone to avoid modifying the original object\n for (const [key, value] of Object.entries(extraVariables ?? {})) {\n vars[key] = { value, loading: false };\n }\n return replaceVariables(text, vars);\n}\n\n// Convenience hook for replacing variables in a string\nexport function useReplaceVariablesInString(str: string | undefined): string | undefined {\n const variablesInString = str ? parseVariables(str) : [];\n const variableValues = useAllVariableValues(variablesInString);\n if (!str) return undefined;\n return replaceVariables(str, variableValues);\n}\n\n/**\n * Convenience hook for replacing variables in a URL, including those nested\n * inside percent-encoded query parameters (e.g. Explore `data=%24var`).\n * Prefer this over {@link useReplaceVariablesInString} for link hrefs.\n */\nexport function useReplaceVariablesInUrl(url: string | undefined): string | undefined {\n const variableValues = useAllVariableValues();\n return useMemo(() => {\n if (url === undefined || url === '') {\n return url;\n }\n return replaceVariablesInUrl(url, variableValues);\n }, [url, variableValues]);\n}\n"],"names":["parseVariables","replaceVariables","replaceVariablesInUrl","immerable","createContext","useContext","useMemo","useBuiltinVariableValues","VariableStoreStateMap","DEFAULT_LOCAL_SOURCE_NAME","_state","get","key","_sourceStatesOrEmpty","source","name","set","value","sourceName","_sourceName","has","undefined","delete","result","sourceStates","Object","keys","length","VariableContext","useVariableContext","ctx","Error","useVariableValues","names","state","values","forEach","s","useAllVariableValues","variableValues","builtinVariableValues","replaceVariablesInString","text","extraVariables","vars","entries","loading","useReplaceVariablesInString","str","variablesInString","useReplaceVariablesInUrl","url"],"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;AAGjC,SAASA,cAAc,EAAEC,gBAAgB,EAAEC,qBAAqB,QAAQ,yBAAyB;AACjG,SAASC,SAAS,QAAQ,QAAQ;AAClC,SAASC,aAAa,EAAEC,UAAU,EAAEC,OAAO,QAAQ,QAAQ;AAE3D,SAASC,wBAAwB,QAAQ,yBAAsB;AAoB/D;;CAEC,GACD,OAAO,MAAMC;IACX;;;GAGC,GACD,CAACL,UAAU,GAAG,KAAK;IAEFM,4BAA4B,GAAG;IAC/BC,SAAwD,CAAC,EAAE;IAE5E;;;GAGC,GACDC,IAAIC,GAAqB,EAA6B;QACpD,OAAO,IAAI,CAACC,oBAAoB,CAACD,IAAIE,MAAM,CAAC,CAACF,IAAIG,IAAI,CAAC;IACxD;IAEA;;;;GAIC,GACDC,IAAIJ,GAAqB,EAAEK,KAAoB,EAA6B;QAC1E,MAAMC,aAAa,IAAI,CAACC,WAAW,CAACP,IAAIE,MAAM;QAC9C,IAAI,CAAC,IAAI,CAACJ,MAAM,CAACQ,WAAW,EAAE;YAC5B,IAAI,CAACR,MAAM,CAACQ,WAAW,GAAG,CAAC;QAC7B;QACA,IAAI,CAACL,oBAAoB,CAACD,IAAIE,MAAM,CAAC,CAACF,IAAIG,IAAI,CAAC,GAAGE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AAG;QAACD;QAAOD;KAAM;IAEjB,IAAIA,UAAUZ,WAAW;QACvB,OAAOa;IACT;IAEA,OAAOC;AACT;AAEA,4EAA4E;AAC5E,OAAO,SAASG,qBAAqBL,KAAgB;IACnD,MAAMM,iBAAiBP,kBAAkBC;IACzC,MAAMO,wBAAwBjC,yBAAyB0B;IAEvD,OAAO3B,QAAQ;QACb,OAAO;YAAE,GAAGiC,cAAc;YAAE,GAAGC,qBAAqB;QAAC;IACvD,GAAG;QAACD;QAAgBC;KAAsB;AAC5C;AAEA,oFAAoF;AACpF,OAAO,SAASC,yBACdC,IAAY,EACZH,cAAgC,EAChCI,cAAuC;IAEvC,MAAMC,OAAO;QAAE,GAAGL,cAAc;IAAC,GAAG,uDAAuD;IAC3F,KAAK,MAAM,CAAC3B,KAAKK,MAAM,IAAIQ,OAAOoB,OAAO,CAACF,kBAAkB,CAAC,GAAI;QAC/DC,IAAI,CAAChC,IAAI,GAAG;YAAEK;YAAO6B,SAAS;QAAM;IACtC;IACA,OAAO7C,iBAAiByC,MAAME;AAChC;AAEA,uDAAuD;AACvD,OAAO,SAASG,4BAA4BC,GAAuB;IACjE,MAAMC,oBAAoBD,MAAMhD,eAAegD,OAAO,EAAE;IACxD,MAAMT,iBAAiBD,qBAAqBW;IAC5C,IAAI,CAACD,KAAK,OAAO3B;IACjB,OAAOpB,iBAAiB+C,KAAKT;AAC/B;AAEA;;;;CAIC,GACD,OAAO,SAASW,yBAAyBC,GAAuB;IAC9D,MAAMZ,iBAAiBD;IACvB,OAAOhC,QAAQ;QACb,IAAI6C,QAAQ9B,aAAa8B,QAAQ,IAAI;YACnC,OAAOA;QACT;QACA,OAAOjD,sBAAsBiD,KAAKZ;IACpC,GAAG;QAACY;QAAKZ;KAAe;AAC1B"}
@@ -1,4 +1,5 @@
1
1
  export * from './event';
2
+ export * from './plugin-versions';
2
3
  export * from './variables';
3
4
  export * from './csv-export';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAaA,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAaA,cAAc,SAAS,CAAC;AACxB,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC"}
@@ -11,6 +11,7 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
  export * from "./event.js";
14
+ export * from "./plugin-versions.js";
14
15
  export * from "./variables.js";
15
16
  export * from "./csv-export.js";
16
17
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/index.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\nexport * from './event';\nexport * from './variables';\nexport * from './csv-export';\n"],"names":[],"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,cAAc,aAAU;AACxB,cAAc,iBAAc;AAC5B,cAAc,kBAAe"}
1
+ {"version":3,"sources":["../../src/utils/index.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\nexport * from './event';\nexport * from './plugin-versions';\nexport * from './variables';\nexport * from './csv-export';\n"],"names":[],"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,cAAc,aAAU;AACxB,cAAc,uBAAoB;AAClC,cAAc,iBAAc;AAC5B,cAAc,kBAAe"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Sentinel version meaning "the latest version available in the Perses instance". It mirrors the backend
3
+ * `plugin.LatestVersion` constant. A plugin definition using it is not pinned to an exact version: the plugin registry
4
+ * resolves it dynamically at load time.
5
+ */
6
+ export declare const LATEST_PLUGIN_VERSION = "latest";
7
+ /**
8
+ * Compare two plugin version strings with semver semantics, the same way the Perses backend orders plugin versions.
9
+ * Returns a positive number when `a` is greater than `b`, a negative number when it is lower, and 0 when they are equal.
10
+ *
11
+ * Pre-releases order below their stable release (`1.0.0-beta` < `1.0.0`), as semver mandates. Versions that cannot be
12
+ * parsed at all always order below parseable ones, and are compared lexicographically between themselves, so an
13
+ * unexpected value can never be picked as "the latest version".
14
+ */
15
+ export declare function comparePluginVersions(a: string, b: string): number;
16
+ /** Return a new array of versions sorted from newest to oldest, using {@link comparePluginVersions}. */
17
+ export declare function sortPluginVersionsDesc(versions: string[]): string[];
18
+ //# sourceMappingURL=plugin-versions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-versions.d.ts","sourceRoot":"","sources":["../../src/utils/plugin-versions.ts"],"names":[],"mappings":"AAgBA;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,WAAW,CAAC;AAU9C;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAalE;AAED,wGAAwG;AACxG,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAEnE"}
@@ -0,0 +1,52 @@
1
+ // Copyright 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 { coerce, compare, parse } from "semver";
14
+ /**
15
+ * Sentinel version meaning "the latest version available in the Perses instance". It mirrors the backend
16
+ * `plugin.LatestVersion` constant. A plugin definition using it is not pinned to an exact version: the plugin registry
17
+ * resolves it dynamically at load time.
18
+ */ export const LATEST_PLUGIN_VERSION = 'latest';
19
+ /**
20
+ * Parse a plugin version with semver, tolerating the loose forms the backend also accepts (a leading `v`, a missing
21
+ * patch segment, ...). Returns `null` when the value cannot be understood as a version at all.
22
+ */ function parsePluginVersion(version) {
23
+ return parse(version, {
24
+ loose: true
25
+ }) ?? coerce(version);
26
+ }
27
+ /**
28
+ * Compare two plugin version strings with semver semantics, the same way the Perses backend orders plugin versions.
29
+ * Returns a positive number when `a` is greater than `b`, a negative number when it is lower, and 0 when they are equal.
30
+ *
31
+ * Pre-releases order below their stable release (`1.0.0-beta` < `1.0.0`), as semver mandates. Versions that cannot be
32
+ * parsed at all always order below parseable ones, and are compared lexicographically between themselves, so an
33
+ * unexpected value can never be picked as "the latest version".
34
+ */ export function comparePluginVersions(a, b) {
35
+ const parsedA = parsePluginVersion(a);
36
+ const parsedB = parsePluginVersion(b);
37
+ if (parsedA && parsedB) {
38
+ return compare(parsedA, parsedB);
39
+ }
40
+ if (parsedA) {
41
+ return 1;
42
+ }
43
+ if (parsedB) {
44
+ return -1;
45
+ }
46
+ return a.localeCompare(b);
47
+ }
48
+ /** Return a new array of versions sorted from newest to oldest, using {@link comparePluginVersions}. */ export function sortPluginVersionsDesc(versions) {
49
+ return versions.toSorted((a, b)=>comparePluginVersions(b, a));
50
+ }
51
+
52
+ //# sourceMappingURL=plugin-versions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/plugin-versions.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 { SemVer } from 'semver';\nimport { coerce, compare, parse } from 'semver';\n\n/**\n * Sentinel version meaning \"the latest version available in the Perses instance\". It mirrors the backend\n * `plugin.LatestVersion` constant. A plugin definition using it is not pinned to an exact version: the plugin registry\n * resolves it dynamically at load time.\n */\nexport const LATEST_PLUGIN_VERSION = 'latest';\n\n/**\n * Parse a plugin version with semver, tolerating the loose forms the backend also accepts (a leading `v`, a missing\n * patch segment, ...). Returns `null` when the value cannot be understood as a version at all.\n */\nfunction parsePluginVersion(version: string): SemVer | null {\n return parse(version, { loose: true }) ?? coerce(version);\n}\n\n/**\n * Compare two plugin version strings with semver semantics, the same way the Perses backend orders plugin versions.\n * Returns a positive number when `a` is greater than `b`, a negative number when it is lower, and 0 when they are equal.\n *\n * Pre-releases order below their stable release (`1.0.0-beta` < `1.0.0`), as semver mandates. Versions that cannot be\n * parsed at all always order below parseable ones, and are compared lexicographically between themselves, so an\n * unexpected value can never be picked as \"the latest version\".\n */\nexport function comparePluginVersions(a: string, b: string): number {\n const parsedA = parsePluginVersion(a);\n const parsedB = parsePluginVersion(b);\n if (parsedA && parsedB) {\n return compare(parsedA, parsedB);\n }\n if (parsedA) {\n return 1;\n }\n if (parsedB) {\n return -1;\n }\n return a.localeCompare(b);\n}\n\n/** Return a new array of versions sorted from newest to oldest, using {@link comparePluginVersions}. */\nexport function sortPluginVersionsDesc(versions: string[]): string[] {\n return versions.toSorted((a, b) => comparePluginVersions(b, a));\n}\n"],"names":["coerce","compare","parse","LATEST_PLUGIN_VERSION","parsePluginVersion","version","loose","comparePluginVersions","a","b","parsedA","parsedB","localeCompare","sortPluginVersionsDesc","versions","toSorted"],"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;AAGjC,SAASA,MAAM,EAAEC,OAAO,EAAEC,KAAK,QAAQ,SAAS;AAEhD;;;;CAIC,GACD,OAAO,MAAMC,wBAAwB,SAAS;AAE9C;;;CAGC,GACD,SAASC,mBAAmBC,OAAe;IACzC,OAAOH,MAAMG,SAAS;QAAEC,OAAO;IAAK,MAAMN,OAAOK;AACnD;AAEA;;;;;;;CAOC,GACD,OAAO,SAASE,sBAAsBC,CAAS,EAAEC,CAAS;IACxD,MAAMC,UAAUN,mBAAmBI;IACnC,MAAMG,UAAUP,mBAAmBK;IACnC,IAAIC,WAAWC,SAAS;QACtB,OAAOV,QAAQS,SAASC;IAC1B;IACA,IAAID,SAAS;QACX,OAAO;IACT;IACA,IAAIC,SAAS;QACX,OAAO,CAAC;IACV;IACA,OAAOH,EAAEI,aAAa,CAACH;AACzB;AAEA,sGAAsG,GACtG,OAAO,SAASI,uBAAuBC,QAAkB;IACvD,OAAOA,SAASC,QAAQ,CAAC,CAACP,GAAGC,IAAMF,sBAAsBE,GAAGD;AAC9D"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perses-dev/plugin-system",
3
- "version": "0.55.0-beta.10",
3
+ "version": "0.55.0-beta.12",
4
4
  "description": "The plugin feature in Pereses",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/perses/perses/blob/main/README.md",
@@ -29,12 +29,13 @@
29
29
  "lint:fix": "oxlint --fix src"
30
30
  },
31
31
  "dependencies": {
32
- "@module-federation/enhanced": "^2.8.0",
33
- "@perses-dev/client": "0.55.0-beta.10",
34
- "@perses-dev/components": "0.55.0-beta.10",
32
+ "@module-federation/enhanced": "^2.9.0",
33
+ "@perses-dev/client": "0.55.0-beta.12",
34
+ "@perses-dev/components": "0.55.0-beta.12",
35
35
  "@perses-dev/spec": "0.3.0-beta.8",
36
36
  "date-fns": "^4.1.0",
37
37
  "date-fns-tz": "^3.2.0",
38
+ "fast-uri": "3.1.6",
38
39
  "immer": "^10.1.1",
39
40
  "react-hook-form": "^7.87.0",
40
41
  "semver": "^7.8.0",