@grafana/plugin-compat 0.1.0 → 0.2.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 +5 -1
- package/README.md +2 -0
- package/dist/cjs/apps.cjs +34 -0
- package/dist/cjs/apps.cjs.map +1 -0
- package/dist/cjs/datasources/getDataSourceInstance.cjs +20 -0
- package/dist/cjs/datasources/getDataSourceInstance.cjs.map +1 -0
- package/dist/cjs/datasources/getDataSourceInstanceList.cjs +33 -0
- package/dist/cjs/datasources/getDataSourceInstanceList.cjs.map +1 -0
- package/dist/cjs/datasources/getDataSourceInstanceSettings.cjs +20 -0
- package/dist/cjs/datasources/getDataSourceInstanceSettings.cjs.map +1 -0
- package/dist/cjs/datasources/getDefaultDataSourceInstanceListItem.cjs +19 -0
- package/dist/cjs/datasources/getDefaultDataSourceInstanceListItem.cjs.map +1 -0
- package/dist/cjs/datasources/useDefaultDataSourceInstanceListItem.cjs +35 -0
- package/dist/cjs/datasources/useDefaultDataSourceInstanceListItem.cjs.map +1 -0
- package/dist/cjs/datasources.cjs +18 -0
- package/dist/cjs/datasources.cjs.map +1 -0
- package/package.json +14 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
# 0.2.0 (2026-09-23)
|
|
2
|
+
|
|
3
|
+
Add a CommonJS build alongside the existing ESM build, so the package works with `require` as well as `import`.
|
|
4
|
+
|
|
1
5
|
# 0.1.0 (2026-09-22)
|
|
2
6
|
|
|
3
|
-
Initial release. `@grafana/plugin-compat` is in **ALPHA**; the API may change between minor versions.
|
|
7
|
+
Initial release. `@grafana/plugin-compat` is in **ALPHA**; the API may change between minor versions.
|
package/README.md
CHANGED
|
@@ -11,6 +11,8 @@ Each function checks for the new host API at runtime and falls back to the
|
|
|
11
11
|
legacy equivalent when it's not available, so a single call works across
|
|
12
12
|
Grafana versions.
|
|
13
13
|
|
|
14
|
+
Ships both ESM and CommonJS builds, so it works with `import` and `require`.
|
|
15
|
+
|
|
14
16
|
## Domains
|
|
15
17
|
|
|
16
18
|
- `@grafana/plugin-compat/datasources` — `getDataSourceInstance`,
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
async function getPluginSettings(pluginId, showErrorAlert = false) {
|
|
10
|
+
if (typeof unstable.getPluginSettings === "function") {
|
|
11
|
+
return unstable.getPluginSettings(pluginId, showErrorAlert);
|
|
12
|
+
}
|
|
13
|
+
return backwardsCompatibleGetPluginSettings(pluginId, showErrorAlert);
|
|
14
|
+
}
|
|
15
|
+
async function backwardsCompatibleGetPluginSettings(pluginId, showErrorAlert = false) {
|
|
16
|
+
return runtime.getBackendSrv().get(`/api/plugins/${pluginId}/settings`, void 0, void 0, {
|
|
17
|
+
showErrorAlert,
|
|
18
|
+
validatePath: true
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
async function updateAppPluginSettings(pluginId, data) {
|
|
22
|
+
if (typeof unstable.updateAppPluginSettings === "function") {
|
|
23
|
+
return unstable.updateAppPluginSettings(pluginId, data);
|
|
24
|
+
}
|
|
25
|
+
return backwardsCompatibleUpdatePluginSettings(pluginId, data);
|
|
26
|
+
}
|
|
27
|
+
async function backwardsCompatibleUpdatePluginSettings(pluginId, data) {
|
|
28
|
+
await runtime.getBackendSrv().post(`/api/plugins/${pluginId}/settings`, data, { validatePath: true });
|
|
29
|
+
return backwardsCompatibleGetPluginSettings(pluginId);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
exports.getPluginSettings = getPluginSettings;
|
|
33
|
+
exports.updateAppPluginSettings = updateAppPluginSettings;
|
|
34
|
+
//# sourceMappingURL=apps.cjs.map
|
|
@@ -0,0 +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;;;;;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
async function getDataSourceInstance(ref, scopedVars) {
|
|
10
|
+
if (typeof unstable.getDataSourceInstance === "function") {
|
|
11
|
+
return unstable.getDataSourceInstance(ref, scopedVars);
|
|
12
|
+
}
|
|
13
|
+
return backwardsCompatibleGetDataSourceInstance(ref, scopedVars);
|
|
14
|
+
}
|
|
15
|
+
async function backwardsCompatibleGetDataSourceInstance(ref, scopedVars) {
|
|
16
|
+
return runtime.getDataSourceSrv().get(ref, scopedVars);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
exports.getDataSourceInstance = getDataSourceInstance;
|
|
20
|
+
//# sourceMappingURL=getDataSourceInstance.cjs.map
|
|
@@ -0,0 +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;;;;"}
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
async function getDataSourceInstanceList(filters) {
|
|
10
|
+
if (typeof unstable.getDataSourceInstanceList === "function") {
|
|
11
|
+
return unstable.getDataSourceInstanceList(filters);
|
|
12
|
+
}
|
|
13
|
+
return backwardsCompatibleGetDataSourceInstanceList(filters);
|
|
14
|
+
}
|
|
15
|
+
async function backwardsCompatibleGetDataSourceInstanceList(filters) {
|
|
16
|
+
const { filter, ...rest } = filters != null ? filters : {};
|
|
17
|
+
const legacyFilters = filter ? { ...rest, filter: (item) => filter(toDataSourceInstanceListItem(item)) } : { ...rest };
|
|
18
|
+
return runtime.getDataSourceSrv().getList(legacyFilters).map(toDataSourceInstanceListItem);
|
|
19
|
+
}
|
|
20
|
+
function toDataSourceInstanceListItem(item) {
|
|
21
|
+
var _a;
|
|
22
|
+
return {
|
|
23
|
+
isDefault: (_a = item.isDefault) != null ? _a : false,
|
|
24
|
+
meta: { ...item.meta },
|
|
25
|
+
name: item.name,
|
|
26
|
+
type: item.type,
|
|
27
|
+
uid: item.uid,
|
|
28
|
+
apiVersion: item.apiVersion
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
exports.getDataSourceInstanceList = getDataSourceInstanceList;
|
|
33
|
+
//# sourceMappingURL=getDataSourceInstanceList.cjs.map
|
|
@@ -0,0 +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;;;;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
async function getDataSourceInstanceSettings(ref, scopedVars) {
|
|
10
|
+
if (typeof unstable.getDataSourceInstanceSettings === "function") {
|
|
11
|
+
return unstable.getDataSourceInstanceSettings(ref, scopedVars);
|
|
12
|
+
}
|
|
13
|
+
return backwardsCompatibleDataSourceInstanceSettings(ref, scopedVars);
|
|
14
|
+
}
|
|
15
|
+
async function backwardsCompatibleDataSourceInstanceSettings(ref, scopedVars) {
|
|
16
|
+
return runtime.getDataSourceSrv().getInstanceSettings(ref, scopedVars);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
exports.getDataSourceInstanceSettings = getDataSourceInstanceSettings;
|
|
20
|
+
//# sourceMappingURL=getDataSourceInstanceSettings.cjs.map
|
|
@@ -0,0 +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;;;;"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var unstable = require('@grafana/runtime/unstable');
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
async function getDefaultDataSourceInstanceListItem(items) {
|
|
9
|
+
if (typeof unstable.getDefaultDataSourceInstanceListItem === "function") {
|
|
10
|
+
return unstable.getDefaultDataSourceInstanceListItem(items);
|
|
11
|
+
}
|
|
12
|
+
return backwardsCompatibleGetDefaultDataSourceInstanceListItem(items);
|
|
13
|
+
}
|
|
14
|
+
async function backwardsCompatibleGetDefaultDataSourceInstanceListItem(items) {
|
|
15
|
+
return items.find((item) => item == null ? void 0 : item.isDefault);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
exports.getDefaultDataSourceInstanceListItem = getDefaultDataSourceInstanceListItem;
|
|
19
|
+
//# sourceMappingURL=getDefaultDataSourceInstanceListItem.cjs.map
|
|
@@ -0,0 +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;;;;"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var react = require('react');
|
|
6
|
+
var getDefaultDataSourceInstanceListItem = require('./getDefaultDataSourceInstanceListItem.cjs');
|
|
7
|
+
|
|
8
|
+
"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;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
exports.useDefaultDataSourceInstanceListItem = useDefaultDataSourceInstanceListItem;
|
|
35
|
+
//# sourceMappingURL=useDefaultDataSourceInstanceListItem.cjs.map
|
|
@@ -0,0 +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;;;;"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var getDataSourceInstance = require('./datasources/getDataSourceInstance.cjs');
|
|
6
|
+
var getDataSourceInstanceList = require('./datasources/getDataSourceInstanceList.cjs');
|
|
7
|
+
var getDataSourceInstanceSettings = require('./datasources/getDataSourceInstanceSettings.cjs');
|
|
8
|
+
var getDefaultDataSourceInstanceListItem = require('./datasources/getDefaultDataSourceInstanceListItem.cjs');
|
|
9
|
+
var useDefaultDataSourceInstanceListItem = require('./datasources/useDefaultDataSourceInstanceListItem.cjs');
|
|
10
|
+
|
|
11
|
+
"use strict";
|
|
12
|
+
|
|
13
|
+
exports.getDataSourceInstance = getDataSourceInstance.getDataSourceInstance;
|
|
14
|
+
exports.getDataSourceInstanceList = getDataSourceInstanceList.getDataSourceInstanceList;
|
|
15
|
+
exports.getDataSourceInstanceSettings = getDataSourceInstanceSettings.getDataSourceInstanceSettings;
|
|
16
|
+
exports.getDefaultDataSourceInstanceListItem = getDefaultDataSourceInstanceListItem.getDefaultDataSourceInstanceListItem;
|
|
17
|
+
exports.useDefaultDataSourceInstanceListItem = useDefaultDataSourceInstanceListItem.useDefaultDataSourceInstanceListItem;
|
|
18
|
+
//# sourceMappingURL=datasources.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datasources.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;"}
|
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.2.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",
|
|
@@ -16,18 +16,21 @@
|
|
|
16
16
|
"url": "http://github.com/grafana/grafana.git",
|
|
17
17
|
"directory": "packages/grafana-plugin-compat"
|
|
18
18
|
},
|
|
19
|
+
"main": "./dist/cjs/datasources.cjs",
|
|
19
20
|
"module": "./dist/esm/datasources.mjs",
|
|
20
21
|
"exports": {
|
|
21
22
|
"./package.json": "./package.json",
|
|
22
23
|
"./datasources": {
|
|
23
24
|
"@grafana-app/source": "./src/datasources.ts",
|
|
24
25
|
"types": "./dist/types/datasources.d.ts",
|
|
25
|
-
"import": "./dist/esm/datasources.mjs"
|
|
26
|
+
"import": "./dist/esm/datasources.mjs",
|
|
27
|
+
"require": "./dist/cjs/datasources.cjs"
|
|
26
28
|
},
|
|
27
29
|
"./apps": {
|
|
28
30
|
"@grafana-app/source": "./src/apps.ts",
|
|
29
31
|
"types": "./dist/types/apps.d.ts",
|
|
30
|
-
"import": "./dist/esm/apps.mjs"
|
|
32
|
+
"import": "./dist/esm/apps.mjs",
|
|
33
|
+
"require": "./dist/cjs/apps.cjs"
|
|
31
34
|
}
|
|
32
35
|
},
|
|
33
36
|
"publishConfig": {
|
|
@@ -48,8 +51,15 @@
|
|
|
48
51
|
"postpack": "mv package.json.bak package.json"
|
|
49
52
|
},
|
|
50
53
|
"devDependencies": {
|
|
54
|
+
"@grafana/data": "13.3.0-pre",
|
|
55
|
+
"@grafana/runtime": "13.3.0-pre",
|
|
56
|
+
"@grafana/schema": "13.3.0-pre",
|
|
57
|
+
"@testing-library/dom": "10.4.1",
|
|
51
58
|
"@testing-library/react": "16.3.0",
|
|
59
|
+
"@types/react": "19.2.18",
|
|
52
60
|
"@typescript/native": "npm:typescript@^7.0.2",
|
|
61
|
+
"react": "19.2.8",
|
|
62
|
+
"react-dom": "19.2.8",
|
|
53
63
|
"rimraf": "^6.0.1",
|
|
54
64
|
"rollup": "^4.60.1",
|
|
55
65
|
"rollup-plugin-esbuild": "6.2.1",
|
|
@@ -62,5 +72,5 @@
|
|
|
62
72
|
"@grafana/schema": ">=12.0.0",
|
|
63
73
|
"react": ">=18"
|
|
64
74
|
},
|
|
65
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "5746c84fbace9e69aa758c72f4b35df51016437c"
|
|
66
76
|
}
|