@grafana/plugin-compat 0.2.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +10 -2
  3. package/dist/cjs/apps.cjs +6 -0
  4. package/dist/cjs/apps.cjs.map +1 -1
  5. package/dist/cjs/datasources/getDataSourceInstance.cjs +3 -0
  6. package/dist/cjs/datasources/getDataSourceInstance.cjs.map +1 -1
  7. package/dist/cjs/datasources/getDataSourceInstanceList.cjs +3 -2
  8. package/dist/cjs/datasources/getDataSourceInstanceList.cjs.map +1 -1
  9. package/dist/cjs/datasources/getDataSourceInstanceSettings.cjs +3 -0
  10. package/dist/cjs/datasources/getDataSourceInstanceSettings.cjs.map +1 -1
  11. package/dist/cjs/datasources/getDefaultDataSourceInstanceListItem.cjs +10 -2
  12. package/dist/cjs/datasources/getDefaultDataSourceInstanceListItem.cjs.map +1 -1
  13. package/dist/cjs/datasources/registerRuntimeDataSourceInstance.cjs +23 -0
  14. package/dist/cjs/datasources/registerRuntimeDataSourceInstance.cjs.map +1 -0
  15. package/dist/cjs/datasources/useDataSourceInstance.cjs +30 -0
  16. package/dist/cjs/datasources/useDataSourceInstance.cjs.map +1 -0
  17. package/dist/cjs/datasources/useDefaultDataSourceInstanceListItem.cjs +5 -24
  18. package/dist/cjs/datasources/useDefaultDataSourceInstanceListItem.cjs.map +1 -1
  19. package/dist/cjs/datasources.cjs +4 -0
  20. package/dist/cjs/datasources.cjs.map +1 -1
  21. package/dist/esm/apps.mjs +8 -2
  22. package/dist/esm/apps.mjs.map +1 -1
  23. package/dist/esm/datasources/getDataSourceInstance.mjs +5 -2
  24. package/dist/esm/datasources/getDataSourceInstance.mjs.map +1 -1
  25. package/dist/esm/datasources/getDataSourceInstanceList.mjs +5 -4
  26. package/dist/esm/datasources/getDataSourceInstanceList.mjs.map +1 -1
  27. package/dist/esm/datasources/getDataSourceInstanceSettings.mjs +5 -2
  28. package/dist/esm/datasources/getDataSourceInstanceSettings.mjs.map +1 -1
  29. package/dist/esm/datasources/getDefaultDataSourceInstanceListItem.mjs +11 -4
  30. package/dist/esm/datasources/getDefaultDataSourceInstanceListItem.mjs.map +1 -1
  31. package/dist/esm/datasources/registerRuntimeDataSourceInstance.mjs +19 -0
  32. package/dist/esm/datasources/registerRuntimeDataSourceInstance.mjs.map +1 -0
  33. package/dist/esm/datasources/useDataSourceInstance.mjs +26 -0
  34. package/dist/esm/datasources/useDataSourceInstance.mjs.map +1 -0
  35. package/dist/esm/datasources/useDefaultDataSourceInstanceListItem.mjs +6 -25
  36. package/dist/esm/datasources/useDefaultDataSourceInstanceListItem.mjs.map +1 -1
  37. package/dist/esm/datasources.mjs +2 -0
  38. package/dist/esm/datasources.mjs.map +1 -1
  39. package/dist/types/datasources/getDefaultDataSourceInstanceListItem.d.ts +2 -1
  40. package/dist/types/datasources/registerRuntimeDataSourceInstance.d.ts +2 -0
  41. package/dist/types/datasources/useDataSourceInstance.d.ts +13 -0
  42. package/dist/types/datasources/useDefaultDataSourceInstanceListItem.d.ts +4 -4
  43. package/dist/types/datasources.d.ts +2 -0
  44. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ # 0.5.0 (2026-10-12)
2
+
3
+ `getPluginSettings` and `updateAppPluginSettings` now use the host's stable `@grafana/runtime` exports when available, then `@grafana/runtime/unstable`, then the legacy `getBackendSrv()` plugin-settings endpoints, so they keep working once the host removes them from `unstable`.
4
+
5
+ Add `useDataSourceInstance` to `@grafana/plugin-compat/datasources`. It uses the host's stable `@grafana/runtime` hook when available, then `@grafana/runtime/unstable`, then resolves through `getDataSourceInstance`, so it works on hosts without the async data source hooks.
6
+
7
+ # 0.4.0 (2026-10-09)
8
+
9
+ The data source functions now use the host's stable `@grafana/runtime` exports when available, then `@grafana/runtime/unstable`, then the legacy `getDataSourceSrv()` APIs, so they keep working on hosts that only expose the async APIs under `unstable`.
10
+
11
+ # 0.3.0 (2026-10-08)
12
+
13
+ Add `registerRuntimeDataSourceInstance` to `@grafana/plugin-compat/datasources`. It uses the host's async registry when available and falls back to `getDataSourceSrv().registerRuntimeDataSource` otherwise.
14
+
1
15
  # 0.2.0 (2026-09-23)
2
16
 
3
17
  Add a CommonJS build alongside the existing ESM build, so the package works with `require` as well as `import`.
package/README.md CHANGED
@@ -18,8 +18,9 @@ Ships both ESM and CommonJS builds, so it works with `import` and `require`.
18
18
  - `@grafana/plugin-compat/datasources` — `getDataSourceInstance`,
19
19
  `getDataSourceInstanceList`, `getDataSourceInstanceSettings`,
20
20
  `getDefaultDataSourceInstanceListItem` and its
21
- `useDefaultDataSourceInstanceListItem` hook. Replacements for
22
- `getDataSourceSrv()` methods.
21
+ `useDefaultDataSourceInstanceListItem` hook, and
22
+ `registerRuntimeDataSourceInstance`. Replacements for `getDataSourceSrv()`
23
+ methods.
23
24
  - `@grafana/plugin-compat/apps` — `getPluginSettings`,
24
25
  `updateAppPluginSettings`. Replacements for the `getBackendSrv()`
25
26
  plugin-settings endpoints.
@@ -31,6 +32,7 @@ import {
31
32
  getDataSourceInstance,
32
33
  getDataSourceInstanceList,
33
34
  getDefaultDataSourceInstanceListItem,
35
+ registerRuntimeDataSourceInstance,
34
36
  useDefaultDataSourceInstanceListItem,
35
37
  } from '@grafana/plugin-compat/datasources';
36
38
  import { getPluginSettings } from '@grafana/plugin-compat/apps';
@@ -43,4 +45,10 @@ const items = await getDataSourceInstanceList({ type: 'prometheus' });
43
45
  const defaultProm = await getDefaultDataSourceInstanceListItem(items);
44
46
 
45
47
  const { isLoading, error, item } = useDefaultDataSourceInstanceListItem(items);
48
+
49
+ // Throws if a data source with the same uid is already registered.
50
+ registerRuntimeDataSourceInstance({ dataSource: new MyRuntimeDataSource('my-plugin-id', 'my-uid') });
46
51
  ```
52
+
53
+ On hosts with the async APIs, a data source registered this way is not visible
54
+ to `getDataSourceSrv()`. Look it up with `getDataSourceInstance` instead.
package/dist/cjs/apps.cjs CHANGED
@@ -7,6 +7,9 @@ var unstable = require('@grafana/runtime/unstable');
7
7
 
8
8
  "use strict";
9
9
  async function getPluginSettings(pluginId, showErrorAlert = false) {
10
+ if (typeof runtime.getPluginSettings === "function") {
11
+ return runtime.getPluginSettings(pluginId, showErrorAlert);
12
+ }
10
13
  if (typeof unstable.getPluginSettings === "function") {
11
14
  return unstable.getPluginSettings(pluginId, showErrorAlert);
12
15
  }
@@ -19,6 +22,9 @@ async function backwardsCompatibleGetPluginSettings(pluginId, showErrorAlert = f
19
22
  });
20
23
  }
21
24
  async function updateAppPluginSettings(pluginId, data) {
25
+ if (typeof runtime.updateAppPluginSettings === "function") {
26
+ return runtime.updateAppPluginSettings(pluginId, data);
27
+ }
22
28
  if (typeof unstable.updateAppPluginSettings === "function") {
23
29
  return unstable.updateAppPluginSettings(pluginId, data);
24
30
  }
@@ -1 +1 @@
1
- {"version":3,"file":"apps.cjs","sources":["../../src/apps.ts"],"sourcesContent":["import { type PluginMeta } from '@grafana/data';\nimport { getBackendSrv } from '@grafana/runtime';\nimport {\n getPluginSettings as runtimeGetPluginSettings,\n updateAppPluginSettings as runtimeUpdateAppPluginSettings,\n} from '@grafana/runtime/unstable';\n\nexport async function getPluginSettings(pluginId: string, showErrorAlert = false): Promise<PluginMeta> {\n if (typeof runtimeGetPluginSettings === 'function') {\n return runtimeGetPluginSettings(pluginId, showErrorAlert);\n }\n\n return backwardsCompatibleGetPluginSettings(pluginId, showErrorAlert);\n}\n\nasync function backwardsCompatibleGetPluginSettings(pluginId: string, showErrorAlert = false): Promise<PluginMeta> {\n return getBackendSrv().get(`/api/plugins/${pluginId}/settings`, undefined, undefined, {\n showErrorAlert,\n validatePath: true,\n });\n}\n\nexport async function updateAppPluginSettings(pluginId: string, data: Partial<PluginMeta>): Promise<PluginMeta> {\n if (typeof runtimeUpdateAppPluginSettings === 'function') {\n return runtimeUpdateAppPluginSettings(pluginId, data);\n }\n\n return backwardsCompatibleUpdatePluginSettings(pluginId, data);\n}\n\nasync function backwardsCompatibleUpdatePluginSettings(\n pluginId: string,\n data: Partial<PluginMeta>\n): Promise<PluginMeta> {\n await getBackendSrv().post(`/api/plugins/${pluginId}/settings`, data, { validatePath: true });\n return backwardsCompatibleGetPluginSettings(pluginId);\n}\n"],"names":["runtimeGetPluginSettings","getBackendSrv","runtimeUpdateAppPluginSettings"],"mappings":";;;;;;;;AAOA,eAAsB,iBAAA,CAAkB,QAAA,EAAkB,cAAA,GAAiB,KAAA,EAA4B;AACrG,EAAA,IAAI,OAAOA,+BAA6B,UAAA,EAAY;AAClD,IAAA,OAAOA,0BAAA,CAAyB,UAAU,cAAc,CAAA;AAAA,EAC1D;AAEA,EAAA,OAAO,oCAAA,CAAqC,UAAU,cAAc,CAAA;AACtE;AAEA,eAAe,oCAAA,CAAqC,QAAA,EAAkB,cAAA,GAAiB,KAAA,EAA4B;AACjH,EAAA,OAAOC,uBAAc,CAAE,GAAA,CAAI,gBAAgB,QAAQ,CAAA,SAAA,CAAA,EAAa,QAAW,KAAA,CAAA,EAAW;AAAA,IACpF,cAAA;AAAA,IACA,YAAA,EAAc;AAAA,GACf,CAAA;AACH;AAEA,eAAsB,uBAAA,CAAwB,UAAkB,IAAA,EAAgD;AAC9G,EAAA,IAAI,OAAOC,qCAAmC,UAAA,EAAY;AACxD,IAAA,OAAOA,gCAAA,CAA+B,UAAU,IAAI,CAAA;AAAA,EACtD;AAEA,EAAA,OAAO,uCAAA,CAAwC,UAAU,IAAI,CAAA;AAC/D;AAEA,eAAe,uCAAA,CACb,UACA,IAAA,EACqB;AACrB,EAAA,MAAMD,qBAAA,EAAc,CAAE,IAAA,CAAK,CAAA,aAAA,EAAgB,QAAQ,aAAa,IAAA,EAAM,EAAE,YAAA,EAAc,IAAA,EAAM,CAAA;AAC5F,EAAA,OAAO,qCAAqC,QAAQ,CAAA;AACtD;;;;;"}
1
+ {"version":3,"file":"apps.cjs","sources":["../../src/apps.ts"],"sourcesContent":["import { type PluginMeta } from '@grafana/data';\nimport {\n getBackendSrv,\n getPluginSettings as stableGetPluginSettings,\n updateAppPluginSettings as stableUpdateAppPluginSettings,\n} from '@grafana/runtime';\nimport {\n getPluginSettings as unstableGetPluginSettings,\n updateAppPluginSettings as unstableUpdateAppPluginSettings,\n} from '@grafana/runtime/unstable';\n\nexport async function getPluginSettings(pluginId: string, showErrorAlert = false): Promise<PluginMeta> {\n if (typeof stableGetPluginSettings === 'function') {\n return stableGetPluginSettings(pluginId, showErrorAlert);\n }\n\n if (typeof unstableGetPluginSettings === 'function') {\n return unstableGetPluginSettings(pluginId, showErrorAlert);\n }\n\n return backwardsCompatibleGetPluginSettings(pluginId, showErrorAlert);\n}\n\nasync function backwardsCompatibleGetPluginSettings(pluginId: string, showErrorAlert = false): Promise<PluginMeta> {\n return getBackendSrv().get(`/api/plugins/${pluginId}/settings`, undefined, undefined, {\n showErrorAlert,\n validatePath: true,\n });\n}\n\nexport async function updateAppPluginSettings(pluginId: string, data: Partial<PluginMeta>): Promise<PluginMeta> {\n if (typeof stableUpdateAppPluginSettings === 'function') {\n return stableUpdateAppPluginSettings(pluginId, data);\n }\n\n if (typeof unstableUpdateAppPluginSettings === 'function') {\n return unstableUpdateAppPluginSettings(pluginId, data);\n }\n\n return backwardsCompatibleUpdatePluginSettings(pluginId, data);\n}\n\nasync function backwardsCompatibleUpdatePluginSettings(\n pluginId: string,\n data: Partial<PluginMeta>\n): Promise<PluginMeta> {\n await getBackendSrv().post(`/api/plugins/${pluginId}/settings`, data, { validatePath: true });\n return backwardsCompatibleGetPluginSettings(pluginId);\n}\n"],"names":["stableGetPluginSettings","unstableGetPluginSettings","getBackendSrv","stableUpdateAppPluginSettings","unstableUpdateAppPluginSettings"],"mappings":";;;;;;;;AAWA,eAAsB,iBAAA,CAAkB,QAAA,EAAkB,cAAA,GAAiB,KAAA,EAA4B;AACrG,EAAA,IAAI,OAAOA,8BAA4B,UAAA,EAAY;AACjD,IAAA,OAAOA,yBAAA,CAAwB,UAAU,cAAc,CAAA;AAAA,EACzD;AAEA,EAAA,IAAI,OAAOC,+BAA8B,UAAA,EAAY;AACnD,IAAA,OAAOA,0BAAA,CAA0B,UAAU,cAAc,CAAA;AAAA,EAC3D;AAEA,EAAA,OAAO,oCAAA,CAAqC,UAAU,cAAc,CAAA;AACtE;AAEA,eAAe,oCAAA,CAAqC,QAAA,EAAkB,cAAA,GAAiB,KAAA,EAA4B;AACjH,EAAA,OAAOC,uBAAc,CAAE,GAAA,CAAI,gBAAgB,QAAQ,CAAA,SAAA,CAAA,EAAa,QAAW,KAAA,CAAA,EAAW;AAAA,IACpF,cAAA;AAAA,IACA,YAAA,EAAc;AAAA,GACf,CAAA;AACH;AAEA,eAAsB,uBAAA,CAAwB,UAAkB,IAAA,EAAgD;AAC9G,EAAA,IAAI,OAAOC,oCAAkC,UAAA,EAAY;AACvD,IAAA,OAAOA,+BAAA,CAA8B,UAAU,IAAI,CAAA;AAAA,EACrD;AAEA,EAAA,IAAI,OAAOC,qCAAoC,UAAA,EAAY;AACzD,IAAA,OAAOA,gCAAA,CAAgC,UAAU,IAAI,CAAA;AAAA,EACvD;AAEA,EAAA,OAAO,uCAAA,CAAwC,UAAU,IAAI,CAAA;AAC/D;AAEA,eAAe,uCAAA,CACb,UACA,IAAA,EACqB;AACrB,EAAA,MAAMF,qBAAA,EAAc,CAAE,IAAA,CAAK,CAAA,aAAA,EAAgB,QAAQ,aAAa,IAAA,EAAM,EAAE,YAAA,EAAc,IAAA,EAAM,CAAA;AAC5F,EAAA,OAAO,qCAAqC,QAAQ,CAAA;AACtD;;;;;"}
@@ -7,6 +7,9 @@ var unstable = require('@grafana/runtime/unstable');
7
7
 
8
8
  "use strict";
9
9
  async function getDataSourceInstance(ref, scopedVars) {
10
+ if (typeof runtime.getDataSourceInstance === "function") {
11
+ return runtime.getDataSourceInstance(ref, scopedVars);
12
+ }
10
13
  if (typeof unstable.getDataSourceInstance === "function") {
11
14
  return unstable.getDataSourceInstance(ref, scopedVars);
12
15
  }
@@ -1 +1 @@
1
- {"version":3,"file":"getDataSourceInstance.cjs","sources":["../../../src/datasources/getDataSourceInstance.ts"],"sourcesContent":["/* eslint-disable @grafana/no-get-data-source-srv */\nimport { type DataSourceApi, type ScopedVars } from '@grafana/data';\nimport { getDataSourceSrv } from '@grafana/runtime';\nimport { getDataSourceInstance as rtGetDataSourceInstance } from '@grafana/runtime/unstable';\n\nimport { type Ref } from './types';\n\nexport async function getDataSourceInstance(ref?: Ref, scopedVars?: ScopedVars): Promise<DataSourceApi> {\n if (typeof rtGetDataSourceInstance === 'function') {\n return rtGetDataSourceInstance(ref, scopedVars);\n }\n\n return backwardsCompatibleGetDataSourceInstance(ref, scopedVars);\n}\n\nasync function backwardsCompatibleGetDataSourceInstance(ref?: Ref, scopedVars?: ScopedVars): Promise<DataSourceApi> {\n return getDataSourceSrv().get(ref, scopedVars);\n}\n"],"names":["rtGetDataSourceInstance","getDataSourceSrv"],"mappings":";;;;;;;;AAOA,eAAsB,qBAAA,CAAsB,KAAW,UAAA,EAAiD;AACtG,EAAA,IAAI,OAAOA,mCAA4B,UAAA,EAAY;AACjD,IAAA,OAAOA,8BAAA,CAAwB,KAAK,UAAU,CAAA;AAAA,EAChD;AAEA,EAAA,OAAO,wCAAA,CAAyC,KAAK,UAAU,CAAA;AACjE;AAEA,eAAe,wCAAA,CAAyC,KAAW,UAAA,EAAiD;AAClH,EAAA,OAAOC,wBAAA,EAAiB,CAAE,GAAA,CAAI,GAAA,EAAK,UAAU,CAAA;AAC/C;;;;"}
1
+ {"version":3,"file":"getDataSourceInstance.cjs","sources":["../../../src/datasources/getDataSourceInstance.ts"],"sourcesContent":["/* eslint-disable @grafana/no-get-data-source-srv */\nimport { type DataSourceApi, type ScopedVars } from '@grafana/data';\nimport { getDataSourceSrv, getDataSourceInstance as stableGetDataSourceInstance } from '@grafana/runtime';\nimport { getDataSourceInstance as unstableGetDataSourceInstance } from '@grafana/runtime/unstable';\n\nimport { type Ref } from './types';\n\nexport async function getDataSourceInstance(ref?: Ref, scopedVars?: ScopedVars): Promise<DataSourceApi> {\n if (typeof stableGetDataSourceInstance === 'function') {\n return stableGetDataSourceInstance(ref, scopedVars);\n }\n\n if (typeof unstableGetDataSourceInstance === 'function') {\n return unstableGetDataSourceInstance(ref, scopedVars);\n }\n\n return backwardsCompatibleGetDataSourceInstance(ref, scopedVars);\n}\n\nasync function backwardsCompatibleGetDataSourceInstance(ref?: Ref, scopedVars?: ScopedVars): Promise<DataSourceApi> {\n return getDataSourceSrv().get(ref, scopedVars);\n}\n"],"names":["stableGetDataSourceInstance","unstableGetDataSourceInstance","getDataSourceSrv"],"mappings":";;;;;;;;AAOA,eAAsB,qBAAA,CAAsB,KAAW,UAAA,EAAiD;AACtG,EAAA,IAAI,OAAOA,kCAAgC,UAAA,EAAY;AACrD,IAAA,OAAOA,6BAAA,CAA4B,KAAK,UAAU,CAAA;AAAA,EACpD;AAEA,EAAA,IAAI,OAAOC,mCAAkC,UAAA,EAAY;AACvD,IAAA,OAAOA,8BAAA,CAA8B,KAAK,UAAU,CAAA;AAAA,EACtD;AAEA,EAAA,OAAO,wCAAA,CAAyC,KAAK,UAAU,CAAA;AACjE;AAEA,eAAe,wCAAA,CAAyC,KAAW,UAAA,EAAiD;AAClH,EAAA,OAAOC,wBAAA,EAAiB,CAAE,GAAA,CAAI,GAAA,EAAK,UAAU,CAAA;AAC/C;;;;"}
@@ -7,6 +7,9 @@ var unstable = require('@grafana/runtime/unstable');
7
7
 
8
8
  "use strict";
9
9
  async function getDataSourceInstanceList(filters) {
10
+ if (typeof runtime.getDataSourceInstanceList === "function") {
11
+ return runtime.getDataSourceInstanceList(filters);
12
+ }
10
13
  if (typeof unstable.getDataSourceInstanceList === "function") {
11
14
  return unstable.getDataSourceInstanceList(filters);
12
15
  }
@@ -18,9 +21,7 @@ async function backwardsCompatibleGetDataSourceInstanceList(filters) {
18
21
  return runtime.getDataSourceSrv().getList(legacyFilters).map(toDataSourceInstanceListItem);
19
22
  }
20
23
  function toDataSourceInstanceListItem(item) {
21
- var _a;
22
24
  return {
23
- isDefault: (_a = item.isDefault) != null ? _a : false,
24
25
  meta: { ...item.meta },
25
26
  name: item.name,
26
27
  type: item.type,
@@ -1 +1 @@
1
- {"version":3,"file":"getDataSourceInstanceList.cjs","sources":["../../../src/datasources/getDataSourceInstanceList.ts"],"sourcesContent":["/* eslint-disable @grafana/no-get-data-source-srv */\nimport { type DataSourceInstanceListItem, type DataSourceInstanceSettings } from '@grafana/data';\nimport { type GetDataSourceListFilters, getDataSourceSrv } from '@grafana/runtime';\nimport {\n type GetDataSourceInstanceListFilters,\n getDataSourceInstanceList as rtGetDataSourceInstanceList,\n} from '@grafana/runtime/unstable';\n\nexport async function getDataSourceInstanceList(\n filters?: GetDataSourceInstanceListFilters\n): Promise<DataSourceInstanceListItem[]> {\n if (typeof rtGetDataSourceInstanceList === 'function') {\n return rtGetDataSourceInstanceList(filters);\n }\n\n return backwardsCompatibleGetDataSourceInstanceList(filters);\n}\n\nasync function backwardsCompatibleGetDataSourceInstanceList(\n filters?: GetDataSourceInstanceListFilters\n): Promise<DataSourceInstanceListItem[]> {\n const { filter, ...rest } = filters ?? {};\n const legacyFilters: GetDataSourceListFilters = filter\n ? { ...rest, filter: (item) => filter(toDataSourceInstanceListItem(item)) }\n : { ...rest };\n\n return getDataSourceSrv().getList(legacyFilters).map(toDataSourceInstanceListItem);\n}\n\nfunction toDataSourceInstanceListItem(item: DataSourceInstanceSettings): DataSourceInstanceListItem {\n return {\n isDefault: item.isDefault ?? false,\n meta: { ...item.meta },\n name: item.name,\n type: item.type,\n uid: item.uid,\n apiVersion: item.apiVersion,\n };\n}\n"],"names":["rtGetDataSourceInstanceList","getDataSourceSrv"],"mappings":";;;;;;;;AAQA,eAAsB,0BACpB,OAAA,EACuC;AACvC,EAAA,IAAI,OAAOA,uCAAgC,UAAA,EAAY;AACrD,IAAA,OAAOA,mCAA4B,OAAO,CAAA;AAAA,EAC5C;AAEA,EAAA,OAAO,6CAA6C,OAAO,CAAA;AAC7D;AAEA,eAAe,6CACb,OAAA,EACuC;AACvC,EAAA,MAAM,EAAE,MAAA,EAAQ,GAAG,IAAA,EAAK,GAAI,4BAAW,EAAC;AACxC,EAAA,MAAM,gBAA0C,MAAA,GAC5C,EAAE,GAAG,IAAA,EAAM,QAAQ,CAAC,IAAA,KAAS,MAAA,CAAO,4BAAA,CAA6B,IAAI,CAAC,CAAA,EAAE,GACxE,EAAE,GAAG,IAAA,EAAK;AAEd,EAAA,OAAOC,0BAAiB,CAAE,OAAA,CAAQ,aAAa,CAAA,CAAE,IAAI,4BAA4B,CAAA;AACnF;AAEA,SAAS,6BAA6B,IAAA,EAA8D;AA7BpG,EAAA,IAAA,EAAA;AA8BE,EAAA,OAAO;AAAA,IACL,SAAA,EAAA,CAAW,EAAA,GAAA,IAAA,CAAK,SAAA,KAAL,IAAA,GAAA,EAAA,GAAkB,KAAA;AAAA,IAC7B,IAAA,EAAM,EAAE,GAAG,IAAA,CAAK,IAAA,EAAK;AAAA,IACrB,MAAM,IAAA,CAAK,IAAA;AAAA,IACX,MAAM,IAAA,CAAK,IAAA;AAAA,IACX,KAAK,IAAA,CAAK,GAAA;AAAA,IACV,YAAY,IAAA,CAAK;AAAA,GACnB;AACF;;;;"}
1
+ {"version":3,"file":"getDataSourceInstanceList.cjs","sources":["../../../src/datasources/getDataSourceInstanceList.ts"],"sourcesContent":["/* eslint-disable @grafana/no-get-data-source-srv */\nimport { type DataSourceInstanceListItem, type DataSourceInstanceSettings } from '@grafana/data';\nimport {\n type GetDataSourceListFilters,\n getDataSourceSrv,\n getDataSourceInstanceList as stableGetDataSourceInstanceList,\n} from '@grafana/runtime';\nimport {\n type GetDataSourceInstanceListFilters,\n getDataSourceInstanceList as unstableGetDataSourceInstanceList,\n} from '@grafana/runtime/unstable';\n\nexport async function getDataSourceInstanceList(\n filters?: GetDataSourceInstanceListFilters\n): Promise<DataSourceInstanceListItem[]> {\n if (typeof stableGetDataSourceInstanceList === 'function') {\n return stableGetDataSourceInstanceList(filters);\n }\n\n if (typeof unstableGetDataSourceInstanceList === 'function') {\n return unstableGetDataSourceInstanceList(filters);\n }\n\n return backwardsCompatibleGetDataSourceInstanceList(filters);\n}\n\nasync function backwardsCompatibleGetDataSourceInstanceList(\n filters?: GetDataSourceInstanceListFilters\n): Promise<DataSourceInstanceListItem[]> {\n const { filter, ...rest } = filters ?? {};\n const legacyFilters: GetDataSourceListFilters = filter\n ? { ...rest, filter: (item) => filter(toDataSourceInstanceListItem(item)) }\n : { ...rest };\n\n return getDataSourceSrv().getList(legacyFilters).map(toDataSourceInstanceListItem);\n}\n\nfunction toDataSourceInstanceListItem(item: DataSourceInstanceSettings): DataSourceInstanceListItem {\n return {\n meta: { ...item.meta },\n name: item.name,\n type: item.type,\n uid: item.uid,\n apiVersion: item.apiVersion,\n };\n}\n"],"names":["stableGetDataSourceInstanceList","unstableGetDataSourceInstanceList","getDataSourceSrv"],"mappings":";;;;;;;;AAYA,eAAsB,0BACpB,OAAA,EACuC;AACvC,EAAA,IAAI,OAAOA,sCAAoC,UAAA,EAAY;AACzD,IAAA,OAAOA,kCAAgC,OAAO,CAAA;AAAA,EAChD;AAEA,EAAA,IAAI,OAAOC,uCAAsC,UAAA,EAAY;AAC3D,IAAA,OAAOA,mCAAkC,OAAO,CAAA;AAAA,EAClD;AAEA,EAAA,OAAO,6CAA6C,OAAO,CAAA;AAC7D;AAEA,eAAe,6CACb,OAAA,EACuC;AACvC,EAAA,MAAM,EAAE,MAAA,EAAQ,GAAG,IAAA,EAAK,GAAI,4BAAW,EAAC;AACxC,EAAA,MAAM,gBAA0C,MAAA,GAC5C,EAAE,GAAG,IAAA,EAAM,QAAQ,CAAC,IAAA,KAAS,MAAA,CAAO,4BAAA,CAA6B,IAAI,CAAC,CAAA,EAAE,GACxE,EAAE,GAAG,IAAA,EAAK;AAEd,EAAA,OAAOC,0BAAiB,CAAE,OAAA,CAAQ,aAAa,CAAA,CAAE,IAAI,4BAA4B,CAAA;AACnF;AAEA,SAAS,6BAA6B,IAAA,EAA8D;AAClG,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,EAAE,GAAG,IAAA,CAAK,IAAA,EAAK;AAAA,IACrB,MAAM,IAAA,CAAK,IAAA;AAAA,IACX,MAAM,IAAA,CAAK,IAAA;AAAA,IACX,KAAK,IAAA,CAAK,GAAA;AAAA,IACV,YAAY,IAAA,CAAK;AAAA,GACnB;AACF;;;;"}
@@ -7,6 +7,9 @@ var unstable = require('@grafana/runtime/unstable');
7
7
 
8
8
  "use strict";
9
9
  async function getDataSourceInstanceSettings(ref, scopedVars) {
10
+ if (typeof runtime.getDataSourceInstanceSettings === "function") {
11
+ return runtime.getDataSourceInstanceSettings(ref, scopedVars);
12
+ }
10
13
  if (typeof unstable.getDataSourceInstanceSettings === "function") {
11
14
  return unstable.getDataSourceInstanceSettings(ref, scopedVars);
12
15
  }
@@ -1 +1 @@
1
- {"version":3,"file":"getDataSourceInstanceSettings.cjs","sources":["../../../src/datasources/getDataSourceInstanceSettings.ts"],"sourcesContent":["/* eslint-disable @grafana/no-get-data-source-srv */\nimport { type ScopedVars, type DataSourceInstanceSettings } from '@grafana/data';\nimport { getDataSourceSrv } from '@grafana/runtime';\nimport { getDataSourceInstanceSettings as rtGetDataSourceInstanceSettings } from '@grafana/runtime/unstable';\n\nimport { type Ref } from './types';\n\nexport async function getDataSourceInstanceSettings(\n ref?: Ref,\n scopedVars?: ScopedVars\n): Promise<DataSourceInstanceSettings | undefined> {\n if (typeof rtGetDataSourceInstanceSettings === 'function') {\n return rtGetDataSourceInstanceSettings(ref, scopedVars);\n }\n\n return backwardsCompatibleDataSourceInstanceSettings(ref, scopedVars);\n}\n\nasync function backwardsCompatibleDataSourceInstanceSettings(\n ref?: Ref,\n scopedVars?: ScopedVars\n): Promise<DataSourceInstanceSettings | undefined> {\n return getDataSourceSrv().getInstanceSettings(ref, scopedVars);\n}\n"],"names":["rtGetDataSourceInstanceSettings","getDataSourceSrv"],"mappings":";;;;;;;;AAOA,eAAsB,6BAAA,CACpB,KACA,UAAA,EACiD;AACjD,EAAA,IAAI,OAAOA,2CAAoC,UAAA,EAAY;AACzD,IAAA,OAAOA,sCAAA,CAAgC,KAAK,UAAU,CAAA;AAAA,EACxD;AAEA,EAAA,OAAO,6CAAA,CAA8C,KAAK,UAAU,CAAA;AACtE;AAEA,eAAe,6CAAA,CACb,KACA,UAAA,EACiD;AACjD,EAAA,OAAOC,wBAAA,EAAiB,CAAE,mBAAA,CAAoB,GAAA,EAAK,UAAU,CAAA;AAC/D;;;;"}
1
+ {"version":3,"file":"getDataSourceInstanceSettings.cjs","sources":["../../../src/datasources/getDataSourceInstanceSettings.ts"],"sourcesContent":["/* eslint-disable @grafana/no-get-data-source-srv */\nimport { type ScopedVars, type DataSourceInstanceSettings } from '@grafana/data';\nimport {\n getDataSourceSrv,\n getDataSourceInstanceSettings as stableGetDataSourceInstanceSettings,\n} from '@grafana/runtime';\nimport { getDataSourceInstanceSettings as unstableGetDataSourceInstanceSettings } from '@grafana/runtime/unstable';\n\nimport { type Ref } from './types';\n\nexport async function getDataSourceInstanceSettings(\n ref?: Ref,\n scopedVars?: ScopedVars\n): Promise<DataSourceInstanceSettings | undefined> {\n if (typeof stableGetDataSourceInstanceSettings === 'function') {\n return stableGetDataSourceInstanceSettings(ref, scopedVars);\n }\n\n if (typeof unstableGetDataSourceInstanceSettings === 'function') {\n return unstableGetDataSourceInstanceSettings(ref, scopedVars);\n }\n\n return backwardsCompatibleDataSourceInstanceSettings(ref, scopedVars);\n}\n\nasync function backwardsCompatibleDataSourceInstanceSettings(\n ref?: Ref,\n scopedVars?: ScopedVars\n): Promise<DataSourceInstanceSettings | undefined> {\n return getDataSourceSrv().getInstanceSettings(ref, scopedVars);\n}\n"],"names":["stableGetDataSourceInstanceSettings","unstableGetDataSourceInstanceSettings","getDataSourceSrv"],"mappings":";;;;;;;;AAUA,eAAsB,6BAAA,CACpB,KACA,UAAA,EACiD;AACjD,EAAA,IAAI,OAAOA,0CAAwC,UAAA,EAAY;AAC7D,IAAA,OAAOA,qCAAA,CAAoC,KAAK,UAAU,CAAA;AAAA,EAC5D;AAEA,EAAA,IAAI,OAAOC,2CAA0C,UAAA,EAAY;AAC/D,IAAA,OAAOA,sCAAA,CAAsC,KAAK,UAAU,CAAA;AAAA,EAC9D;AAEA,EAAA,OAAO,6CAAA,CAA8C,KAAK,UAAU,CAAA;AACtE;AAEA,eAAe,6CAAA,CACb,KACA,UAAA,EACiD;AACjD,EAAA,OAAOC,wBAAA,EAAiB,CAAE,mBAAA,CAAoB,GAAA,EAAK,UAAU,CAAA;AAC/D;;;;"}
@@ -2,18 +2,26 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var runtime = require('@grafana/runtime');
5
6
  var unstable = require('@grafana/runtime/unstable');
6
7
 
7
8
  "use strict";
8
9
  async function getDefaultDataSourceInstanceListItem(items) {
10
+ if (typeof runtime.getDefaultDataSourceInstanceListItem === "function") {
11
+ return runtime.getDefaultDataSourceInstanceListItem(items);
12
+ }
9
13
  if (typeof unstable.getDefaultDataSourceInstanceListItem === "function") {
10
14
  return unstable.getDefaultDataSourceInstanceListItem(items);
11
15
  }
12
16
  return backwardsCompatibleGetDefaultDataSourceInstanceListItem(items);
13
17
  }
14
- async function backwardsCompatibleGetDefaultDataSourceInstanceListItem(items) {
15
- return items.find((item) => item == null ? void 0 : item.isDefault);
18
+ function backwardsCompatibleGetDefaultDataSourceInstanceListItem(items) {
19
+ return items.find((item) => {
20
+ var _a;
21
+ return item && ((_a = runtime.getDataSourceSrv().getInstanceSettings(item.uid)) == null ? void 0 : _a.isDefault);
22
+ });
16
23
  }
17
24
 
25
+ exports.backwardsCompatibleGetDefaultDataSourceInstanceListItem = backwardsCompatibleGetDefaultDataSourceInstanceListItem;
18
26
  exports.getDefaultDataSourceInstanceListItem = getDefaultDataSourceInstanceListItem;
19
27
  //# sourceMappingURL=getDefaultDataSourceInstanceListItem.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"getDefaultDataSourceInstanceListItem.cjs","sources":["../../../src/datasources/getDefaultDataSourceInstanceListItem.ts"],"sourcesContent":["import { type DataSourceInstanceListItem } from '@grafana/data';\nimport { getDefaultDataSourceInstanceListItem as rtGetDefaultDataSourceInstanceListItem } from '@grafana/runtime/unstable';\n\n/**\n * Resolve the item flagged as the default data source, or `undefined` when the list holds none.\n *\n * At most one instance per org carries the flag, so a filtered list need not contain it.\n */\nexport async function getDefaultDataSourceInstanceListItem(\n items: DataSourceInstanceListItem[]\n): Promise<DataSourceInstanceListItem | undefined> {\n if (typeof rtGetDefaultDataSourceInstanceListItem === 'function') {\n return rtGetDefaultDataSourceInstanceListItem(items);\n }\n\n return backwardsCompatibleGetDefaultDataSourceInstanceListItem(items);\n}\n\nasync function backwardsCompatibleGetDefaultDataSourceInstanceListItem(\n items: DataSourceInstanceListItem[]\n): Promise<DataSourceInstanceListItem | undefined> {\n return items.find((item) => item?.isDefault);\n}\n"],"names":["rtGetDefaultDataSourceInstanceListItem"],"mappings":";;;;;;;AAQA,eAAsB,qCACpB,KAAA,EACiD;AACjD,EAAA,IAAI,OAAOA,kDAA2C,UAAA,EAAY;AAChE,IAAA,OAAOA,8CAAuC,KAAK,CAAA;AAAA,EACrD;AAEA,EAAA,OAAO,wDAAwD,KAAK,CAAA;AACtE;AAEA,eAAe,wDACb,KAAA,EACiD;AACjD,EAAA,OAAO,KAAA,CAAM,IAAA,CAAK,CAAC,IAAA,KAAS,6BAAM,SAAS,CAAA;AAC7C;;;;"}
1
+ {"version":3,"file":"getDefaultDataSourceInstanceListItem.cjs","sources":["../../../src/datasources/getDefaultDataSourceInstanceListItem.ts"],"sourcesContent":["/* eslint-disable @grafana/no-get-data-source-srv */\nimport { type DataSourceInstanceListItem } from '@grafana/data';\nimport {\n getDataSourceSrv,\n getDefaultDataSourceInstanceListItem as stableGetDefaultDataSourceInstanceListItem,\n} from '@grafana/runtime';\nimport { getDefaultDataSourceInstanceListItem as unstableGetDefaultDataSourceInstanceListItem } from '@grafana/runtime/unstable';\n\n/**\n * Resolve the item whose data source is the org default, or `undefined` when the list holds none.\n *\n * At most one instance per org carries the flag, so a filtered list need not contain it.\n */\nexport async function getDefaultDataSourceInstanceListItem(\n items: DataSourceInstanceListItem[]\n): Promise<DataSourceInstanceListItem | undefined> {\n if (typeof stableGetDefaultDataSourceInstanceListItem === 'function') {\n return stableGetDefaultDataSourceInstanceListItem(items);\n }\n\n if (typeof unstableGetDefaultDataSourceInstanceListItem === 'function') {\n return unstableGetDefaultDataSourceInstanceListItem(items);\n }\n\n return backwardsCompatibleGetDefaultDataSourceInstanceListItem(items);\n}\n\nexport function backwardsCompatibleGetDefaultDataSourceInstanceListItem(\n items: DataSourceInstanceListItem[]\n): DataSourceInstanceListItem | undefined {\n return items.find((item) => item && getDataSourceSrv().getInstanceSettings(item.uid)?.isDefault);\n}\n"],"names":["stableGetDefaultDataSourceInstanceListItem","unstableGetDefaultDataSourceInstanceListItem"],"mappings":";;;;;;;;AAaA,eAAsB,qCACpB,KAAA,EACiD;AACjD,EAAA,IAAI,OAAOA,iDAA+C,UAAA,EAAY;AACpE,IAAA,OAAOA,6CAA2C,KAAK,CAAA;AAAA,EACzD;AAEA,EAAA,IAAI,OAAOC,kDAAiD,UAAA,EAAY;AACtE,IAAA,OAAOA,8CAA6C,KAAK,CAAA;AAAA,EAC3D;AAEA,EAAA,OAAO,wDAAwD,KAAK,CAAA;AACtE;AAEO,SAAS,wDACd,KAAA,EACwC;AACxC,EAAA,OAAO,KAAA,CAAM,IAAA,CAAK,CAAC,IAAA,KAAM;AA9B3B,IAAA,IAAA,EAAA;AA8B8B,IAAA,OAAA,IAAA,KAAA,CAAQ,+BAAiB,CAAE,mBAAA,CAAoB,IAAA,CAAK,GAAG,MAA/C,IAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAkD,SAAA,CAAA;AAAA,EAAA,CAAS,CAAA;AACjG;;;;;"}
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var runtime = require('@grafana/runtime');
6
+ var unstable = require('@grafana/runtime/unstable');
7
+
8
+ "use strict";
9
+ function registerRuntimeDataSourceInstance(entry) {
10
+ if (typeof runtime.registerRuntimeDataSourceInstance === "function") {
11
+ return runtime.registerRuntimeDataSourceInstance(entry);
12
+ }
13
+ if (typeof unstable.registerRuntimeDataSourceInstance === "function") {
14
+ return unstable.registerRuntimeDataSourceInstance(entry);
15
+ }
16
+ return backwardsCompatibleRegisterRuntimeDataSourceInstance(entry);
17
+ }
18
+ function backwardsCompatibleRegisterRuntimeDataSourceInstance(entry) {
19
+ return runtime.getDataSourceSrv().registerRuntimeDataSource(entry);
20
+ }
21
+
22
+ exports.registerRuntimeDataSourceInstance = registerRuntimeDataSourceInstance;
23
+ //# sourceMappingURL=registerRuntimeDataSourceInstance.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registerRuntimeDataSourceInstance.cjs","sources":["../../../src/datasources/registerRuntimeDataSourceInstance.ts"],"sourcesContent":["/* eslint-disable @grafana/no-get-data-source-srv */\nimport {\n getDataSourceSrv,\n type RuntimeDataSourceRegistration,\n registerRuntimeDataSourceInstance as stableRegisterRuntimeDataSourceInstance,\n} from '@grafana/runtime';\nimport { registerRuntimeDataSourceInstance as unstableRegisterRuntimeDataSourceInstance } from '@grafana/runtime/unstable';\n\nexport function registerRuntimeDataSourceInstance(entry: RuntimeDataSourceRegistration): void {\n if (typeof stableRegisterRuntimeDataSourceInstance === 'function') {\n return stableRegisterRuntimeDataSourceInstance(entry);\n }\n\n if (typeof unstableRegisterRuntimeDataSourceInstance === 'function') {\n return unstableRegisterRuntimeDataSourceInstance(entry);\n }\n\n return backwardsCompatibleRegisterRuntimeDataSourceInstance(entry);\n}\n\nfunction backwardsCompatibleRegisterRuntimeDataSourceInstance(entry: RuntimeDataSourceRegistration): void {\n return getDataSourceSrv().registerRuntimeDataSource(entry);\n}\n"],"names":["stableRegisterRuntimeDataSourceInstance","unstableRegisterRuntimeDataSourceInstance","getDataSourceSrv"],"mappings":";;;;;;;;AAQO,SAAS,kCAAkC,KAAA,EAA4C;AAC5F,EAAA,IAAI,OAAOA,8CAA4C,UAAA,EAAY;AACjE,IAAA,OAAOA,0CAAwC,KAAK,CAAA;AAAA,EACtD;AAEA,EAAA,IAAI,OAAOC,+CAA8C,UAAA,EAAY;AACnE,IAAA,OAAOA,2CAA0C,KAAK,CAAA;AAAA,EACxD;AAEA,EAAA,OAAO,qDAAqD,KAAK,CAAA;AACnE;AAEA,SAAS,qDAAqD,KAAA,EAA4C;AACxG,EAAA,OAAOC,wBAAA,EAAiB,CAAE,yBAAA,CAA0B,KAAK,CAAA;AAC3D;;;;"}
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var react = require('react');
6
+ var runtime = require('@grafana/runtime');
7
+ var unstable = require('@grafana/runtime/unstable');
8
+ var getDataSourceInstance = require('./getDataSourceInstance.cjs');
9
+
10
+ "use strict";
11
+ const useDataSourceInstance = typeof runtime.useDataSourceInstance === "function" ? runtime.useDataSourceInstance : typeof unstable.useDataSourceInstance === "function" ? unstable.useDataSourceInstance : useBackwardsCompatibleDataSourceInstance;
12
+ function useBackwardsCompatibleDataSourceInstance(ref) {
13
+ const [result, setResult] = react.useState({ isLoading: true });
14
+ const refKey = JSON.stringify(ref != null ? ref : null);
15
+ react.useEffect(() => {
16
+ let isCurrent = true;
17
+ setResult((previous) => ({ ...previous, isLoading: true }));
18
+ getDataSourceInstance.getDataSourceInstance(ref).then(
19
+ (dataSource) => isCurrent && setResult({ isLoading: false, dataSource }),
20
+ (error) => isCurrent && setResult({ isLoading: false, error })
21
+ );
22
+ return () => {
23
+ isCurrent = false;
24
+ };
25
+ }, [refKey]);
26
+ return result;
27
+ }
28
+
29
+ exports.useDataSourceInstance = useDataSourceInstance;
30
+ //# sourceMappingURL=useDataSourceInstance.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDataSourceInstance.cjs","sources":["../../../src/datasources/useDataSourceInstance.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport { type DataSourceApi } from '@grafana/data';\nimport { useDataSourceInstance as stableUseDataSourceInstance } from '@grafana/runtime';\nimport { useDataSourceInstance as unstableUseDataSourceInstance } from '@grafana/runtime/unstable';\n\nimport { getDataSourceInstance } from './getDataSourceInstance';\nimport { type Ref } from './types';\n\n/** Declared here because `@grafana/runtime` lacks it on older supported hosts. */\nexport interface UseDataSourceInstanceResult {\n isLoading: boolean;\n error?: Error;\n dataSource?: DataSourceApi;\n}\n\n/**\n * Uses the host hook when available. The fallback re-resolves only when `ref` changes, not on data source cache\n * changes. Picked once at load so the hook order stays stable.\n */\nexport const useDataSourceInstance: (ref?: Ref) => UseDataSourceInstanceResult =\n typeof stableUseDataSourceInstance === 'function'\n ? stableUseDataSourceInstance\n : typeof unstableUseDataSourceInstance === 'function'\n ? unstableUseDataSourceInstance\n : useBackwardsCompatibleDataSourceInstance;\n\nfunction useBackwardsCompatibleDataSourceInstance(ref?: Ref): UseDataSourceInstanceResult {\n const [result, setResult] = useState<UseDataSourceInstanceResult>({ isLoading: true });\n // Same key as the host hook, so inline ref objects don't refetch and `null` matches `undefined`.\n const refKey = JSON.stringify(ref ?? null);\n\n useEffect(() => {\n let isCurrent = true;\n setResult((previous) => ({ ...previous, isLoading: true }));\n\n getDataSourceInstance(ref).then(\n (dataSource) => isCurrent && setResult({ isLoading: false, dataSource }),\n (error: Error) => isCurrent && setResult({ isLoading: false, error })\n );\n\n return () => {\n isCurrent = false;\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [refKey]);\n\n return result;\n}\n"],"names":["stableUseDataSourceInstance","unstableUseDataSourceInstance","useState","useEffect","getDataSourceInstance"],"mappings":";;;;;;;;;;AAoBO,MAAM,qBAAA,GACX,OAAOA,6BAAA,KAAgC,UAAA,GACnCA,gCACA,OAAOC,8BAAA,KAAkC,aACvCA,8BAAA,GACA;AAER,SAAS,yCAAyC,GAAA,EAAwC;AACxF,EAAA,MAAM,CAAC,QAAQ,SAAS,CAAA,GAAIC,eAAsC,EAAE,SAAA,EAAW,MAAM,CAAA;AAErF,EAAA,MAAM,MAAA,GAAS,IAAA,CAAK,SAAA,CAAU,GAAA,IAAA,IAAA,GAAA,GAAA,GAAO,IAAI,CAAA;AAEzC,EAAAC,eAAA,CAAU,MAAM;AACd,IAAA,IAAI,SAAA,GAAY,IAAA;AAChB,IAAA,SAAA,CAAU,CAAC,QAAA,MAAc,EAAE,GAAG,QAAA,EAAU,SAAA,EAAW,MAAK,CAAE,CAAA;AAE1D,IAAAC,2CAAA,CAAsB,GAAG,CAAA,CAAE,IAAA;AAAA,MACzB,CAAC,eAAe,SAAA,IAAa,SAAA,CAAU,EAAE,SAAA,EAAW,KAAA,EAAO,YAAY,CAAA;AAAA,MACvE,CAAC,UAAiB,SAAA,IAAa,SAAA,CAAU,EAAE,SAAA,EAAW,KAAA,EAAO,OAAO;AAAA,KACtE;AAEA,IAAA,OAAO,MAAM;AACX,MAAA,SAAA,GAAY,KAAA;AAAA,IACd,CAAA;AAAA,EAEF,CAAA,EAAG,CAAC,MAAM,CAAC,CAAA;AAEX,EAAA,OAAO,MAAA;AACT;;;;"}
@@ -2,33 +2,14 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var react = require('react');
5
+ var runtime = require('@grafana/runtime');
6
+ var unstable = require('@grafana/runtime/unstable');
6
7
  var getDefaultDataSourceInstanceListItem = require('./getDefaultDataSourceInstanceListItem.cjs');
7
8
 
8
9
  "use strict";
9
- function useDefaultDataSourceInstanceListItem(items) {
10
- const [result, setResult] = react.useState({ isLoading: true });
11
- const itemsKey = JSON.stringify(items.map((item) => [item == null ? void 0 : item.uid, item == null ? void 0 : item.isDefault]));
12
- react.useEffect(() => {
13
- let active = true;
14
- setResult({ isLoading: true });
15
- getDefaultDataSourceInstanceListItem.getDefaultDataSourceInstanceListItem(items).then(
16
- (item) => {
17
- if (active) {
18
- setResult({ isLoading: false, item });
19
- }
20
- },
21
- (err) => {
22
- if (active) {
23
- setResult({ isLoading: false, error: err instanceof Error ? err : new Error(String(err)) });
24
- }
25
- }
26
- );
27
- return () => {
28
- active = false;
29
- };
30
- }, [itemsKey]);
31
- return result;
10
+ const useDefaultDataSourceInstanceListItem = typeof runtime.useDefaultDataSourceInstanceListItem === "function" ? runtime.useDefaultDataSourceInstanceListItem : typeof unstable.useDefaultDataSourceInstanceListItem === "function" ? unstable.useDefaultDataSourceInstanceListItem : useBackwardsCompatibleDefaultDataSourceInstanceListItem;
11
+ function useBackwardsCompatibleDefaultDataSourceInstanceListItem(items) {
12
+ return { isLoading: false, item: getDefaultDataSourceInstanceListItem.backwardsCompatibleGetDefaultDataSourceInstanceListItem(items) };
32
13
  }
33
14
 
34
15
  exports.useDefaultDataSourceInstanceListItem = useDefaultDataSourceInstanceListItem;
@@ -1 +1 @@
1
- {"version":3,"file":"useDefaultDataSourceInstanceListItem.cjs","sources":["../../../src/datasources/useDefaultDataSourceInstanceListItem.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport { type DataSourceInstanceListItem } from '@grafana/data';\n\nimport { getDefaultDataSourceInstanceListItem } from './getDefaultDataSourceInstanceListItem';\n\n/** Declared here because `@grafana/runtime/unstable` lacks it on older supported hosts. */\nexport interface UseDefaultDataSourceInstanceListItemResult {\n isLoading: boolean;\n error?: Error;\n item?: DataSourceInstanceListItem;\n}\n\n/**\n * React hook wrapping {@link getDefaultDataSourceInstanceListItem}. Re-resolves when the uid or\n * `isDefault` flag of any item changes, so passing an inline array is safe.\n */\nexport function useDefaultDataSourceInstanceListItem(\n items: DataSourceInstanceListItem[]\n): UseDefaultDataSourceInstanceListItemResult {\n const [result, setResult] = useState<UseDefaultDataSourceInstanceListItemResult>({ isLoading: true });\n const itemsKey = JSON.stringify(items.map((item) => [item?.uid, item?.isDefault]));\n\n useEffect(() => {\n let active = true;\n setResult({ isLoading: true });\n\n getDefaultDataSourceInstanceListItem(items).then(\n (item) => {\n if (active) {\n setResult({ isLoading: false, item });\n }\n },\n (err: unknown) => {\n if (active) {\n setResult({ isLoading: false, error: err instanceof Error ? err : new Error(String(err)) });\n }\n }\n );\n\n return () => {\n active = false;\n };\n // Keyed by uid and flag, the only fields the resolver reads.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [itemsKey]);\n\n return result;\n}\n"],"names":["useState","useEffect","getDefaultDataSourceInstanceListItem"],"mappings":";;;;;;;;AAiBO,SAAS,qCACd,KAAA,EAC4C;AAC5C,EAAA,MAAM,CAAC,QAAQ,SAAS,CAAA,GAAIA,eAAqD,EAAE,SAAA,EAAW,MAAM,CAAA;AACpG,EAAA,MAAM,QAAA,GAAW,IAAA,CAAK,SAAA,CAAU,KAAA,CAAM,GAAA,CAAI,CAAC,IAAA,KAAS,CAAC,IAAA,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,IAAA,CAAM,GAAA,EAAK,IAAA,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,IAAA,CAAM,SAAS,CAAC,CAAC,CAAA;AAEjF,EAAAC,eAAA,CAAU,MAAM;AACd,IAAA,IAAI,MAAA,GAAS,IAAA;AACb,IAAA,SAAA,CAAU,EAAE,SAAA,EAAW,IAAA,EAAM,CAAA;AAE7B,IAAAC,yEAAA,CAAqC,KAAK,CAAA,CAAE,IAAA;AAAA,MAC1C,CAAC,IAAA,KAAS;AACR,QAAA,IAAI,MAAA,EAAQ;AACV,UAAA,SAAA,CAAU,EAAE,SAAA,EAAW,KAAA,EAAO,IAAA,EAAM,CAAA;AAAA,QACtC;AAAA,MACF,CAAA;AAAA,MACA,CAAC,GAAA,KAAiB;AAChB,QAAA,IAAI,MAAA,EAAQ;AACV,UAAA,SAAA,CAAU,EAAE,SAAA,EAAW,KAAA,EAAO,KAAA,EAAO,GAAA,YAAe,KAAA,GAAQ,GAAA,GAAM,IAAI,KAAA,CAAM,MAAA,CAAO,GAAG,CAAC,GAAG,CAAA;AAAA,QAC5F;AAAA,MACF;AAAA,KACF;AAEA,IAAA,OAAO,MAAM;AACX,MAAA,MAAA,GAAS,KAAA;AAAA,IACX,CAAA;AAAA,EAGF,CAAA,EAAG,CAAC,QAAQ,CAAC,CAAA;AAEb,EAAA,OAAO,MAAA;AACT;;;;"}
1
+ {"version":3,"file":"useDefaultDataSourceInstanceListItem.cjs","sources":["../../../src/datasources/useDefaultDataSourceInstanceListItem.ts"],"sourcesContent":["import { type DataSourceInstanceListItem } from '@grafana/data';\nimport { useDefaultDataSourceInstanceListItem as stableUseDefaultDataSourceInstanceListItem } from '@grafana/runtime';\nimport { useDefaultDataSourceInstanceListItem as unstableUseDefaultDataSourceInstanceListItem } from '@grafana/runtime/unstable';\n\nimport { backwardsCompatibleGetDefaultDataSourceInstanceListItem } from './getDefaultDataSourceInstanceListItem';\n\n/** Declared here because `@grafana/runtime` lacks it on older supported hosts. */\nexport interface UseDefaultDataSourceInstanceListItemResult {\n isLoading: boolean;\n error?: Error;\n item?: DataSourceInstanceListItem;\n}\n\n/**\n * Uses the host hook when available, which also re-resolves on data source cache changes; otherwise\n * resolves synchronously on every render. Picked once at load so the hook order stays stable.\n */\nexport const useDefaultDataSourceInstanceListItem: (\n items: DataSourceInstanceListItem[]\n) => UseDefaultDataSourceInstanceListItemResult =\n typeof stableUseDefaultDataSourceInstanceListItem === 'function'\n ? stableUseDefaultDataSourceInstanceListItem\n : typeof unstableUseDefaultDataSourceInstanceListItem === 'function'\n ? unstableUseDefaultDataSourceInstanceListItem\n : useBackwardsCompatibleDefaultDataSourceInstanceListItem;\n\nfunction useBackwardsCompatibleDefaultDataSourceInstanceListItem(\n items: DataSourceInstanceListItem[]\n): UseDefaultDataSourceInstanceListItemResult {\n return { isLoading: false, item: backwardsCompatibleGetDefaultDataSourceInstanceListItem(items) };\n}\n"],"names":["stableUseDefaultDataSourceInstanceListItem","unstableUseDefaultDataSourceInstanceListItem","backwardsCompatibleGetDefaultDataSourceInstanceListItem"],"mappings":";;;;;;;;;AAiBO,MAAM,oCAAA,GAGX,OAAOA,4CAAA,KAA+C,UAAA,GAClDA,+CACA,OAAOC,6CAAA,KAAiD,aACtDA,6CAAA,GACA;AAER,SAAS,wDACP,KAAA,EAC4C;AAC5C,EAAA,OAAO,EAAE,SAAA,EAAW,KAAA,EAAO,IAAA,EAAMC,4FAAA,CAAwD,KAAK,CAAA,EAAE;AAClG;;;;"}
@@ -6,6 +6,8 @@ var getDataSourceInstance = require('./datasources/getDataSourceInstance.cjs');
6
6
  var getDataSourceInstanceList = require('./datasources/getDataSourceInstanceList.cjs');
7
7
  var getDataSourceInstanceSettings = require('./datasources/getDataSourceInstanceSettings.cjs');
8
8
  var getDefaultDataSourceInstanceListItem = require('./datasources/getDefaultDataSourceInstanceListItem.cjs');
9
+ var registerRuntimeDataSourceInstance = require('./datasources/registerRuntimeDataSourceInstance.cjs');
10
+ var useDataSourceInstance = require('./datasources/useDataSourceInstance.cjs');
9
11
  var useDefaultDataSourceInstanceListItem = require('./datasources/useDefaultDataSourceInstanceListItem.cjs');
10
12
 
11
13
  "use strict";
@@ -14,5 +16,7 @@ exports.getDataSourceInstance = getDataSourceInstance.getDataSourceInstance;
14
16
  exports.getDataSourceInstanceList = getDataSourceInstanceList.getDataSourceInstanceList;
15
17
  exports.getDataSourceInstanceSettings = getDataSourceInstanceSettings.getDataSourceInstanceSettings;
16
18
  exports.getDefaultDataSourceInstanceListItem = getDefaultDataSourceInstanceListItem.getDefaultDataSourceInstanceListItem;
19
+ exports.registerRuntimeDataSourceInstance = registerRuntimeDataSourceInstance.registerRuntimeDataSourceInstance;
20
+ exports.useDataSourceInstance = useDataSourceInstance.useDataSourceInstance;
17
21
  exports.useDefaultDataSourceInstanceListItem = useDefaultDataSourceInstanceListItem.useDefaultDataSourceInstanceListItem;
18
22
  //# sourceMappingURL=datasources.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"datasources.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"datasources.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;"}
package/dist/esm/apps.mjs CHANGED
@@ -1,11 +1,14 @@
1
- import { getBackendSrv } from '@grafana/runtime';
2
- import { getPluginSettings as getPluginSettings$1, updateAppPluginSettings as updateAppPluginSettings$1 } from '@grafana/runtime/unstable';
1
+ import { getPluginSettings as getPluginSettings$1, getBackendSrv, updateAppPluginSettings as updateAppPluginSettings$1 } from '@grafana/runtime';
2
+ import { getPluginSettings as getPluginSettings$2, updateAppPluginSettings as updateAppPluginSettings$2 } from '@grafana/runtime/unstable';
3
3
 
4
4
  "use strict";
5
5
  async function getPluginSettings(pluginId, showErrorAlert = false) {
6
6
  if (typeof getPluginSettings$1 === "function") {
7
7
  return getPluginSettings$1(pluginId, showErrorAlert);
8
8
  }
9
+ if (typeof getPluginSettings$2 === "function") {
10
+ return getPluginSettings$2(pluginId, showErrorAlert);
11
+ }
9
12
  return backwardsCompatibleGetPluginSettings(pluginId, showErrorAlert);
10
13
  }
11
14
  async function backwardsCompatibleGetPluginSettings(pluginId, showErrorAlert = false) {
@@ -18,6 +21,9 @@ async function updateAppPluginSettings(pluginId, data) {
18
21
  if (typeof updateAppPluginSettings$1 === "function") {
19
22
  return updateAppPluginSettings$1(pluginId, data);
20
23
  }
24
+ if (typeof updateAppPluginSettings$2 === "function") {
25
+ return updateAppPluginSettings$2(pluginId, data);
26
+ }
21
27
  return backwardsCompatibleUpdatePluginSettings(pluginId, data);
22
28
  }
23
29
  async function backwardsCompatibleUpdatePluginSettings(pluginId, data) {
@@ -1 +1 @@
1
- {"version":3,"file":"apps.mjs","sources":["../../src/apps.ts"],"sourcesContent":["import { type PluginMeta } from '@grafana/data';\nimport { getBackendSrv } from '@grafana/runtime';\nimport {\n getPluginSettings as runtimeGetPluginSettings,\n updateAppPluginSettings as runtimeUpdateAppPluginSettings,\n} from '@grafana/runtime/unstable';\n\nexport async function getPluginSettings(pluginId: string, showErrorAlert = false): Promise<PluginMeta> {\n if (typeof runtimeGetPluginSettings === 'function') {\n return runtimeGetPluginSettings(pluginId, showErrorAlert);\n }\n\n return backwardsCompatibleGetPluginSettings(pluginId, showErrorAlert);\n}\n\nasync function backwardsCompatibleGetPluginSettings(pluginId: string, showErrorAlert = false): Promise<PluginMeta> {\n return getBackendSrv().get(`/api/plugins/${pluginId}/settings`, undefined, undefined, {\n showErrorAlert,\n validatePath: true,\n });\n}\n\nexport async function updateAppPluginSettings(pluginId: string, data: Partial<PluginMeta>): Promise<PluginMeta> {\n if (typeof runtimeUpdateAppPluginSettings === 'function') {\n return runtimeUpdateAppPluginSettings(pluginId, data);\n }\n\n return backwardsCompatibleUpdatePluginSettings(pluginId, data);\n}\n\nasync function backwardsCompatibleUpdatePluginSettings(\n pluginId: string,\n data: Partial<PluginMeta>\n): Promise<PluginMeta> {\n await getBackendSrv().post(`/api/plugins/${pluginId}/settings`, data, { validatePath: true });\n return backwardsCompatibleGetPluginSettings(pluginId);\n}\n"],"names":["runtimeGetPluginSettings","runtimeUpdateAppPluginSettings"],"mappings":";;;;AAOA,eAAsB,iBAAA,CAAkB,QAAA,EAAkB,cAAA,GAAiB,KAAA,EAA4B;AACrG,EAAA,IAAI,OAAOA,wBAA6B,UAAA,EAAY;AAClD,IAAA,OAAOA,mBAAA,CAAyB,UAAU,cAAc,CAAA;AAAA,EAC1D;AAEA,EAAA,OAAO,oCAAA,CAAqC,UAAU,cAAc,CAAA;AACtE;AAEA,eAAe,oCAAA,CAAqC,QAAA,EAAkB,cAAA,GAAiB,KAAA,EAA4B;AACjH,EAAA,OAAO,eAAc,CAAE,GAAA,CAAI,gBAAgB,QAAQ,CAAA,SAAA,CAAA,EAAa,QAAW,KAAA,CAAA,EAAW;AAAA,IACpF,cAAA;AAAA,IACA,YAAA,EAAc;AAAA,GACf,CAAA;AACH;AAEA,eAAsB,uBAAA,CAAwB,UAAkB,IAAA,EAAgD;AAC9G,EAAA,IAAI,OAAOC,8BAAmC,UAAA,EAAY;AACxD,IAAA,OAAOA,yBAAA,CAA+B,UAAU,IAAI,CAAA;AAAA,EACtD;AAEA,EAAA,OAAO,uCAAA,CAAwC,UAAU,IAAI,CAAA;AAC/D;AAEA,eAAe,uCAAA,CACb,UACA,IAAA,EACqB;AACrB,EAAA,MAAM,aAAA,EAAc,CAAE,IAAA,CAAK,CAAA,aAAA,EAAgB,QAAQ,aAAa,IAAA,EAAM,EAAE,YAAA,EAAc,IAAA,EAAM,CAAA;AAC5F,EAAA,OAAO,qCAAqC,QAAQ,CAAA;AACtD;;;;"}
1
+ {"version":3,"file":"apps.mjs","sources":["../../src/apps.ts"],"sourcesContent":["import { type PluginMeta } from '@grafana/data';\nimport {\n getBackendSrv,\n getPluginSettings as stableGetPluginSettings,\n updateAppPluginSettings as stableUpdateAppPluginSettings,\n} from '@grafana/runtime';\nimport {\n getPluginSettings as unstableGetPluginSettings,\n updateAppPluginSettings as unstableUpdateAppPluginSettings,\n} from '@grafana/runtime/unstable';\n\nexport async function getPluginSettings(pluginId: string, showErrorAlert = false): Promise<PluginMeta> {\n if (typeof stableGetPluginSettings === 'function') {\n return stableGetPluginSettings(pluginId, showErrorAlert);\n }\n\n if (typeof unstableGetPluginSettings === 'function') {\n return unstableGetPluginSettings(pluginId, showErrorAlert);\n }\n\n return backwardsCompatibleGetPluginSettings(pluginId, showErrorAlert);\n}\n\nasync function backwardsCompatibleGetPluginSettings(pluginId: string, showErrorAlert = false): Promise<PluginMeta> {\n return getBackendSrv().get(`/api/plugins/${pluginId}/settings`, undefined, undefined, {\n showErrorAlert,\n validatePath: true,\n });\n}\n\nexport async function updateAppPluginSettings(pluginId: string, data: Partial<PluginMeta>): Promise<PluginMeta> {\n if (typeof stableUpdateAppPluginSettings === 'function') {\n return stableUpdateAppPluginSettings(pluginId, data);\n }\n\n if (typeof unstableUpdateAppPluginSettings === 'function') {\n return unstableUpdateAppPluginSettings(pluginId, data);\n }\n\n return backwardsCompatibleUpdatePluginSettings(pluginId, data);\n}\n\nasync function backwardsCompatibleUpdatePluginSettings(\n pluginId: string,\n data: Partial<PluginMeta>\n): Promise<PluginMeta> {\n await getBackendSrv().post(`/api/plugins/${pluginId}/settings`, data, { validatePath: true });\n return backwardsCompatibleGetPluginSettings(pluginId);\n}\n"],"names":["stableGetPluginSettings","unstableGetPluginSettings","stableUpdateAppPluginSettings","unstableUpdateAppPluginSettings"],"mappings":";;;;AAWA,eAAsB,iBAAA,CAAkB,QAAA,EAAkB,cAAA,GAAiB,KAAA,EAA4B;AACrG,EAAA,IAAI,OAAOA,wBAA4B,UAAA,EAAY;AACjD,IAAA,OAAOA,mBAAA,CAAwB,UAAU,cAAc,CAAA;AAAA,EACzD;AAEA,EAAA,IAAI,OAAOC,wBAA8B,UAAA,EAAY;AACnD,IAAA,OAAOA,mBAAA,CAA0B,UAAU,cAAc,CAAA;AAAA,EAC3D;AAEA,EAAA,OAAO,oCAAA,CAAqC,UAAU,cAAc,CAAA;AACtE;AAEA,eAAe,oCAAA,CAAqC,QAAA,EAAkB,cAAA,GAAiB,KAAA,EAA4B;AACjH,EAAA,OAAO,eAAc,CAAE,GAAA,CAAI,gBAAgB,QAAQ,CAAA,SAAA,CAAA,EAAa,QAAW,KAAA,CAAA,EAAW;AAAA,IACpF,cAAA;AAAA,IACA,YAAA,EAAc;AAAA,GACf,CAAA;AACH;AAEA,eAAsB,uBAAA,CAAwB,UAAkB,IAAA,EAAgD;AAC9G,EAAA,IAAI,OAAOC,8BAAkC,UAAA,EAAY;AACvD,IAAA,OAAOA,yBAAA,CAA8B,UAAU,IAAI,CAAA;AAAA,EACrD;AAEA,EAAA,IAAI,OAAOC,8BAAoC,UAAA,EAAY;AACzD,IAAA,OAAOA,yBAAA,CAAgC,UAAU,IAAI,CAAA;AAAA,EACvD;AAEA,EAAA,OAAO,uCAAA,CAAwC,UAAU,IAAI,CAAA;AAC/D;AAEA,eAAe,uCAAA,CACb,UACA,IAAA,EACqB;AACrB,EAAA,MAAM,aAAA,EAAc,CAAE,IAAA,CAAK,CAAA,aAAA,EAAgB,QAAQ,aAAa,IAAA,EAAM,EAAE,YAAA,EAAc,IAAA,EAAM,CAAA;AAC5F,EAAA,OAAO,qCAAqC,QAAQ,CAAA;AACtD;;;;"}
@@ -1,11 +1,14 @@
1
- import { getDataSourceSrv } from '@grafana/runtime';
2
- import { getDataSourceInstance as getDataSourceInstance$1 } from '@grafana/runtime/unstable';
1
+ import { getDataSourceInstance as getDataSourceInstance$1, getDataSourceSrv } from '@grafana/runtime';
2
+ import { getDataSourceInstance as getDataSourceInstance$2 } from '@grafana/runtime/unstable';
3
3
 
4
4
  "use strict";
5
5
  async function getDataSourceInstance(ref, scopedVars) {
6
6
  if (typeof getDataSourceInstance$1 === "function") {
7
7
  return getDataSourceInstance$1(ref, scopedVars);
8
8
  }
9
+ if (typeof getDataSourceInstance$2 === "function") {
10
+ return getDataSourceInstance$2(ref, scopedVars);
11
+ }
9
12
  return backwardsCompatibleGetDataSourceInstance(ref, scopedVars);
10
13
  }
11
14
  async function backwardsCompatibleGetDataSourceInstance(ref, scopedVars) {
@@ -1 +1 @@
1
- {"version":3,"file":"getDataSourceInstance.mjs","sources":["../../../src/datasources/getDataSourceInstance.ts"],"sourcesContent":["/* eslint-disable @grafana/no-get-data-source-srv */\nimport { type DataSourceApi, type ScopedVars } from '@grafana/data';\nimport { getDataSourceSrv } from '@grafana/runtime';\nimport { getDataSourceInstance as rtGetDataSourceInstance } from '@grafana/runtime/unstable';\n\nimport { type Ref } from './types';\n\nexport async function getDataSourceInstance(ref?: Ref, scopedVars?: ScopedVars): Promise<DataSourceApi> {\n if (typeof rtGetDataSourceInstance === 'function') {\n return rtGetDataSourceInstance(ref, scopedVars);\n }\n\n return backwardsCompatibleGetDataSourceInstance(ref, scopedVars);\n}\n\nasync function backwardsCompatibleGetDataSourceInstance(ref?: Ref, scopedVars?: ScopedVars): Promise<DataSourceApi> {\n return getDataSourceSrv().get(ref, scopedVars);\n}\n"],"names":["rtGetDataSourceInstance"],"mappings":";;;;AAOA,eAAsB,qBAAA,CAAsB,KAAW,UAAA,EAAiD;AACtG,EAAA,IAAI,OAAOA,4BAA4B,UAAA,EAAY;AACjD,IAAA,OAAOA,uBAAA,CAAwB,KAAK,UAAU,CAAA;AAAA,EAChD;AAEA,EAAA,OAAO,wCAAA,CAAyC,KAAK,UAAU,CAAA;AACjE;AAEA,eAAe,wCAAA,CAAyC,KAAW,UAAA,EAAiD;AAClH,EAAA,OAAO,gBAAA,EAAiB,CAAE,GAAA,CAAI,GAAA,EAAK,UAAU,CAAA;AAC/C;;;;"}
1
+ {"version":3,"file":"getDataSourceInstance.mjs","sources":["../../../src/datasources/getDataSourceInstance.ts"],"sourcesContent":["/* eslint-disable @grafana/no-get-data-source-srv */\nimport { type DataSourceApi, type ScopedVars } from '@grafana/data';\nimport { getDataSourceSrv, getDataSourceInstance as stableGetDataSourceInstance } from '@grafana/runtime';\nimport { getDataSourceInstance as unstableGetDataSourceInstance } from '@grafana/runtime/unstable';\n\nimport { type Ref } from './types';\n\nexport async function getDataSourceInstance(ref?: Ref, scopedVars?: ScopedVars): Promise<DataSourceApi> {\n if (typeof stableGetDataSourceInstance === 'function') {\n return stableGetDataSourceInstance(ref, scopedVars);\n }\n\n if (typeof unstableGetDataSourceInstance === 'function') {\n return unstableGetDataSourceInstance(ref, scopedVars);\n }\n\n return backwardsCompatibleGetDataSourceInstance(ref, scopedVars);\n}\n\nasync function backwardsCompatibleGetDataSourceInstance(ref?: Ref, scopedVars?: ScopedVars): Promise<DataSourceApi> {\n return getDataSourceSrv().get(ref, scopedVars);\n}\n"],"names":["stableGetDataSourceInstance","unstableGetDataSourceInstance"],"mappings":";;;;AAOA,eAAsB,qBAAA,CAAsB,KAAW,UAAA,EAAiD;AACtG,EAAA,IAAI,OAAOA,4BAAgC,UAAA,EAAY;AACrD,IAAA,OAAOA,uBAAA,CAA4B,KAAK,UAAU,CAAA;AAAA,EACpD;AAEA,EAAA,IAAI,OAAOC,4BAAkC,UAAA,EAAY;AACvD,IAAA,OAAOA,uBAAA,CAA8B,KAAK,UAAU,CAAA;AAAA,EACtD;AAEA,EAAA,OAAO,wCAAA,CAAyC,KAAK,UAAU,CAAA;AACjE;AAEA,eAAe,wCAAA,CAAyC,KAAW,UAAA,EAAiD;AAClH,EAAA,OAAO,gBAAA,EAAiB,CAAE,GAAA,CAAI,GAAA,EAAK,UAAU,CAAA;AAC/C;;;;"}
@@ -1,11 +1,14 @@
1
- import { getDataSourceSrv } from '@grafana/runtime';
2
- import { getDataSourceInstanceList as getDataSourceInstanceList$1 } from '@grafana/runtime/unstable';
1
+ import { getDataSourceInstanceList as getDataSourceInstanceList$1, getDataSourceSrv } from '@grafana/runtime';
2
+ import { getDataSourceInstanceList as getDataSourceInstanceList$2 } from '@grafana/runtime/unstable';
3
3
 
4
4
  "use strict";
5
5
  async function getDataSourceInstanceList(filters) {
6
6
  if (typeof getDataSourceInstanceList$1 === "function") {
7
7
  return getDataSourceInstanceList$1(filters);
8
8
  }
9
+ if (typeof getDataSourceInstanceList$2 === "function") {
10
+ return getDataSourceInstanceList$2(filters);
11
+ }
9
12
  return backwardsCompatibleGetDataSourceInstanceList(filters);
10
13
  }
11
14
  async function backwardsCompatibleGetDataSourceInstanceList(filters) {
@@ -14,9 +17,7 @@ async function backwardsCompatibleGetDataSourceInstanceList(filters) {
14
17
  return getDataSourceSrv().getList(legacyFilters).map(toDataSourceInstanceListItem);
15
18
  }
16
19
  function toDataSourceInstanceListItem(item) {
17
- var _a;
18
20
  return {
19
- isDefault: (_a = item.isDefault) != null ? _a : false,
20
21
  meta: { ...item.meta },
21
22
  name: item.name,
22
23
  type: item.type,
@@ -1 +1 @@
1
- {"version":3,"file":"getDataSourceInstanceList.mjs","sources":["../../../src/datasources/getDataSourceInstanceList.ts"],"sourcesContent":["/* eslint-disable @grafana/no-get-data-source-srv */\nimport { type DataSourceInstanceListItem, type DataSourceInstanceSettings } from '@grafana/data';\nimport { type GetDataSourceListFilters, getDataSourceSrv } from '@grafana/runtime';\nimport {\n type GetDataSourceInstanceListFilters,\n getDataSourceInstanceList as rtGetDataSourceInstanceList,\n} from '@grafana/runtime/unstable';\n\nexport async function getDataSourceInstanceList(\n filters?: GetDataSourceInstanceListFilters\n): Promise<DataSourceInstanceListItem[]> {\n if (typeof rtGetDataSourceInstanceList === 'function') {\n return rtGetDataSourceInstanceList(filters);\n }\n\n return backwardsCompatibleGetDataSourceInstanceList(filters);\n}\n\nasync function backwardsCompatibleGetDataSourceInstanceList(\n filters?: GetDataSourceInstanceListFilters\n): Promise<DataSourceInstanceListItem[]> {\n const { filter, ...rest } = filters ?? {};\n const legacyFilters: GetDataSourceListFilters = filter\n ? { ...rest, filter: (item) => filter(toDataSourceInstanceListItem(item)) }\n : { ...rest };\n\n return getDataSourceSrv().getList(legacyFilters).map(toDataSourceInstanceListItem);\n}\n\nfunction toDataSourceInstanceListItem(item: DataSourceInstanceSettings): DataSourceInstanceListItem {\n return {\n isDefault: item.isDefault ?? false,\n meta: { ...item.meta },\n name: item.name,\n type: item.type,\n uid: item.uid,\n apiVersion: item.apiVersion,\n };\n}\n"],"names":["rtGetDataSourceInstanceList"],"mappings":";;;;AAQA,eAAsB,0BACpB,OAAA,EACuC;AACvC,EAAA,IAAI,OAAOA,gCAAgC,UAAA,EAAY;AACrD,IAAA,OAAOA,4BAA4B,OAAO,CAAA;AAAA,EAC5C;AAEA,EAAA,OAAO,6CAA6C,OAAO,CAAA;AAC7D;AAEA,eAAe,6CACb,OAAA,EACuC;AACvC,EAAA,MAAM,EAAE,MAAA,EAAQ,GAAG,IAAA,EAAK,GAAI,4BAAW,EAAC;AACxC,EAAA,MAAM,gBAA0C,MAAA,GAC5C,EAAE,GAAG,IAAA,EAAM,QAAQ,CAAC,IAAA,KAAS,MAAA,CAAO,4BAAA,CAA6B,IAAI,CAAC,CAAA,EAAE,GACxE,EAAE,GAAG,IAAA,EAAK;AAEd,EAAA,OAAO,kBAAiB,CAAE,OAAA,CAAQ,aAAa,CAAA,CAAE,IAAI,4BAA4B,CAAA;AACnF;AAEA,SAAS,6BAA6B,IAAA,EAA8D;AA7BpG,EAAA,IAAA,EAAA;AA8BE,EAAA,OAAO;AAAA,IACL,SAAA,EAAA,CAAW,EAAA,GAAA,IAAA,CAAK,SAAA,KAAL,IAAA,GAAA,EAAA,GAAkB,KAAA;AAAA,IAC7B,IAAA,EAAM,EAAE,GAAG,IAAA,CAAK,IAAA,EAAK;AAAA,IACrB,MAAM,IAAA,CAAK,IAAA;AAAA,IACX,MAAM,IAAA,CAAK,IAAA;AAAA,IACX,KAAK,IAAA,CAAK,GAAA;AAAA,IACV,YAAY,IAAA,CAAK;AAAA,GACnB;AACF;;;;"}
1
+ {"version":3,"file":"getDataSourceInstanceList.mjs","sources":["../../../src/datasources/getDataSourceInstanceList.ts"],"sourcesContent":["/* eslint-disable @grafana/no-get-data-source-srv */\nimport { type DataSourceInstanceListItem, type DataSourceInstanceSettings } from '@grafana/data';\nimport {\n type GetDataSourceListFilters,\n getDataSourceSrv,\n getDataSourceInstanceList as stableGetDataSourceInstanceList,\n} from '@grafana/runtime';\nimport {\n type GetDataSourceInstanceListFilters,\n getDataSourceInstanceList as unstableGetDataSourceInstanceList,\n} from '@grafana/runtime/unstable';\n\nexport async function getDataSourceInstanceList(\n filters?: GetDataSourceInstanceListFilters\n): Promise<DataSourceInstanceListItem[]> {\n if (typeof stableGetDataSourceInstanceList === 'function') {\n return stableGetDataSourceInstanceList(filters);\n }\n\n if (typeof unstableGetDataSourceInstanceList === 'function') {\n return unstableGetDataSourceInstanceList(filters);\n }\n\n return backwardsCompatibleGetDataSourceInstanceList(filters);\n}\n\nasync function backwardsCompatibleGetDataSourceInstanceList(\n filters?: GetDataSourceInstanceListFilters\n): Promise<DataSourceInstanceListItem[]> {\n const { filter, ...rest } = filters ?? {};\n const legacyFilters: GetDataSourceListFilters = filter\n ? { ...rest, filter: (item) => filter(toDataSourceInstanceListItem(item)) }\n : { ...rest };\n\n return getDataSourceSrv().getList(legacyFilters).map(toDataSourceInstanceListItem);\n}\n\nfunction toDataSourceInstanceListItem(item: DataSourceInstanceSettings): DataSourceInstanceListItem {\n return {\n meta: { ...item.meta },\n name: item.name,\n type: item.type,\n uid: item.uid,\n apiVersion: item.apiVersion,\n };\n}\n"],"names":["stableGetDataSourceInstanceList","unstableGetDataSourceInstanceList"],"mappings":";;;;AAYA,eAAsB,0BACpB,OAAA,EACuC;AACvC,EAAA,IAAI,OAAOA,gCAAoC,UAAA,EAAY;AACzD,IAAA,OAAOA,4BAAgC,OAAO,CAAA;AAAA,EAChD;AAEA,EAAA,IAAI,OAAOC,gCAAsC,UAAA,EAAY;AAC3D,IAAA,OAAOA,4BAAkC,OAAO,CAAA;AAAA,EAClD;AAEA,EAAA,OAAO,6CAA6C,OAAO,CAAA;AAC7D;AAEA,eAAe,6CACb,OAAA,EACuC;AACvC,EAAA,MAAM,EAAE,MAAA,EAAQ,GAAG,IAAA,EAAK,GAAI,4BAAW,EAAC;AACxC,EAAA,MAAM,gBAA0C,MAAA,GAC5C,EAAE,GAAG,IAAA,EAAM,QAAQ,CAAC,IAAA,KAAS,MAAA,CAAO,4BAAA,CAA6B,IAAI,CAAC,CAAA,EAAE,GACxE,EAAE,GAAG,IAAA,EAAK;AAEd,EAAA,OAAO,kBAAiB,CAAE,OAAA,CAAQ,aAAa,CAAA,CAAE,IAAI,4BAA4B,CAAA;AACnF;AAEA,SAAS,6BAA6B,IAAA,EAA8D;AAClG,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,EAAE,GAAG,IAAA,CAAK,IAAA,EAAK;AAAA,IACrB,MAAM,IAAA,CAAK,IAAA;AAAA,IACX,MAAM,IAAA,CAAK,IAAA;AAAA,IACX,KAAK,IAAA,CAAK,GAAA;AAAA,IACV,YAAY,IAAA,CAAK;AAAA,GACnB;AACF;;;;"}
@@ -1,11 +1,14 @@
1
- import { getDataSourceSrv } from '@grafana/runtime';
2
- import { getDataSourceInstanceSettings as getDataSourceInstanceSettings$1 } from '@grafana/runtime/unstable';
1
+ import { getDataSourceInstanceSettings as getDataSourceInstanceSettings$1, getDataSourceSrv } from '@grafana/runtime';
2
+ import { getDataSourceInstanceSettings as getDataSourceInstanceSettings$2 } from '@grafana/runtime/unstable';
3
3
 
4
4
  "use strict";
5
5
  async function getDataSourceInstanceSettings(ref, scopedVars) {
6
6
  if (typeof getDataSourceInstanceSettings$1 === "function") {
7
7
  return getDataSourceInstanceSettings$1(ref, scopedVars);
8
8
  }
9
+ if (typeof getDataSourceInstanceSettings$2 === "function") {
10
+ return getDataSourceInstanceSettings$2(ref, scopedVars);
11
+ }
9
12
  return backwardsCompatibleDataSourceInstanceSettings(ref, scopedVars);
10
13
  }
11
14
  async function backwardsCompatibleDataSourceInstanceSettings(ref, scopedVars) {
@@ -1 +1 @@
1
- {"version":3,"file":"getDataSourceInstanceSettings.mjs","sources":["../../../src/datasources/getDataSourceInstanceSettings.ts"],"sourcesContent":["/* eslint-disable @grafana/no-get-data-source-srv */\nimport { type ScopedVars, type DataSourceInstanceSettings } from '@grafana/data';\nimport { getDataSourceSrv } from '@grafana/runtime';\nimport { getDataSourceInstanceSettings as rtGetDataSourceInstanceSettings } from '@grafana/runtime/unstable';\n\nimport { type Ref } from './types';\n\nexport async function getDataSourceInstanceSettings(\n ref?: Ref,\n scopedVars?: ScopedVars\n): Promise<DataSourceInstanceSettings | undefined> {\n if (typeof rtGetDataSourceInstanceSettings === 'function') {\n return rtGetDataSourceInstanceSettings(ref, scopedVars);\n }\n\n return backwardsCompatibleDataSourceInstanceSettings(ref, scopedVars);\n}\n\nasync function backwardsCompatibleDataSourceInstanceSettings(\n ref?: Ref,\n scopedVars?: ScopedVars\n): Promise<DataSourceInstanceSettings | undefined> {\n return getDataSourceSrv().getInstanceSettings(ref, scopedVars);\n}\n"],"names":["rtGetDataSourceInstanceSettings"],"mappings":";;;;AAOA,eAAsB,6BAAA,CACpB,KACA,UAAA,EACiD;AACjD,EAAA,IAAI,OAAOA,oCAAoC,UAAA,EAAY;AACzD,IAAA,OAAOA,+BAAA,CAAgC,KAAK,UAAU,CAAA;AAAA,EACxD;AAEA,EAAA,OAAO,6CAAA,CAA8C,KAAK,UAAU,CAAA;AACtE;AAEA,eAAe,6CAAA,CACb,KACA,UAAA,EACiD;AACjD,EAAA,OAAO,gBAAA,EAAiB,CAAE,mBAAA,CAAoB,GAAA,EAAK,UAAU,CAAA;AAC/D;;;;"}
1
+ {"version":3,"file":"getDataSourceInstanceSettings.mjs","sources":["../../../src/datasources/getDataSourceInstanceSettings.ts"],"sourcesContent":["/* eslint-disable @grafana/no-get-data-source-srv */\nimport { type ScopedVars, type DataSourceInstanceSettings } from '@grafana/data';\nimport {\n getDataSourceSrv,\n getDataSourceInstanceSettings as stableGetDataSourceInstanceSettings,\n} from '@grafana/runtime';\nimport { getDataSourceInstanceSettings as unstableGetDataSourceInstanceSettings } from '@grafana/runtime/unstable';\n\nimport { type Ref } from './types';\n\nexport async function getDataSourceInstanceSettings(\n ref?: Ref,\n scopedVars?: ScopedVars\n): Promise<DataSourceInstanceSettings | undefined> {\n if (typeof stableGetDataSourceInstanceSettings === 'function') {\n return stableGetDataSourceInstanceSettings(ref, scopedVars);\n }\n\n if (typeof unstableGetDataSourceInstanceSettings === 'function') {\n return unstableGetDataSourceInstanceSettings(ref, scopedVars);\n }\n\n return backwardsCompatibleDataSourceInstanceSettings(ref, scopedVars);\n}\n\nasync function backwardsCompatibleDataSourceInstanceSettings(\n ref?: Ref,\n scopedVars?: ScopedVars\n): Promise<DataSourceInstanceSettings | undefined> {\n return getDataSourceSrv().getInstanceSettings(ref, scopedVars);\n}\n"],"names":["stableGetDataSourceInstanceSettings","unstableGetDataSourceInstanceSettings"],"mappings":";;;;AAUA,eAAsB,6BAAA,CACpB,KACA,UAAA,EACiD;AACjD,EAAA,IAAI,OAAOA,oCAAwC,UAAA,EAAY;AAC7D,IAAA,OAAOA,+BAAA,CAAoC,KAAK,UAAU,CAAA;AAAA,EAC5D;AAEA,EAAA,IAAI,OAAOC,oCAA0C,UAAA,EAAY;AAC/D,IAAA,OAAOA,+BAAA,CAAsC,KAAK,UAAU,CAAA;AAAA,EAC9D;AAEA,EAAA,OAAO,6CAAA,CAA8C,KAAK,UAAU,CAAA;AACtE;AAEA,eAAe,6CAAA,CACb,KACA,UAAA,EACiD;AACjD,EAAA,OAAO,gBAAA,EAAiB,CAAE,mBAAA,CAAoB,GAAA,EAAK,UAAU,CAAA;AAC/D;;;;"}
@@ -1,15 +1,22 @@
1
- import { getDefaultDataSourceInstanceListItem as getDefaultDataSourceInstanceListItem$1 } from '@grafana/runtime/unstable';
1
+ import { getDefaultDataSourceInstanceListItem as getDefaultDataSourceInstanceListItem$1, getDataSourceSrv } from '@grafana/runtime';
2
+ import { getDefaultDataSourceInstanceListItem as getDefaultDataSourceInstanceListItem$2 } from '@grafana/runtime/unstable';
2
3
 
3
4
  "use strict";
4
5
  async function getDefaultDataSourceInstanceListItem(items) {
5
6
  if (typeof getDefaultDataSourceInstanceListItem$1 === "function") {
6
7
  return getDefaultDataSourceInstanceListItem$1(items);
7
8
  }
9
+ if (typeof getDefaultDataSourceInstanceListItem$2 === "function") {
10
+ return getDefaultDataSourceInstanceListItem$2(items);
11
+ }
8
12
  return backwardsCompatibleGetDefaultDataSourceInstanceListItem(items);
9
13
  }
10
- async function backwardsCompatibleGetDefaultDataSourceInstanceListItem(items) {
11
- return items.find((item) => item == null ? void 0 : item.isDefault);
14
+ function backwardsCompatibleGetDefaultDataSourceInstanceListItem(items) {
15
+ return items.find((item) => {
16
+ var _a;
17
+ return item && ((_a = getDataSourceSrv().getInstanceSettings(item.uid)) == null ? void 0 : _a.isDefault);
18
+ });
12
19
  }
13
20
 
14
- export { getDefaultDataSourceInstanceListItem };
21
+ export { backwardsCompatibleGetDefaultDataSourceInstanceListItem, getDefaultDataSourceInstanceListItem };
15
22
  //# sourceMappingURL=getDefaultDataSourceInstanceListItem.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"getDefaultDataSourceInstanceListItem.mjs","sources":["../../../src/datasources/getDefaultDataSourceInstanceListItem.ts"],"sourcesContent":["import { type DataSourceInstanceListItem } from '@grafana/data';\nimport { getDefaultDataSourceInstanceListItem as rtGetDefaultDataSourceInstanceListItem } from '@grafana/runtime/unstable';\n\n/**\n * Resolve the item flagged as the default data source, or `undefined` when the list holds none.\n *\n * At most one instance per org carries the flag, so a filtered list need not contain it.\n */\nexport async function getDefaultDataSourceInstanceListItem(\n items: DataSourceInstanceListItem[]\n): Promise<DataSourceInstanceListItem | undefined> {\n if (typeof rtGetDefaultDataSourceInstanceListItem === 'function') {\n return rtGetDefaultDataSourceInstanceListItem(items);\n }\n\n return backwardsCompatibleGetDefaultDataSourceInstanceListItem(items);\n}\n\nasync function backwardsCompatibleGetDefaultDataSourceInstanceListItem(\n items: DataSourceInstanceListItem[]\n): Promise<DataSourceInstanceListItem | undefined> {\n return items.find((item) => item?.isDefault);\n}\n"],"names":["rtGetDefaultDataSourceInstanceListItem"],"mappings":";;;AAQA,eAAsB,qCACpB,KAAA,EACiD;AACjD,EAAA,IAAI,OAAOA,2CAA2C,UAAA,EAAY;AAChE,IAAA,OAAOA,uCAAuC,KAAK,CAAA;AAAA,EACrD;AAEA,EAAA,OAAO,wDAAwD,KAAK,CAAA;AACtE;AAEA,eAAe,wDACb,KAAA,EACiD;AACjD,EAAA,OAAO,KAAA,CAAM,IAAA,CAAK,CAAC,IAAA,KAAS,6BAAM,SAAS,CAAA;AAC7C;;;;"}
1
+ {"version":3,"file":"getDefaultDataSourceInstanceListItem.mjs","sources":["../../../src/datasources/getDefaultDataSourceInstanceListItem.ts"],"sourcesContent":["/* eslint-disable @grafana/no-get-data-source-srv */\nimport { type DataSourceInstanceListItem } from '@grafana/data';\nimport {\n getDataSourceSrv,\n getDefaultDataSourceInstanceListItem as stableGetDefaultDataSourceInstanceListItem,\n} from '@grafana/runtime';\nimport { getDefaultDataSourceInstanceListItem as unstableGetDefaultDataSourceInstanceListItem } from '@grafana/runtime/unstable';\n\n/**\n * Resolve the item whose data source is the org default, or `undefined` when the list holds none.\n *\n * At most one instance per org carries the flag, so a filtered list need not contain it.\n */\nexport async function getDefaultDataSourceInstanceListItem(\n items: DataSourceInstanceListItem[]\n): Promise<DataSourceInstanceListItem | undefined> {\n if (typeof stableGetDefaultDataSourceInstanceListItem === 'function') {\n return stableGetDefaultDataSourceInstanceListItem(items);\n }\n\n if (typeof unstableGetDefaultDataSourceInstanceListItem === 'function') {\n return unstableGetDefaultDataSourceInstanceListItem(items);\n }\n\n return backwardsCompatibleGetDefaultDataSourceInstanceListItem(items);\n}\n\nexport function backwardsCompatibleGetDefaultDataSourceInstanceListItem(\n items: DataSourceInstanceListItem[]\n): DataSourceInstanceListItem | undefined {\n return items.find((item) => item && getDataSourceSrv().getInstanceSettings(item.uid)?.isDefault);\n}\n"],"names":["stableGetDefaultDataSourceInstanceListItem","unstableGetDefaultDataSourceInstanceListItem"],"mappings":";;;;AAaA,eAAsB,qCACpB,KAAA,EACiD;AACjD,EAAA,IAAI,OAAOA,2CAA+C,UAAA,EAAY;AACpE,IAAA,OAAOA,uCAA2C,KAAK,CAAA;AAAA,EACzD;AAEA,EAAA,IAAI,OAAOC,2CAAiD,UAAA,EAAY;AACtE,IAAA,OAAOA,uCAA6C,KAAK,CAAA;AAAA,EAC3D;AAEA,EAAA,OAAO,wDAAwD,KAAK,CAAA;AACtE;AAEO,SAAS,wDACd,KAAA,EACwC;AACxC,EAAA,OAAO,KAAA,CAAM,IAAA,CAAK,CAAC,IAAA,KAAM;AA9B3B,IAAA,IAAA,EAAA;AA8B8B,IAAA,OAAA,IAAA,KAAA,CAAQ,uBAAiB,CAAE,mBAAA,CAAoB,IAAA,CAAK,GAAG,MAA/C,IAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAkD,SAAA,CAAA;AAAA,EAAA,CAAS,CAAA;AACjG;;;;"}
@@ -0,0 +1,19 @@
1
+ import { registerRuntimeDataSourceInstance as registerRuntimeDataSourceInstance$1, getDataSourceSrv } from '@grafana/runtime';
2
+ import { registerRuntimeDataSourceInstance as registerRuntimeDataSourceInstance$2 } from '@grafana/runtime/unstable';
3
+
4
+ "use strict";
5
+ function registerRuntimeDataSourceInstance(entry) {
6
+ if (typeof registerRuntimeDataSourceInstance$1 === "function") {
7
+ return registerRuntimeDataSourceInstance$1(entry);
8
+ }
9
+ if (typeof registerRuntimeDataSourceInstance$2 === "function") {
10
+ return registerRuntimeDataSourceInstance$2(entry);
11
+ }
12
+ return backwardsCompatibleRegisterRuntimeDataSourceInstance(entry);
13
+ }
14
+ function backwardsCompatibleRegisterRuntimeDataSourceInstance(entry) {
15
+ return getDataSourceSrv().registerRuntimeDataSource(entry);
16
+ }
17
+
18
+ export { registerRuntimeDataSourceInstance };
19
+ //# sourceMappingURL=registerRuntimeDataSourceInstance.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registerRuntimeDataSourceInstance.mjs","sources":["../../../src/datasources/registerRuntimeDataSourceInstance.ts"],"sourcesContent":["/* eslint-disable @grafana/no-get-data-source-srv */\nimport {\n getDataSourceSrv,\n type RuntimeDataSourceRegistration,\n registerRuntimeDataSourceInstance as stableRegisterRuntimeDataSourceInstance,\n} from '@grafana/runtime';\nimport { registerRuntimeDataSourceInstance as unstableRegisterRuntimeDataSourceInstance } from '@grafana/runtime/unstable';\n\nexport function registerRuntimeDataSourceInstance(entry: RuntimeDataSourceRegistration): void {\n if (typeof stableRegisterRuntimeDataSourceInstance === 'function') {\n return stableRegisterRuntimeDataSourceInstance(entry);\n }\n\n if (typeof unstableRegisterRuntimeDataSourceInstance === 'function') {\n return unstableRegisterRuntimeDataSourceInstance(entry);\n }\n\n return backwardsCompatibleRegisterRuntimeDataSourceInstance(entry);\n}\n\nfunction backwardsCompatibleRegisterRuntimeDataSourceInstance(entry: RuntimeDataSourceRegistration): void {\n return getDataSourceSrv().registerRuntimeDataSource(entry);\n}\n"],"names":["stableRegisterRuntimeDataSourceInstance","unstableRegisterRuntimeDataSourceInstance"],"mappings":";;;;AAQO,SAAS,kCAAkC,KAAA,EAA4C;AAC5F,EAAA,IAAI,OAAOA,wCAA4C,UAAA,EAAY;AACjE,IAAA,OAAOA,oCAAwC,KAAK,CAAA;AAAA,EACtD;AAEA,EAAA,IAAI,OAAOC,wCAA8C,UAAA,EAAY;AACnE,IAAA,OAAOA,oCAA0C,KAAK,CAAA;AAAA,EACxD;AAEA,EAAA,OAAO,qDAAqD,KAAK,CAAA;AACnE;AAEA,SAAS,qDAAqD,KAAA,EAA4C;AACxG,EAAA,OAAO,gBAAA,EAAiB,CAAE,yBAAA,CAA0B,KAAK,CAAA;AAC3D;;;;"}
@@ -0,0 +1,26 @@
1
+ import { useState, useEffect } from 'react';
2
+ import { useDataSourceInstance as useDataSourceInstance$1 } from '@grafana/runtime';
3
+ import { useDataSourceInstance as useDataSourceInstance$2 } from '@grafana/runtime/unstable';
4
+ import { getDataSourceInstance } from './getDataSourceInstance.mjs';
5
+
6
+ "use strict";
7
+ const useDataSourceInstance = typeof useDataSourceInstance$1 === "function" ? useDataSourceInstance$1 : typeof useDataSourceInstance$2 === "function" ? useDataSourceInstance$2 : useBackwardsCompatibleDataSourceInstance;
8
+ function useBackwardsCompatibleDataSourceInstance(ref) {
9
+ const [result, setResult] = useState({ isLoading: true });
10
+ const refKey = JSON.stringify(ref != null ? ref : null);
11
+ useEffect(() => {
12
+ let isCurrent = true;
13
+ setResult((previous) => ({ ...previous, isLoading: true }));
14
+ getDataSourceInstance(ref).then(
15
+ (dataSource) => isCurrent && setResult({ isLoading: false, dataSource }),
16
+ (error) => isCurrent && setResult({ isLoading: false, error })
17
+ );
18
+ return () => {
19
+ isCurrent = false;
20
+ };
21
+ }, [refKey]);
22
+ return result;
23
+ }
24
+
25
+ export { useDataSourceInstance };
26
+ //# sourceMappingURL=useDataSourceInstance.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDataSourceInstance.mjs","sources":["../../../src/datasources/useDataSourceInstance.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport { type DataSourceApi } from '@grafana/data';\nimport { useDataSourceInstance as stableUseDataSourceInstance } from '@grafana/runtime';\nimport { useDataSourceInstance as unstableUseDataSourceInstance } from '@grafana/runtime/unstable';\n\nimport { getDataSourceInstance } from './getDataSourceInstance';\nimport { type Ref } from './types';\n\n/** Declared here because `@grafana/runtime` lacks it on older supported hosts. */\nexport interface UseDataSourceInstanceResult {\n isLoading: boolean;\n error?: Error;\n dataSource?: DataSourceApi;\n}\n\n/**\n * Uses the host hook when available. The fallback re-resolves only when `ref` changes, not on data source cache\n * changes. Picked once at load so the hook order stays stable.\n */\nexport const useDataSourceInstance: (ref?: Ref) => UseDataSourceInstanceResult =\n typeof stableUseDataSourceInstance === 'function'\n ? stableUseDataSourceInstance\n : typeof unstableUseDataSourceInstance === 'function'\n ? unstableUseDataSourceInstance\n : useBackwardsCompatibleDataSourceInstance;\n\nfunction useBackwardsCompatibleDataSourceInstance(ref?: Ref): UseDataSourceInstanceResult {\n const [result, setResult] = useState<UseDataSourceInstanceResult>({ isLoading: true });\n // Same key as the host hook, so inline ref objects don't refetch and `null` matches `undefined`.\n const refKey = JSON.stringify(ref ?? null);\n\n useEffect(() => {\n let isCurrent = true;\n setResult((previous) => ({ ...previous, isLoading: true }));\n\n getDataSourceInstance(ref).then(\n (dataSource) => isCurrent && setResult({ isLoading: false, dataSource }),\n (error: Error) => isCurrent && setResult({ isLoading: false, error })\n );\n\n return () => {\n isCurrent = false;\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [refKey]);\n\n return result;\n}\n"],"names":["stableUseDataSourceInstance","unstableUseDataSourceInstance"],"mappings":";;;;;;AAoBO,MAAM,qBAAA,GACX,OAAOA,uBAAA,KAAgC,UAAA,GACnCA,0BACA,OAAOC,uBAAA,KAAkC,aACvCA,uBAAA,GACA;AAER,SAAS,yCAAyC,GAAA,EAAwC;AACxF,EAAA,MAAM,CAAC,QAAQ,SAAS,CAAA,GAAI,SAAsC,EAAE,SAAA,EAAW,MAAM,CAAA;AAErF,EAAA,MAAM,MAAA,GAAS,IAAA,CAAK,SAAA,CAAU,GAAA,IAAA,IAAA,GAAA,GAAA,GAAO,IAAI,CAAA;AAEzC,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,IAAI,SAAA,GAAY,IAAA;AAChB,IAAA,SAAA,CAAU,CAAC,QAAA,MAAc,EAAE,GAAG,QAAA,EAAU,SAAA,EAAW,MAAK,CAAE,CAAA;AAE1D,IAAA,qBAAA,CAAsB,GAAG,CAAA,CAAE,IAAA;AAAA,MACzB,CAAC,eAAe,SAAA,IAAa,SAAA,CAAU,EAAE,SAAA,EAAW,KAAA,EAAO,YAAY,CAAA;AAAA,MACvE,CAAC,UAAiB,SAAA,IAAa,SAAA,CAAU,EAAE,SAAA,EAAW,KAAA,EAAO,OAAO;AAAA,KACtE;AAEA,IAAA,OAAO,MAAM;AACX,MAAA,SAAA,GAAY,KAAA;AAAA,IACd,CAAA;AAAA,EAEF,CAAA,EAAG,CAAC,MAAM,CAAC,CAAA;AAEX,EAAA,OAAO,MAAA;AACT;;;;"}
@@ -1,30 +1,11 @@
1
- import { useState, useEffect } from 'react';
2
- import { getDefaultDataSourceInstanceListItem } from './getDefaultDataSourceInstanceListItem.mjs';
1
+ import { useDefaultDataSourceInstanceListItem as useDefaultDataSourceInstanceListItem$1 } from '@grafana/runtime';
2
+ import { useDefaultDataSourceInstanceListItem as useDefaultDataSourceInstanceListItem$2 } from '@grafana/runtime/unstable';
3
+ import { backwardsCompatibleGetDefaultDataSourceInstanceListItem } from './getDefaultDataSourceInstanceListItem.mjs';
3
4
 
4
5
  "use strict";
5
- function useDefaultDataSourceInstanceListItem(items) {
6
- const [result, setResult] = useState({ isLoading: true });
7
- const itemsKey = JSON.stringify(items.map((item) => [item == null ? void 0 : item.uid, item == null ? void 0 : item.isDefault]));
8
- useEffect(() => {
9
- let active = true;
10
- setResult({ isLoading: true });
11
- getDefaultDataSourceInstanceListItem(items).then(
12
- (item) => {
13
- if (active) {
14
- setResult({ isLoading: false, item });
15
- }
16
- },
17
- (err) => {
18
- if (active) {
19
- setResult({ isLoading: false, error: err instanceof Error ? err : new Error(String(err)) });
20
- }
21
- }
22
- );
23
- return () => {
24
- active = false;
25
- };
26
- }, [itemsKey]);
27
- return result;
6
+ const useDefaultDataSourceInstanceListItem = typeof useDefaultDataSourceInstanceListItem$1 === "function" ? useDefaultDataSourceInstanceListItem$1 : typeof useDefaultDataSourceInstanceListItem$2 === "function" ? useDefaultDataSourceInstanceListItem$2 : useBackwardsCompatibleDefaultDataSourceInstanceListItem;
7
+ function useBackwardsCompatibleDefaultDataSourceInstanceListItem(items) {
8
+ return { isLoading: false, item: backwardsCompatibleGetDefaultDataSourceInstanceListItem(items) };
28
9
  }
29
10
 
30
11
  export { useDefaultDataSourceInstanceListItem };
@@ -1 +1 @@
1
- {"version":3,"file":"useDefaultDataSourceInstanceListItem.mjs","sources":["../../../src/datasources/useDefaultDataSourceInstanceListItem.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport { type DataSourceInstanceListItem } from '@grafana/data';\n\nimport { getDefaultDataSourceInstanceListItem } from './getDefaultDataSourceInstanceListItem';\n\n/** Declared here because `@grafana/runtime/unstable` lacks it on older supported hosts. */\nexport interface UseDefaultDataSourceInstanceListItemResult {\n isLoading: boolean;\n error?: Error;\n item?: DataSourceInstanceListItem;\n}\n\n/**\n * React hook wrapping {@link getDefaultDataSourceInstanceListItem}. Re-resolves when the uid or\n * `isDefault` flag of any item changes, so passing an inline array is safe.\n */\nexport function useDefaultDataSourceInstanceListItem(\n items: DataSourceInstanceListItem[]\n): UseDefaultDataSourceInstanceListItemResult {\n const [result, setResult] = useState<UseDefaultDataSourceInstanceListItemResult>({ isLoading: true });\n const itemsKey = JSON.stringify(items.map((item) => [item?.uid, item?.isDefault]));\n\n useEffect(() => {\n let active = true;\n setResult({ isLoading: true });\n\n getDefaultDataSourceInstanceListItem(items).then(\n (item) => {\n if (active) {\n setResult({ isLoading: false, item });\n }\n },\n (err: unknown) => {\n if (active) {\n setResult({ isLoading: false, error: err instanceof Error ? err : new Error(String(err)) });\n }\n }\n );\n\n return () => {\n active = false;\n };\n // Keyed by uid and flag, the only fields the resolver reads.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [itemsKey]);\n\n return result;\n}\n"],"names":[],"mappings":";;;;AAiBO,SAAS,qCACd,KAAA,EAC4C;AAC5C,EAAA,MAAM,CAAC,QAAQ,SAAS,CAAA,GAAI,SAAqD,EAAE,SAAA,EAAW,MAAM,CAAA;AACpG,EAAA,MAAM,QAAA,GAAW,IAAA,CAAK,SAAA,CAAU,KAAA,CAAM,GAAA,CAAI,CAAC,IAAA,KAAS,CAAC,IAAA,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,IAAA,CAAM,GAAA,EAAK,IAAA,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,IAAA,CAAM,SAAS,CAAC,CAAC,CAAA;AAEjF,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,IAAI,MAAA,GAAS,IAAA;AACb,IAAA,SAAA,CAAU,EAAE,SAAA,EAAW,IAAA,EAAM,CAAA;AAE7B,IAAA,oCAAA,CAAqC,KAAK,CAAA,CAAE,IAAA;AAAA,MAC1C,CAAC,IAAA,KAAS;AACR,QAAA,IAAI,MAAA,EAAQ;AACV,UAAA,SAAA,CAAU,EAAE,SAAA,EAAW,KAAA,EAAO,IAAA,EAAM,CAAA;AAAA,QACtC;AAAA,MACF,CAAA;AAAA,MACA,CAAC,GAAA,KAAiB;AAChB,QAAA,IAAI,MAAA,EAAQ;AACV,UAAA,SAAA,CAAU,EAAE,SAAA,EAAW,KAAA,EAAO,KAAA,EAAO,GAAA,YAAe,KAAA,GAAQ,GAAA,GAAM,IAAI,KAAA,CAAM,MAAA,CAAO,GAAG,CAAC,GAAG,CAAA;AAAA,QAC5F;AAAA,MACF;AAAA,KACF;AAEA,IAAA,OAAO,MAAM;AACX,MAAA,MAAA,GAAS,KAAA;AAAA,IACX,CAAA;AAAA,EAGF,CAAA,EAAG,CAAC,QAAQ,CAAC,CAAA;AAEb,EAAA,OAAO,MAAA;AACT;;;;"}
1
+ {"version":3,"file":"useDefaultDataSourceInstanceListItem.mjs","sources":["../../../src/datasources/useDefaultDataSourceInstanceListItem.ts"],"sourcesContent":["import { type DataSourceInstanceListItem } from '@grafana/data';\nimport { useDefaultDataSourceInstanceListItem as stableUseDefaultDataSourceInstanceListItem } from '@grafana/runtime';\nimport { useDefaultDataSourceInstanceListItem as unstableUseDefaultDataSourceInstanceListItem } from '@grafana/runtime/unstable';\n\nimport { backwardsCompatibleGetDefaultDataSourceInstanceListItem } from './getDefaultDataSourceInstanceListItem';\n\n/** Declared here because `@grafana/runtime` lacks it on older supported hosts. */\nexport interface UseDefaultDataSourceInstanceListItemResult {\n isLoading: boolean;\n error?: Error;\n item?: DataSourceInstanceListItem;\n}\n\n/**\n * Uses the host hook when available, which also re-resolves on data source cache changes; otherwise\n * resolves synchronously on every render. Picked once at load so the hook order stays stable.\n */\nexport const useDefaultDataSourceInstanceListItem: (\n items: DataSourceInstanceListItem[]\n) => UseDefaultDataSourceInstanceListItemResult =\n typeof stableUseDefaultDataSourceInstanceListItem === 'function'\n ? stableUseDefaultDataSourceInstanceListItem\n : typeof unstableUseDefaultDataSourceInstanceListItem === 'function'\n ? unstableUseDefaultDataSourceInstanceListItem\n : useBackwardsCompatibleDefaultDataSourceInstanceListItem;\n\nfunction useBackwardsCompatibleDefaultDataSourceInstanceListItem(\n items: DataSourceInstanceListItem[]\n): UseDefaultDataSourceInstanceListItemResult {\n return { isLoading: false, item: backwardsCompatibleGetDefaultDataSourceInstanceListItem(items) };\n}\n"],"names":["stableUseDefaultDataSourceInstanceListItem","unstableUseDefaultDataSourceInstanceListItem"],"mappings":";;;;;AAiBO,MAAM,oCAAA,GAGX,OAAOA,sCAAA,KAA+C,UAAA,GAClDA,yCACA,OAAOC,sCAAA,KAAiD,aACtDA,sCAAA,GACA;AAER,SAAS,wDACP,KAAA,EAC4C;AAC5C,EAAA,OAAO,EAAE,SAAA,EAAW,KAAA,EAAO,IAAA,EAAM,uDAAA,CAAwD,KAAK,CAAA,EAAE;AAClG;;;;"}
@@ -2,6 +2,8 @@ export { getDataSourceInstance } from './datasources/getDataSourceInstance.mjs';
2
2
  export { getDataSourceInstanceList } from './datasources/getDataSourceInstanceList.mjs';
3
3
  export { getDataSourceInstanceSettings } from './datasources/getDataSourceInstanceSettings.mjs';
4
4
  export { getDefaultDataSourceInstanceListItem } from './datasources/getDefaultDataSourceInstanceListItem.mjs';
5
+ export { registerRuntimeDataSourceInstance } from './datasources/registerRuntimeDataSourceInstance.mjs';
6
+ export { useDataSourceInstance } from './datasources/useDataSourceInstance.mjs';
5
7
  export { useDefaultDataSourceInstanceListItem } from './datasources/useDefaultDataSourceInstanceListItem.mjs';
6
8
 
7
9
  "use strict";
@@ -1 +1 @@
1
- {"version":3,"file":"datasources.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
1
+ {"version":3,"file":"datasources.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
@@ -1,7 +1,8 @@
1
1
  import { type DataSourceInstanceListItem } from '@grafana/data';
2
2
  /**
3
- * Resolve the item flagged as the default data source, or `undefined` when the list holds none.
3
+ * Resolve the item whose data source is the org default, or `undefined` when the list holds none.
4
4
  *
5
5
  * At most one instance per org carries the flag, so a filtered list need not contain it.
6
6
  */
7
7
  export declare function getDefaultDataSourceInstanceListItem(items: DataSourceInstanceListItem[]): Promise<DataSourceInstanceListItem | undefined>;
8
+ export declare function backwardsCompatibleGetDefaultDataSourceInstanceListItem(items: DataSourceInstanceListItem[]): DataSourceInstanceListItem | undefined;
@@ -0,0 +1,2 @@
1
+ import { type RuntimeDataSourceRegistration } from '@grafana/runtime';
2
+ export declare function registerRuntimeDataSourceInstance(entry: RuntimeDataSourceRegistration): void;
@@ -0,0 +1,13 @@
1
+ import { type DataSourceApi } from '@grafana/data';
2
+ import { type Ref } from './types';
3
+ /** Declared here because `@grafana/runtime` lacks it on older supported hosts. */
4
+ export interface UseDataSourceInstanceResult {
5
+ isLoading: boolean;
6
+ error?: Error;
7
+ dataSource?: DataSourceApi;
8
+ }
9
+ /**
10
+ * Uses the host hook when available. The fallback re-resolves only when `ref` changes, not on data source cache
11
+ * changes. Picked once at load so the hook order stays stable.
12
+ */
13
+ export declare const useDataSourceInstance: (ref?: Ref) => UseDataSourceInstanceResult;
@@ -1,12 +1,12 @@
1
1
  import { type DataSourceInstanceListItem } from '@grafana/data';
2
- /** Declared here because `@grafana/runtime/unstable` lacks it on older supported hosts. */
2
+ /** Declared here because `@grafana/runtime` lacks it on older supported hosts. */
3
3
  export interface UseDefaultDataSourceInstanceListItemResult {
4
4
  isLoading: boolean;
5
5
  error?: Error;
6
6
  item?: DataSourceInstanceListItem;
7
7
  }
8
8
  /**
9
- * React hook wrapping {@link getDefaultDataSourceInstanceListItem}. Re-resolves when the uid or
10
- * `isDefault` flag of any item changes, so passing an inline array is safe.
9
+ * Uses the host hook when available, which also re-resolves on data source cache changes; otherwise
10
+ * resolves synchronously on every render. Picked once at load so the hook order stays stable.
11
11
  */
12
- export declare function useDefaultDataSourceInstanceListItem(items: DataSourceInstanceListItem[]): UseDefaultDataSourceInstanceListItemResult;
12
+ export declare const useDefaultDataSourceInstanceListItem: (items: DataSourceInstanceListItem[]) => UseDefaultDataSourceInstanceListItemResult;
@@ -2,4 +2,6 @@ export { getDataSourceInstance } from './datasources/getDataSourceInstance';
2
2
  export { getDataSourceInstanceList } from './datasources/getDataSourceInstanceList';
3
3
  export { getDataSourceInstanceSettings } from './datasources/getDataSourceInstanceSettings';
4
4
  export { getDefaultDataSourceInstanceListItem } from './datasources/getDefaultDataSourceInstanceListItem';
5
+ export { registerRuntimeDataSourceInstance } from './datasources/registerRuntimeDataSourceInstance';
6
+ export { useDataSourceInstance, type UseDataSourceInstanceResult } from './datasources/useDataSourceInstance';
5
7
  export { useDefaultDataSourceInstanceListItem, type UseDefaultDataSourceInstanceListItemResult, } from './datasources/useDefaultDataSourceInstanceListItem';
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "author": "Grafana Labs",
3
3
  "license": "Apache-2.0",
4
4
  "name": "@grafana/plugin-compat",
5
- "version": "0.2.0",
5
+ "version": "0.5.0",
6
6
  "description": "Compatibility shims that let Grafana plugins adopt new Grafana host APIs across a range of host versions",
7
7
  "keywords": [
8
8
  "grafana",
@@ -72,5 +72,5 @@
72
72
  "@grafana/schema": ">=12.0.0",
73
73
  "react": ">=18"
74
74
  },
75
- "gitHead": "5746c84fbace9e69aa758c72f4b35df51016437c"
75
+ "gitHead": "e664af940679e7ccfe3106ac9fb0d11a82f03ed2"
76
76
  }