@grafana/plugin-compat 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +10 -2
- package/dist/cjs/datasources/getDataSourceInstance.cjs +3 -0
- package/dist/cjs/datasources/getDataSourceInstance.cjs.map +1 -1
- package/dist/cjs/datasources/getDataSourceInstanceList.cjs +3 -2
- package/dist/cjs/datasources/getDataSourceInstanceList.cjs.map +1 -1
- package/dist/cjs/datasources/getDataSourceInstanceSettings.cjs +3 -0
- package/dist/cjs/datasources/getDataSourceInstanceSettings.cjs.map +1 -1
- package/dist/cjs/datasources/getDefaultDataSourceInstanceListItem.cjs +10 -2
- package/dist/cjs/datasources/getDefaultDataSourceInstanceListItem.cjs.map +1 -1
- package/dist/cjs/datasources/registerRuntimeDataSourceInstance.cjs +23 -0
- package/dist/cjs/datasources/registerRuntimeDataSourceInstance.cjs.map +1 -0
- package/dist/cjs/datasources/useDefaultDataSourceInstanceListItem.cjs +5 -24
- package/dist/cjs/datasources/useDefaultDataSourceInstanceListItem.cjs.map +1 -1
- package/dist/cjs/datasources.cjs +2 -0
- package/dist/cjs/datasources.cjs.map +1 -1
- package/dist/esm/datasources/getDataSourceInstance.mjs +5 -2
- package/dist/esm/datasources/getDataSourceInstance.mjs.map +1 -1
- package/dist/esm/datasources/getDataSourceInstanceList.mjs +5 -4
- package/dist/esm/datasources/getDataSourceInstanceList.mjs.map +1 -1
- package/dist/esm/datasources/getDataSourceInstanceSettings.mjs +5 -2
- package/dist/esm/datasources/getDataSourceInstanceSettings.mjs.map +1 -1
- package/dist/esm/datasources/getDefaultDataSourceInstanceListItem.mjs +11 -4
- package/dist/esm/datasources/getDefaultDataSourceInstanceListItem.mjs.map +1 -1
- package/dist/esm/datasources/registerRuntimeDataSourceInstance.mjs +19 -0
- package/dist/esm/datasources/registerRuntimeDataSourceInstance.mjs.map +1 -0
- package/dist/esm/datasources/useDefaultDataSourceInstanceListItem.mjs +6 -25
- package/dist/esm/datasources/useDefaultDataSourceInstanceListItem.mjs.map +1 -1
- package/dist/esm/datasources.mjs +1 -0
- package/dist/esm/datasources.mjs.map +1 -1
- package/dist/types/datasources/getDefaultDataSourceInstanceListItem.d.ts +2 -1
- package/dist/types/datasources/registerRuntimeDataSourceInstance.d.ts +2 -0
- package/dist/types/datasources/useDefaultDataSourceInstanceListItem.d.ts +4 -4
- package/dist/types/datasources.d.ts +1 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
# 0.4.0 (2026-10-09)
|
|
2
|
+
|
|
3
|
+
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`.
|
|
4
|
+
|
|
5
|
+
# 0.3.0 (2026-10-08)
|
|
6
|
+
|
|
7
|
+
Add `registerRuntimeDataSourceInstance` to `@grafana/plugin-compat/datasources`. It uses the host's async registry when available and falls back to `getDataSourceSrv().registerRuntimeDataSource` otherwise.
|
|
8
|
+
|
|
1
9
|
# 0.2.0 (2026-09-23)
|
|
2
10
|
|
|
3
11
|
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
|
|
22
|
-
`getDataSourceSrv()`
|
|
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.
|
|
@@ -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
|
|
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 {
|
|
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 {
|
|
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
|
-
|
|
15
|
-
return items.find((item) =>
|
|
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":["
|
|
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;;;;"}
|
|
@@ -2,33 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
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
|
|
10
|
-
|
|
11
|
-
|
|
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 {
|
|
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;;;;"}
|
package/dist/cjs/datasources.cjs
CHANGED
|
@@ -6,6 +6,7 @@ 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');
|
|
9
10
|
var useDefaultDataSourceInstanceListItem = require('./datasources/useDefaultDataSourceInstanceListItem.cjs');
|
|
10
11
|
|
|
11
12
|
"use strict";
|
|
@@ -14,5 +15,6 @@ exports.getDataSourceInstance = getDataSourceInstance.getDataSourceInstance;
|
|
|
14
15
|
exports.getDataSourceInstanceList = getDataSourceInstanceList.getDataSourceInstanceList;
|
|
15
16
|
exports.getDataSourceInstanceSettings = getDataSourceInstanceSettings.getDataSourceInstanceSettings;
|
|
16
17
|
exports.getDefaultDataSourceInstanceListItem = getDefaultDataSourceInstanceListItem.getDefaultDataSourceInstanceListItem;
|
|
18
|
+
exports.registerRuntimeDataSourceInstance = registerRuntimeDataSourceInstance.registerRuntimeDataSourceInstance;
|
|
17
19
|
exports.useDefaultDataSourceInstanceListItem = useDefaultDataSourceInstanceListItem.useDefaultDataSourceInstanceListItem;
|
|
18
20
|
//# 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":";;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { getDataSourceSrv } from '@grafana/runtime';
|
|
2
|
-
import { getDataSourceInstance as getDataSourceInstance$
|
|
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
|
|
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
|
+
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 {
|
|
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
|
+
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 {
|
|
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
|
|
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
|
-
|
|
11
|
-
return items.find((item) =>
|
|
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":["
|
|
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;;;;"}
|
|
@@ -1,30 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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
|
|
6
|
-
|
|
7
|
-
|
|
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 {
|
|
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;;;;"}
|
package/dist/esm/datasources.mjs
CHANGED
|
@@ -2,6 +2,7 @@ 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';
|
|
5
6
|
export { useDefaultDataSourceInstanceListItem } from './datasources/useDefaultDataSourceInstanceListItem.mjs';
|
|
6
7
|
|
|
7
8
|
"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
|
|
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;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { type DataSourceInstanceListItem } from '@grafana/data';
|
|
2
|
-
/** Declared here because `@grafana/runtime
|
|
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
|
-
*
|
|
10
|
-
*
|
|
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
|
|
12
|
+
export declare const useDefaultDataSourceInstanceListItem: (items: DataSourceInstanceListItem[]) => UseDefaultDataSourceInstanceListItemResult;
|
|
@@ -2,4 +2,5 @@ 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';
|
|
5
6
|
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.
|
|
5
|
+
"version": "0.4.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": "
|
|
75
|
+
"gitHead": "891f7973f81c6e4e0a24bed3120cca3b3cc93ebc"
|
|
76
76
|
}
|