@perses-dev/plugin-system 0.8.0 → 0.9.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/dist/cjs/components/PluginRegistry/PluginRegistry.js +43 -29
- package/dist/cjs/components/PluginRegistry/PluginRegistry.test.js +114 -38
- package/dist/cjs/components/PluginRegistry/index.js +17 -18
- package/dist/cjs/components/PluginRegistry/plugin-indexes.js +23 -20
- package/dist/cjs/components/PluginRegistry/plugin-registry-model.js +17 -7
- package/dist/cjs/components/PluginRegistry/test-plugins/bert/index.js +22 -12
- package/dist/cjs/components/PluginRegistry/test-plugins/ernie/index.js +20 -8
- package/dist/cjs/components/PluginRegistry/test-plugins/index.js +59 -39
- package/dist/cjs/components/index.js +17 -20
- package/dist/cjs/index.js +19 -20
- package/dist/cjs/model/datasource.js +16 -0
- package/dist/cjs/model/index.js +21 -21
- package/dist/cjs/model/panels.js +4 -21
- package/dist/cjs/model/plugins.js +4 -7
- package/dist/cjs/model/time-series-queries.js +16 -0
- package/dist/cjs/model/variables.js +5 -17
- package/dist/cjs/model/visual-editing.js +10 -2
- package/dist/cjs/runtime/datasources.js +20 -13
- package/dist/cjs/runtime/index.js +22 -21
- package/dist/cjs/runtime/plugins.js +25 -22
- package/dist/cjs/runtime/query-string.js +17 -10
- package/dist/cjs/runtime/template-variables.js +34 -16
- package/dist/cjs/runtime/time-range.js +17 -10
- package/dist/cjs/runtime/time-series-queries.js +58 -0
- package/dist/cjs/test/render.js +32 -13
- package/dist/cjs/test/setup-tests.js +4 -10
- package/dist/cjs/utils/cache-keys.js +8 -7
- package/dist/components/PluginRegistry/PluginRegistry.js +81 -1
- package/dist/components/PluginRegistry/PluginRegistry.js.map +1 -0
- package/dist/components/PluginRegistry/PluginRegistry.test.js +142 -1
- package/dist/components/PluginRegistry/PluginRegistry.test.js.map +1 -0
- package/dist/components/PluginRegistry/index.js +16 -1
- package/dist/components/PluginRegistry/index.js.map +1 -0
- package/dist/components/PluginRegistry/plugin-indexes.js +66 -1
- package/dist/components/PluginRegistry/plugin-indexes.js.map +1 -0
- package/dist/components/PluginRegistry/plugin-registry-model.d.ts +1 -2
- package/dist/components/PluginRegistry/plugin-registry-model.d.ts.map +1 -1
- package/dist/components/PluginRegistry/plugin-registry-model.js +23 -1
- package/dist/components/PluginRegistry/plugin-registry-model.js.map +1 -0
- package/dist/components/PluginRegistry/test-plugins/bert/index.js +25 -1
- package/dist/components/PluginRegistry/test-plugins/bert/index.js.map +1 -0
- package/dist/components/PluginRegistry/test-plugins/ernie/index.d.ts.map +1 -1
- package/dist/components/PluginRegistry/test-plugins/ernie/index.js +30 -1
- package/dist/components/PluginRegistry/test-plugins/ernie/index.js.map +1 -0
- package/dist/components/PluginRegistry/test-plugins/index.js +35 -1
- package/dist/components/PluginRegistry/test-plugins/index.js.map +1 -0
- package/dist/components/index.d.ts +1 -3
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +15 -1
- package/dist/components/index.js.map +1 -0
- package/dist/index.js +17 -1
- package/dist/index.js.map +1 -0
- package/dist/model/datasource.d.ts +9 -0
- package/dist/model/datasource.d.ts.map +1 -0
- package/dist/model/datasource.js +15 -0
- package/dist/model/datasource.js.map +1 -0
- package/dist/model/index.d.ts +2 -1
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +20 -1
- package/dist/model/index.js.map +1 -0
- package/dist/model/panels.d.ts +7 -11
- package/dist/model/panels.d.ts.map +1 -1
- package/dist/model/panels.js +15 -1
- package/dist/model/panels.js.map +1 -0
- package/dist/model/plugins.d.ts +16 -25
- package/dist/model/plugins.d.ts.map +1 -1
- package/dist/model/plugins.js +15 -1
- package/dist/model/plugins.js.map +1 -0
- package/dist/model/time-series-queries.d.ts +28 -0
- package/dist/model/time-series-queries.d.ts.map +1 -0
- package/dist/model/time-series-queries.js +15 -0
- package/dist/model/time-series-queries.js.map +1 -0
- package/dist/model/variables.d.ts +16 -11
- package/dist/model/variables.d.ts.map +1 -1
- package/dist/model/variables.js +15 -1
- package/dist/model/variables.js.map +1 -0
- package/dist/model/visual-editing.d.ts +5 -6
- package/dist/model/visual-editing.d.ts.map +1 -1
- package/dist/model/visual-editing.js +15 -1
- package/dist/model/visual-editing.js.map +1 -0
- package/dist/runtime/datasources.d.ts +5 -9
- package/dist/runtime/datasources.d.ts.map +1 -1
- package/dist/runtime/datasources.js +23 -1
- package/dist/runtime/datasources.js.map +1 -0
- package/dist/runtime/index.d.ts +3 -1
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +20 -1
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/plugins.d.ts +5 -14
- package/dist/runtime/plugins.d.ts.map +1 -1
- package/dist/runtime/plugins.js +33 -1
- package/dist/runtime/plugins.js.map +1 -0
- package/dist/runtime/query-string.js +25 -1
- package/dist/runtime/query-string.js.map +1 -0
- package/dist/runtime/template-variables.d.ts +10 -1
- package/dist/runtime/template-variables.d.ts.map +1 -1
- package/dist/runtime/template-variables.js +44 -1
- package/dist/runtime/template-variables.js.map +1 -0
- package/dist/runtime/time-range.js +25 -1
- package/dist/runtime/time-range.js.map +1 -0
- package/dist/runtime/time-series-queries.d.ts +14 -0
- package/dist/runtime/time-series-queries.d.ts.map +1 -0
- package/dist/runtime/time-series-queries.js +54 -0
- package/dist/runtime/time-series-queries.js.map +1 -0
- package/dist/test/render.d.ts.map +1 -1
- package/dist/test/render.js +42 -1
- package/dist/test/render.js.map +1 -0
- package/dist/test/setup-tests.d.ts.map +1 -1
- package/dist/test/setup-tests.js +16 -1
- package/dist/test/setup-tests.js.map +1 -0
- package/dist/utils/cache-keys.js +19 -1
- package/dist/utils/cache-keys.js.map +1 -0
- package/package.json +11 -8
- package/dist/cjs/components/PluginBoundary.js +0 -14
- package/dist/cjs/components/PluginLoadingBoundary/PluginLoader.js +0 -39
- package/dist/cjs/components/PluginLoadingBoundary/PluginLoadingBoundary.js +0 -85
- package/dist/cjs/components/PluginLoadingBoundary/index.js +0 -29
- package/dist/cjs/components/PluginRegistry/legacy/PluginRegistry.js +0 -57
- package/dist/cjs/components/PluginRegistry/legacy/index.js +0 -29
- package/dist/cjs/components/PluginRegistry/legacy/registry-state.js +0 -97
- package/dist/cjs/components/PluginRegistry/test-plugins/bert/plugin.json +0 -32
- package/dist/cjs/components/PluginRegistry/test-plugins/ernie/plugin.json +0 -24
- package/dist/cjs/model/graph-queries.js +0 -28
- package/dist/components/PluginBoundary.d.ts +0 -13
- package/dist/components/PluginBoundary.d.ts.map +0 -1
- package/dist/components/PluginBoundary.js +0 -1
- package/dist/components/PluginLoadingBoundary/PluginLoader.d.ts +0 -11
- package/dist/components/PluginLoadingBoundary/PluginLoader.d.ts.map +0 -1
- package/dist/components/PluginLoadingBoundary/PluginLoader.js +0 -1
- package/dist/components/PluginLoadingBoundary/PluginLoadingBoundary.d.ts +0 -27
- package/dist/components/PluginLoadingBoundary/PluginLoadingBoundary.d.ts.map +0 -1
- package/dist/components/PluginLoadingBoundary/PluginLoadingBoundary.js +0 -1
- package/dist/components/PluginLoadingBoundary/index.d.ts +0 -2
- package/dist/components/PluginLoadingBoundary/index.d.ts.map +0 -1
- package/dist/components/PluginLoadingBoundary/index.js +0 -1
- package/dist/components/PluginRegistry/legacy/PluginRegistry.d.ts +0 -29
- package/dist/components/PluginRegistry/legacy/PluginRegistry.d.ts.map +0 -1
- package/dist/components/PluginRegistry/legacy/PluginRegistry.js +0 -1
- package/dist/components/PluginRegistry/legacy/index.d.ts +0 -2
- package/dist/components/PluginRegistry/legacy/index.d.ts.map +0 -1
- package/dist/components/PluginRegistry/legacy/index.js +0 -1
- package/dist/components/PluginRegistry/legacy/registry-state.d.ts +0 -18
- package/dist/components/PluginRegistry/legacy/registry-state.d.ts.map +0 -1
- package/dist/components/PluginRegistry/legacy/registry-state.js +0 -1
- package/dist/components/PluginRegistry/test-plugins/bert/plugin.json +0 -32
- package/dist/components/PluginRegistry/test-plugins/ernie/plugin.json +0 -24
- package/dist/model/graph-queries.d.ts +0 -36
- package/dist/model/graph-queries.d.ts.map +0 -1
- package/dist/model/graph-queries.js +0 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
// Copyright 2021 The Perses Authors
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
3
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
3
|
// you may not use this file except in compliance with the License.
|
|
5
4
|
// You may obtain a copy of the License at
|
|
@@ -11,29 +10,48 @@
|
|
|
11
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
11
|
// See the License for the specific language governing permissions and
|
|
13
12
|
// limitations under the License.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
function _export(target, all) {
|
|
18
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: all[name]
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
_export(exports, {
|
|
24
|
+
DEFAULT_ALL_VALUE: ()=>DEFAULT_ALL_VALUE,
|
|
25
|
+
TemplateVariableContext: ()=>TemplateVariableContext,
|
|
26
|
+
useTemplateVariableValues: ()=>useTemplateVariableValues
|
|
27
|
+
});
|
|
28
|
+
const _react = require("react");
|
|
29
|
+
const DEFAULT_ALL_VALUE = '$__all';
|
|
30
|
+
const TemplateVariableContext = (0, _react.createContext)(undefined);
|
|
18
31
|
function useTemplateVariableContext() {
|
|
19
|
-
const ctx = (0,
|
|
32
|
+
const ctx = (0, _react.useContext)(TemplateVariableContext);
|
|
20
33
|
if (ctx === undefined) {
|
|
21
34
|
throw new Error('No TemplateVariableContext found. Did you forget a Provider?');
|
|
22
35
|
}
|
|
23
36
|
return ctx;
|
|
24
37
|
}
|
|
25
38
|
function useTemplateVariableValues(names) {
|
|
26
|
-
const { state
|
|
39
|
+
const { state } = useTemplateVariableContext();
|
|
40
|
+
const values = (0, _react.useMemo)(()=>{
|
|
41
|
+
const values = {};
|
|
42
|
+
names === null || names === void 0 ? void 0 : names.forEach((name)=>{
|
|
43
|
+
const s = state[name];
|
|
44
|
+
if (s) {
|
|
45
|
+
values[name] = s;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
return values;
|
|
49
|
+
}, [
|
|
50
|
+
state,
|
|
51
|
+
names
|
|
52
|
+
]);
|
|
27
53
|
if (names === undefined) {
|
|
28
54
|
return state;
|
|
29
55
|
}
|
|
30
|
-
const values = {};
|
|
31
|
-
names.forEach((name) => {
|
|
32
|
-
const s = state[name];
|
|
33
|
-
if (s) {
|
|
34
|
-
values[name] = s;
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
56
|
return values;
|
|
38
57
|
}
|
|
39
|
-
exports.useTemplateVariableValues = useTemplateVariableValues;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// Copyright 2022 The Perses Authors
|
|
3
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
3
|
// you may not use this file except in compliance with the License.
|
|
@@ -11,18 +10,26 @@
|
|
|
11
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
11
|
// See the License for the specific language governing permissions and
|
|
13
12
|
// limitations under the License.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
function _export(target, all) {
|
|
18
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: all[name]
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
_export(exports, {
|
|
24
|
+
TimeRangeContext: ()=>TimeRangeContext,
|
|
25
|
+
useTimeRange: ()=>useTimeRange
|
|
26
|
+
});
|
|
27
|
+
const _react = require("react");
|
|
28
|
+
const TimeRangeContext = (0, _react.createContext)(undefined);
|
|
21
29
|
function useTimeRange() {
|
|
22
|
-
const ctx = (0,
|
|
30
|
+
const ctx = (0, _react.useContext)(TimeRangeContext);
|
|
23
31
|
if (ctx === undefined) {
|
|
24
32
|
throw new Error('No TimeRangeContext found. Did you forget a Provider?');
|
|
25
33
|
}
|
|
26
34
|
return ctx;
|
|
27
35
|
}
|
|
28
|
-
exports.useTimeRange = useTimeRange;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "useTimeSeriesQueryData", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>useTimeSeriesQueryData
|
|
20
|
+
});
|
|
21
|
+
const _reactQuery = require("@tanstack/react-query");
|
|
22
|
+
const _templateVariables = require("./template-variables");
|
|
23
|
+
const _timeRange = require("./time-range");
|
|
24
|
+
const _plugins = require("./plugins");
|
|
25
|
+
const _datasources = require("./datasources");
|
|
26
|
+
const useTimeSeriesQueryData = (definition, options)=>{
|
|
27
|
+
const { data: plugin } = (0, _plugins.usePlugin)('TimeSeriesQuery', definition.spec.plugin.kind);
|
|
28
|
+
// Build the context object from data available at runtime
|
|
29
|
+
const { timeRange } = (0, _timeRange.useTimeRange)();
|
|
30
|
+
const variableState = (0, _templateVariables.useTemplateVariableValues)();
|
|
31
|
+
const datasourceStore = (0, _datasources.useDatasourceStore)();
|
|
32
|
+
const context = {
|
|
33
|
+
suggestedStepMs: options === null || options === void 0 ? void 0 : options.suggestedStepMs,
|
|
34
|
+
timeRange,
|
|
35
|
+
variableState,
|
|
36
|
+
datasourceStore
|
|
37
|
+
};
|
|
38
|
+
const key = [
|
|
39
|
+
definition,
|
|
40
|
+
context
|
|
41
|
+
];
|
|
42
|
+
const { data , isLoading , error } = (0, _reactQuery.useQuery)(key, ({ queryKey })=>{
|
|
43
|
+
// The 'enabled' option should prevent this from happening, but make TypeScript happy by checking
|
|
44
|
+
if (plugin === undefined) {
|
|
45
|
+
throw new Error('Expected plugin to be loaded');
|
|
46
|
+
}
|
|
47
|
+
const [definition, context] = queryKey;
|
|
48
|
+
return plugin.getTimeSeriesData(definition.spec.plugin.spec, context);
|
|
49
|
+
}, {
|
|
50
|
+
enabled: plugin !== undefined
|
|
51
|
+
});
|
|
52
|
+
// TODO: Stop aliasing fields, just return the hook results directly once we clean up query running in panels
|
|
53
|
+
return {
|
|
54
|
+
data,
|
|
55
|
+
loading: isLoading,
|
|
56
|
+
error: error !== null && error !== void 0 ? error : undefined
|
|
57
|
+
};
|
|
58
|
+
};
|
package/dist/cjs/test/render.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.renderWithContext = void 0;
|
|
4
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
1
|
// Copyright 2022 The Perses Authors
|
|
6
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
3
|
// you may not use this file except in compliance with the License.
|
|
@@ -14,14 +10,37 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
14
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
11
|
// See the License for the specific language governing permissions and
|
|
16
12
|
// limitations under the License.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "renderWithContext", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>renderWithContext
|
|
20
|
+
});
|
|
21
|
+
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
+
const _react = require("@testing-library/react");
|
|
23
|
+
const _reactQuery = require("@tanstack/react-query");
|
|
24
|
+
const testLogger = {
|
|
25
|
+
log: console.log,
|
|
26
|
+
warn: console.warn,
|
|
27
|
+
error: ()=>{
|
|
28
|
+
// Don't log network errors in tests to the console
|
|
29
|
+
}
|
|
30
|
+
};
|
|
24
31
|
function renderWithContext(ui, options) {
|
|
25
|
-
|
|
32
|
+
// Create a new QueryClient for each test to avoid caching issues
|
|
33
|
+
const queryClient = new _reactQuery.QueryClient({
|
|
34
|
+
defaultOptions: {
|
|
35
|
+
queries: {
|
|
36
|
+
refetchOnWindowFocus: false,
|
|
37
|
+
retry: false
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
logger: testLogger
|
|
41
|
+
});
|
|
42
|
+
return (0, _react.render)(/*#__PURE__*/ (0, _jsxRuntime.jsx)(_reactQuery.QueryClientProvider, {
|
|
43
|
+
client: queryClient,
|
|
44
|
+
children: ui
|
|
45
|
+
}), options);
|
|
26
46
|
}
|
|
27
|
-
exports.renderWithContext = renderWithContext;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// Copyright 2022 The Perses Authors
|
|
3
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
3
|
// you may not use this file except in compliance with the License.
|
|
@@ -11,14 +10,9 @@
|
|
|
11
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
11
|
// See the License for the specific language governing permissions and
|
|
13
12
|
// limitations under the License.
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const react_query_1 = require("react-query");
|
|
16
13
|
// Add testing library assertions
|
|
17
|
-
|
|
18
|
-
(
|
|
19
|
-
|
|
20
|
-
warn: console.warn,
|
|
21
|
-
error: () => {
|
|
22
|
-
// Don't log network errors to the console during tests
|
|
23
|
-
},
|
|
14
|
+
"use strict";
|
|
15
|
+
Object.defineProperty(exports, "__esModule", {
|
|
16
|
+
value: true
|
|
24
17
|
});
|
|
18
|
+
require("@testing-library/jest-dom/extend-expect");
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// Copyright 2022 The Perses Authors
|
|
3
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
3
|
// you may not use this file except in compliance with the License.
|
|
@@ -11,12 +10,14 @@
|
|
|
11
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
11
|
// See the License for the specific language governing permissions and
|
|
13
12
|
// limitations under the License.
|
|
14
|
-
|
|
15
|
-
exports
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "getTypeAndKindKey", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>getTypeAndKindKey
|
|
20
|
+
});
|
|
19
21
|
function getTypeAndKindKey(pluginType, kind) {
|
|
20
22
|
return `${pluginType}:${kind}`;
|
|
21
23
|
}
|
|
22
|
-
exports.getTypeAndKindKey = getTypeAndKindKey;
|
|
@@ -1 +1,81 @@
|
|
|
1
|
-
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
import { useEvent } from '@perses-dev/core';
|
|
15
|
+
import { useRef, useCallback, useMemo } from 'react';
|
|
16
|
+
import { getTypeAndKindKey } from '../../utils/cache-keys';
|
|
17
|
+
import { usePluginIndexes } from './plugin-indexes';
|
|
18
|
+
import { PluginRegistryContext } from './plugin-registry-model';
|
|
19
|
+
/**
|
|
20
|
+
* PluginRegistryContext provider that keeps track of all available plugins and provides an API for getting them or
|
|
21
|
+
* querying the metadata about them.
|
|
22
|
+
*/ export function PluginRegistry(props) {
|
|
23
|
+
const { getInstalledPlugins , importPluginModule , children } = props;
|
|
24
|
+
const getPluginIndexes = usePluginIndexes(getInstalledPlugins);
|
|
25
|
+
// De-dupe calls to import plugin modules
|
|
26
|
+
const importCache = useRef(new Map());
|
|
27
|
+
// Do useEvent here since this accesses the importPluginModule prop and we want a stable reference to it for the
|
|
28
|
+
// callback below
|
|
29
|
+
const loadPluginModule = useEvent((resource)=>{
|
|
30
|
+
let request = importCache.current.get(resource);
|
|
31
|
+
if (request === undefined) {
|
|
32
|
+
request = importPluginModule(resource);
|
|
33
|
+
importCache.current.set(resource, request);
|
|
34
|
+
// Remove failed requests from the cache so they can potentially be retried
|
|
35
|
+
request.catch(()=>importCache.current.delete(resource));
|
|
36
|
+
}
|
|
37
|
+
return request;
|
|
38
|
+
});
|
|
39
|
+
const getPlugin = useCallback(async (pluginType, kind)=>{
|
|
40
|
+
// Get the indexes of the installed plugins
|
|
41
|
+
const pluginIndexes = await getPluginIndexes();
|
|
42
|
+
// Figure out what module the plugin is in by looking in the index
|
|
43
|
+
const typeAndKindKey = getTypeAndKindKey(pluginType, kind);
|
|
44
|
+
const resource = pluginIndexes.pluginResourcesByTypeAndKind.get(typeAndKindKey);
|
|
45
|
+
if (resource === undefined) {
|
|
46
|
+
throw new Error(`A ${pluginType} plugin for kind '${kind}' is not installed`);
|
|
47
|
+
}
|
|
48
|
+
// Treat the plugin module as a bunch of named exports that have plugins
|
|
49
|
+
const pluginModule = await loadPluginModule(resource);
|
|
50
|
+
// We currently assume that plugin modules will have named exports that match the kinds they handle
|
|
51
|
+
const plugin = pluginModule[kind];
|
|
52
|
+
if (plugin === undefined) {
|
|
53
|
+
throw new Error(`The ${pluginType} plugin for kind '${kind}' is missing from the ${resource.metadata.name} plugin module`);
|
|
54
|
+
}
|
|
55
|
+
return plugin;
|
|
56
|
+
}, [
|
|
57
|
+
getPluginIndexes,
|
|
58
|
+
loadPluginModule
|
|
59
|
+
]);
|
|
60
|
+
const listPluginMetadata = useCallback(async (pluginType)=>{
|
|
61
|
+
const pluginIndexes = await getPluginIndexes();
|
|
62
|
+
var ref;
|
|
63
|
+
return (ref = pluginIndexes.pluginMetadataByType.get(pluginType)) !== null && ref !== void 0 ? ref : [];
|
|
64
|
+
}, [
|
|
65
|
+
getPluginIndexes
|
|
66
|
+
]);
|
|
67
|
+
// Create the registry's context value and render
|
|
68
|
+
const context = useMemo(()=>({
|
|
69
|
+
getPlugin,
|
|
70
|
+
listPluginMetadata
|
|
71
|
+
}), [
|
|
72
|
+
getPlugin,
|
|
73
|
+
listPluginMetadata
|
|
74
|
+
]);
|
|
75
|
+
return /*#__PURE__*/ _jsx(PluginRegistryContext.Provider, {
|
|
76
|
+
value: context,
|
|
77
|
+
children: children
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
//# sourceMappingURL=PluginRegistry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/PluginRegistry/PluginRegistry.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useEvent } from '@perses-dev/core';\nimport { useRef, useCallback, useMemo } from 'react';\nimport { PluginModuleResource, PluginType, Plugin, PluginImplementation } from '../../model';\nimport { getTypeAndKindKey } from '../../utils/cache-keys';\nimport { GetInstalledPlugins, usePluginIndexes } from './plugin-indexes';\nimport { PluginRegistryContext } from './plugin-registry-model';\n\nexport interface PluginRegistryProps {\n children?: React.ReactNode;\n getInstalledPlugins: GetInstalledPlugins;\n importPluginModule: (resource: PluginModuleResource) => Promise<unknown>;\n}\n\n/**\n * PluginRegistryContext provider that keeps track of all available plugins and provides an API for getting them or\n * querying the metadata about them.\n */\nexport function PluginRegistry(props: PluginRegistryProps) {\n const { getInstalledPlugins, importPluginModule, children } = props;\n\n const getPluginIndexes = usePluginIndexes(getInstalledPlugins);\n\n // De-dupe calls to import plugin modules\n const importCache = useRef(new Map<PluginModuleResource, Promise<unknown>>());\n\n // Do useEvent here since this accesses the importPluginModule prop and we want a stable reference to it for the\n // callback below\n const loadPluginModule = useEvent((resource: PluginModuleResource) => {\n let request = importCache.current.get(resource);\n if (request === undefined) {\n request = importPluginModule(resource);\n importCache.current.set(resource, request);\n\n // Remove failed requests from the cache so they can potentially be retried\n request.catch(() => importCache.current.delete(resource));\n }\n return request;\n });\n\n const getPlugin = useCallback(\n async <T extends PluginType>(pluginType: T, kind: string): Promise<PluginImplementation<T>> => {\n // Get the indexes of the installed plugins\n const pluginIndexes = await getPluginIndexes();\n\n // Figure out what module the plugin is in by looking in the index\n const typeAndKindKey = getTypeAndKindKey(pluginType, kind);\n const resource = pluginIndexes.pluginResourcesByTypeAndKind.get(typeAndKindKey);\n if (resource === undefined) {\n throw new Error(`A ${pluginType} plugin for kind '${kind}' is not installed`);\n }\n\n // Treat the plugin module as a bunch of named exports that have plugins\n const pluginModule = (await loadPluginModule(resource)) as Record<string, Plugin>;\n\n // We currently assume that plugin modules will have named exports that match the kinds they handle\n const plugin = pluginModule[kind];\n if (plugin === undefined) {\n throw new Error(\n `The ${pluginType} plugin for kind '${kind}' is missing from the ${resource.metadata.name} plugin module`\n );\n }\n\n return plugin as PluginImplementation<T>;\n },\n [getPluginIndexes, loadPluginModule]\n );\n\n const listPluginMetadata = useCallback(\n async (pluginType: PluginType) => {\n const pluginIndexes = await getPluginIndexes();\n return pluginIndexes.pluginMetadataByType.get(pluginType) ?? [];\n },\n [getPluginIndexes]\n );\n\n // Create the registry's context value and render\n const context = useMemo(() => ({ getPlugin, listPluginMetadata }), [getPlugin, listPluginMetadata]);\n return <PluginRegistryContext.Provider value={context}>{children}</PluginRegistryContext.Provider>;\n}\n"],"names":["useEvent","useRef","useCallback","useMemo","getTypeAndKindKey","usePluginIndexes","PluginRegistryContext","PluginRegistry","props","getInstalledPlugins","importPluginModule","children","getPluginIndexes","importCache","Map","loadPluginModule","resource","request","current","get","undefined","set","catch","delete","getPlugin","pluginType","kind","pluginIndexes","typeAndKindKey","pluginResourcesByTypeAndKind","Error","pluginModule","plugin","metadata","name","listPluginMetadata","pluginMetadataByType","context","Provider","value"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAi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SAAE,CAAA,AAAC,EAAE;QAACX,SAAS;QAAEW,kBAAkB;KAAC,CAAC,AAAC;IACpG,qBAAO,KAAC7B,qBAAqB,CAACgC,QAAQ;QAACC,KAAK,EAAEF,OAAO;kBAAG1B,QAAQ;MAAkC,CAAC;AACrG,CAAC"}
|
|
@@ -1 +1,142 @@
|
|
|
1
|
-
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
+
import React from 'react';
|
|
15
|
+
import { screen } from '@testing-library/react';
|
|
16
|
+
import { useListPluginMetadata, usePlugin } from '../../runtime/plugins';
|
|
17
|
+
import { renderWithContext } from '../../test/render';
|
|
18
|
+
import { PluginRegistry } from './PluginRegistry';
|
|
19
|
+
import { testRegistryProps } from './test-plugins';
|
|
20
|
+
describe('PluginRegistry', ()=>{
|
|
21
|
+
const renderPluginRegistry = (children)=>{
|
|
22
|
+
renderWithContext(/*#__PURE__*/ _jsx(PluginRegistry, {
|
|
23
|
+
...testRegistryProps,
|
|
24
|
+
children: children
|
|
25
|
+
}));
|
|
26
|
+
};
|
|
27
|
+
it('can load a plugin that exists', async ()=>{
|
|
28
|
+
renderPluginRegistry(/*#__PURE__*/ _jsx(PluginConsumer, {
|
|
29
|
+
pluginType: "Variable",
|
|
30
|
+
kind: "ErnieVariable"
|
|
31
|
+
}));
|
|
32
|
+
const hasPlugin = await screen.findByText('Has plugin: true', undefined, {
|
|
33
|
+
timeout: 3000
|
|
34
|
+
});
|
|
35
|
+
expect(hasPlugin).toBeInTheDocument();
|
|
36
|
+
});
|
|
37
|
+
it('errors when plugin is not installed', async ()=>{
|
|
38
|
+
// This plugin is not in the test metadata at all
|
|
39
|
+
renderPluginRegistry(/*#__PURE__*/ _jsx(PluginConsumer, {
|
|
40
|
+
pluginType: "TimeSeriesQuery",
|
|
41
|
+
kind: "NotInstalled"
|
|
42
|
+
}));
|
|
43
|
+
const error = await screen.findByText(/error:/i);
|
|
44
|
+
expect(error).toBeInTheDocument();
|
|
45
|
+
expect(error).toHaveTextContent(/not installed/i);
|
|
46
|
+
});
|
|
47
|
+
it('errors when plugin is missing from the module', async ()=>{
|
|
48
|
+
// This plugin is in the test metadata, but the code is missing from the module
|
|
49
|
+
renderPluginRegistry(/*#__PURE__*/ _jsx(PluginConsumer, {
|
|
50
|
+
pluginType: "Variable",
|
|
51
|
+
kind: "MissingErnieVariable"
|
|
52
|
+
}));
|
|
53
|
+
const error = await screen.findByText(/error:/i);
|
|
54
|
+
expect(error).toBeInTheDocument();
|
|
55
|
+
expect(error).toHaveTextContent(/missing/i);
|
|
56
|
+
});
|
|
57
|
+
it('lists metadata for plugin metadata that exists', async ()=>{
|
|
58
|
+
// There should be 3 variable plugins across both test modules
|
|
59
|
+
renderPluginRegistry(/*#__PURE__*/ _jsx(MetadataConsumer, {
|
|
60
|
+
pluginType: "Variable"
|
|
61
|
+
}));
|
|
62
|
+
const table = await screen.findByRole('table');
|
|
63
|
+
expect(table).toBeInTheDocument();
|
|
64
|
+
const rows = screen.getAllByRole('row');
|
|
65
|
+
expect(rows).toHaveLength(3);
|
|
66
|
+
});
|
|
67
|
+
it('lists metadata for plugin types with no plugins available', async ()=>{
|
|
68
|
+
// There are no TimeSeriesQuery plugins in any of the test modules
|
|
69
|
+
renderPluginRegistry(/*#__PURE__*/ _jsx(MetadataConsumer, {
|
|
70
|
+
pluginType: "TimeSeriesQuery"
|
|
71
|
+
}));
|
|
72
|
+
const table = await screen.findByRole('table');
|
|
73
|
+
expect(table).toBeInTheDocument();
|
|
74
|
+
const rows = screen.queryAllByRole('row');
|
|
75
|
+
expect(rows).toHaveLength(0);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
// A helper component for testing the PluginRegistry by calling usePlugin to load a plugin
|
|
79
|
+
const PluginConsumer = (props)=>{
|
|
80
|
+
const { data: plugin , isLoading , error } = usePlugin(props.pluginType, props.kind);
|
|
81
|
+
if (error) {
|
|
82
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
83
|
+
children: [
|
|
84
|
+
"Error: ",
|
|
85
|
+
error.message
|
|
86
|
+
]
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
if (isLoading) {
|
|
90
|
+
return /*#__PURE__*/ _jsx("div", {
|
|
91
|
+
children: "Loading"
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
95
|
+
children: [
|
|
96
|
+
"Has plugin: ",
|
|
97
|
+
(plugin !== undefined).toString()
|
|
98
|
+
]
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
// A helper component for testing the PluginRegistry metadata APIs by calling useListPluginMetadata
|
|
102
|
+
const MetadataConsumer = (props)=>{
|
|
103
|
+
const { data: pluginMetadata , isLoading , error } = useListPluginMetadata(props.pluginType);
|
|
104
|
+
if (error) {
|
|
105
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
106
|
+
children: [
|
|
107
|
+
"Error: ",
|
|
108
|
+
error.message
|
|
109
|
+
]
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
if (isLoading) {
|
|
113
|
+
return /*#__PURE__*/ _jsx("div", {
|
|
114
|
+
children: "Loading"
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
if (pluginMetadata === undefined) {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
return /*#__PURE__*/ _jsx("table", {
|
|
121
|
+
children: /*#__PURE__*/ _jsx("tbody", {
|
|
122
|
+
children: pluginMetadata.map((item)=>/*#__PURE__*/ _jsxs("tr", {
|
|
123
|
+
children: [
|
|
124
|
+
/*#__PURE__*/ _jsx("td", {
|
|
125
|
+
children: item.pluginType
|
|
126
|
+
}),
|
|
127
|
+
/*#__PURE__*/ _jsx("td", {
|
|
128
|
+
children: item.kind
|
|
129
|
+
}),
|
|
130
|
+
/*#__PURE__*/ _jsx("td", {
|
|
131
|
+
children: item.display.name
|
|
132
|
+
}),
|
|
133
|
+
/*#__PURE__*/ _jsx("td", {
|
|
134
|
+
children: item.display.description
|
|
135
|
+
})
|
|
136
|
+
]
|
|
137
|
+
}, item.kind))
|
|
138
|
+
})
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
//# sourceMappingURL=PluginRegistry.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/PluginRegistry/PluginRegistry.test.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport React from 'react';\nimport { screen } from '@testing-library/react';\nimport { PluginType } from '../../model';\nimport { useListPluginMetadata, usePlugin } from '../../runtime/plugins';\nimport { renderWithContext } from '../../test/render';\nimport { PluginRegistry } from './PluginRegistry';\nimport { testRegistryProps } from './test-plugins';\n\ndescribe('PluginRegistry', () => {\n const renderPluginRegistry = (children: React.ReactNode) => {\n renderWithContext(<PluginRegistry {...testRegistryProps}>{children}</PluginRegistry>);\n };\n\n it('can load a plugin that exists', async () => {\n renderPluginRegistry(<PluginConsumer pluginType=\"Variable\" kind=\"ErnieVariable\" />);\n\n const hasPlugin = await screen.findByText('Has plugin: true', undefined, { timeout: 3000 });\n expect(hasPlugin).toBeInTheDocument();\n });\n\n it('errors when plugin is not installed', async () => {\n // This plugin is not in the test metadata at all\n renderPluginRegistry(<PluginConsumer pluginType=\"TimeSeriesQuery\" kind=\"NotInstalled\" />);\n\n const error = await screen.findByText(/error:/i);\n expect(error).toBeInTheDocument();\n expect(error).toHaveTextContent(/not installed/i);\n });\n\n it('errors when plugin is missing from the module', async () => {\n // This plugin is in the test metadata, but the code is missing from the module\n renderPluginRegistry(<PluginConsumer pluginType=\"Variable\" kind=\"MissingErnieVariable\" />);\n\n const error = await screen.findByText(/error:/i);\n expect(error).toBeInTheDocument();\n expect(error).toHaveTextContent(/missing/i);\n });\n\n it('lists metadata for plugin metadata that exists', async () => {\n // There should be 3 variable plugins across both test modules\n renderPluginRegistry(<MetadataConsumer pluginType=\"Variable\" />);\n\n const table = await screen.findByRole('table');\n expect(table).toBeInTheDocument();\n const rows = screen.getAllByRole('row');\n expect(rows).toHaveLength(3);\n });\n\n it('lists metadata for plugin types with no plugins available', async () => {\n // There are no TimeSeriesQuery plugins in any of the test modules\n renderPluginRegistry(<MetadataConsumer pluginType=\"TimeSeriesQuery\" />);\n\n const table = await screen.findByRole('table');\n expect(table).toBeInTheDocument();\n const rows = screen.queryAllByRole('row');\n expect(rows).toHaveLength(0);\n });\n});\n\n// A helper component for testing the PluginRegistry by calling usePlugin to load a plugin\nconst PluginConsumer = (props: { pluginType: PluginType; kind: string }) => {\n const { data: plugin, isLoading, error } = usePlugin(props.pluginType, props.kind);\n if (error) {\n return <div>Error: {(error as Error).message}</div>;\n }\n if (isLoading) {\n return <div>Loading</div>;\n }\n return <div>Has plugin: {(plugin !== undefined).toString()}</div>;\n};\n\n// A helper component for testing the PluginRegistry metadata APIs by calling useListPluginMetadata\nconst MetadataConsumer = (props: { pluginType: PluginType }) => {\n const { data: pluginMetadata, isLoading, error } = useListPluginMetadata(props.pluginType);\n if (error) {\n return <div>Error: {(error as Error).message}</div>;\n }\n if (isLoading) {\n return <div>Loading</div>;\n }\n\n if (pluginMetadata === undefined) {\n return null;\n }\n\n return (\n <table>\n <tbody>\n {pluginMetadata.map((item) => (\n <tr key={item.kind}>\n <td>{item.pluginType}</td>\n <td>{item.kind}</td>\n <td>{item.display.name}</td>\n <td>{item.display.description}</td>\n </tr>\n ))}\n </tbody>\n </table>\n );\n};\n"],"names":["React","screen","useListPluginMetadata","usePlugin","renderWithContext","PluginRegistry","testRegistryProps","describe","renderPluginRegistry","children","it","PluginConsumer","pluginType","kind","hasPlugin","findByText","undefined","timeout","expect","toBeInTheDocument","error","toHaveTextContent","MetadataConsumer","table","findByRole","rows","getAllByRole","toHaveLength","queryAllByRole","props","data","plugin","isLoading","div","message","toString","pluginMetadata","tbody","map","item","tr","td","display","name","description"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,OAAOA,KAAK,MAAM,OAAO,CAAC;AAC1B,SAASC,MAAM,QAAQ,wBAAwB,CAAC;AAEhD,SAASC,qBAAqB,EAAEC,SAAS,QAAQ,uBAAuB,CAAC;AACzE,SAASC,iBAAiB,QAAQ,mBAAmB,CAAC;AACtD,SAASC,cAAc,QAAQ,kBAAkB,CAAC;AAClD,SAASC,iBAAiB,QAAQ,gBAAgB,CAAC;AAEnDC,QAAQ,CAAC,gBAAgB,EAAE,IAAM;IAC/B,MAAMC,oBAAoB,GAAG,CAACC,QAAyB,GAAK;QAC1DL,iBAAiB,eAAC,KAACC,cAAc;YAAE,GAAGC,iBAAiB;sBAAGG,QAAQ;UAAkB,CAAC,CAAC;IACxF,CAAC,AAAC;IAEFC,EAA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A,MAAM,KAAKf,SAAS,CAAA,CAAEmB,QAAQ,EAAE;;MAAO,CAAC;AACpE,CAAC,AAAC;AAEF,mGAAmG;AACnG,MAAMb,gBAAgB,GAAG,CAACO,KAAiC,GAAK;IAC9D,MAAM,EAAEC,IAAI,EAAEM,cAAc,CAAA,EAAEJ,SAAS,CAAA,EAAEZ,KAAK,CAAA,EAAE,GAAGlB,qBAAqB,CAAC2B,KAAK,CAACjB,UAAU,CAAC,AAAC;IAC3F,IAAIQ,KAAK,EAAE;QACT,qBAAO,MAACa,KAAG;;gBAAC,SAAO;gBAAC,AAACb,KAAK,CAAWc,OAAO;;UAAO,CAAC;IACtD,CAAC;IACD,IAAIF,SAAS,EAAE;QACb,qBAAO,KAACC,KAAG;sBAAC,SAAO;UAAM,CAAC;IAC5B,CAAC;IAED,IAAIG,cAAc,KAAKpB,SAAS,EAAE;QAChC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,qBACE,KAACO,OAAK;kBACJ,cAAA,KAACc,OAAK;sBACHD,cAAc,CAACE,GAAG,CAAC,CAACC,IAAI,iBACvB,MAACC,IAAE;;sCACD,KAACC,IAAE;sCAAEF,IAAI,CAAC3B,UAAU;0BAAM;sCAC1B,KAAC6B,IAAE;sCAAEF,IAAI,CAAC1B,IAAI;0BAAM;sCACpB,KAAC4B,IAAE;sCAAEF,IAAI,CAACG,OAAO,CAACC,IAAI;0BAAM;sCAC5B,KAACF,IAAE;sCAAEF,IAAI,CAACG,OAAO,CAACE,WAAW;0BAAM;;mBAJ5BL,IAAI,CAAC1B,IAAI,CAKb,AACN,CAAC;UACI;MACF,CACR;AACJ,CAAC,AAAC"}
|
|
@@ -1 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
export * from './plugin-registry-model';
|
|
14
|
+
export * from './PluginRegistry';
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/PluginRegistry/index.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './plugin-registry-model';\nexport * from './PluginRegistry';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC"}
|
|
@@ -1 +1,66 @@
|
|
|
1
|
-
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { useEvent } from '@perses-dev/core';
|
|
14
|
+
import { useCallback, useRef } from 'react';
|
|
15
|
+
import { getTypeAndKindKey } from '../../utils/cache-keys';
|
|
16
|
+
/**
|
|
17
|
+
* Returns an async callback for getting indexes of the installed plugin data.
|
|
18
|
+
*/ export function usePluginIndexes(getInstalledPlugins) {
|
|
19
|
+
// Creates indexes from the installed plugins data (does useEvent because this accesses the getInstalledPlugins prop
|
|
20
|
+
// and we want a stable reference for the callback below)
|
|
21
|
+
const createPluginIndexes = useEvent(async ()=>{
|
|
22
|
+
const installedPlugins = await getInstalledPlugins();
|
|
23
|
+
// Create the two indexes from the installed plugins
|
|
24
|
+
const pluginResourcesByTypeAndKind = new Map();
|
|
25
|
+
const pluginMetadataByType = new Map();
|
|
26
|
+
for (const resource of installedPlugins){
|
|
27
|
+
for (const pluginMetadata of resource.spec.plugins){
|
|
28
|
+
const { pluginType , kind } = pluginMetadata;
|
|
29
|
+
// Index the plugin by type and kind to point at the module that contains it
|
|
30
|
+
const key = getTypeAndKindKey(pluginType, kind);
|
|
31
|
+
if (pluginResourcesByTypeAndKind.has(key)) {
|
|
32
|
+
console.warn(`Got more than one ${pluginType} plugin for kind ${kind}`);
|
|
33
|
+
}
|
|
34
|
+
pluginResourcesByTypeAndKind.set(key, resource);
|
|
35
|
+
// Index the metadata by plugin type
|
|
36
|
+
let list = pluginMetadataByType.get(pluginType);
|
|
37
|
+
if (list === undefined) {
|
|
38
|
+
list = [];
|
|
39
|
+
pluginMetadataByType.set(pluginType, list);
|
|
40
|
+
}
|
|
41
|
+
list.push(pluginMetadata);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
pluginResourcesByTypeAndKind,
|
|
46
|
+
pluginMetadataByType
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
// De-dupe creating plugin indexes (i.e. requests to get installed plugins)
|
|
50
|
+
const pluginIndexesCache = useRef(undefined);
|
|
51
|
+
const getPluginIndexes = useCallback(()=>{
|
|
52
|
+
let request = pluginIndexesCache.current;
|
|
53
|
+
if (request === undefined) {
|
|
54
|
+
request = createPluginIndexes();
|
|
55
|
+
pluginIndexesCache.current = request;
|
|
56
|
+
// Remove failed requests from the cache so they can potentially be retried
|
|
57
|
+
request.catch(()=>pluginIndexesCache.current === undefined);
|
|
58
|
+
}
|
|
59
|
+
return request;
|
|
60
|
+
}, [
|
|
61
|
+
createPluginIndexes
|
|
62
|
+
]);
|
|
63
|
+
return getPluginIndexes;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
//# sourceMappingURL=plugin-indexes.js.map
|