@perses-dev/plugin-system 0.7.1 → 0.8.1
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/PluginLoadingBoundary/PluginLoader.js +2 -2
- package/dist/cjs/components/PluginLoadingBoundary/PluginLoadingBoundary.js +7 -7
- package/dist/cjs/components/PluginRegistry/PluginRegistry.js +48 -35
- package/dist/cjs/components/PluginRegistry/PluginRegistry.test.js +73 -0
- package/dist/cjs/components/PluginRegistry/index.js +2 -1
- package/dist/cjs/components/PluginRegistry/legacy/PluginRegistry.js +57 -0
- package/dist/cjs/components/PluginRegistry/legacy/index.js +29 -0
- package/dist/cjs/components/PluginRegistry/{registry-state.js → legacy/registry-state.js} +39 -39
- package/dist/cjs/components/PluginRegistry/plugin-indexes.js +67 -0
- package/dist/cjs/components/PluginRegistry/plugin-registry-model.js +25 -0
- package/dist/cjs/components/PluginRegistry/test-plugins/bert/index.js +26 -0
- package/dist/cjs/components/PluginRegistry/test-plugins/bert/plugin.json +32 -0
- package/dist/cjs/components/PluginRegistry/test-plugins/ernie/index.js +23 -0
- package/dist/cjs/components/PluginRegistry/test-plugins/ernie/plugin.json +24 -0
- package/dist/cjs/components/PluginRegistry/test-plugins/index.js +63 -0
- package/dist/cjs/components/index.js +1 -1
- package/dist/cjs/model/graph-queries.js +1 -1
- package/dist/cjs/model/index.js +2 -1
- package/dist/cjs/model/panels.js +26 -10
- package/dist/cjs/model/plugins.js +1 -1
- package/dist/cjs/model/variables.js +1 -1
- package/dist/cjs/model/visual-editing.js +14 -0
- package/dist/cjs/runtime/index.js +1 -0
- package/dist/cjs/runtime/plugins.js +38 -0
- package/dist/cjs/runtime/query-string.js +28 -0
- package/dist/cjs/runtime/template-variables.js +20 -9
- package/dist/cjs/runtime/time-range.js +1 -1
- package/dist/cjs/test/render.js +27 -0
- package/dist/cjs/test/setup-tests.js +24 -0
- package/dist/cjs/utils/cache-keys.js +22 -0
- package/dist/components/PluginLoadingBoundary/PluginLoader.js +1 -1
- package/dist/components/PluginLoadingBoundary/PluginLoadingBoundary.d.ts +2 -2
- package/dist/components/PluginLoadingBoundary/PluginLoadingBoundary.d.ts.map +1 -1
- package/dist/components/PluginLoadingBoundary/PluginLoadingBoundary.js +1 -1
- package/dist/components/PluginRegistry/PluginRegistry.d.ts +6 -21
- package/dist/components/PluginRegistry/PluginRegistry.d.ts.map +1 -1
- package/dist/components/PluginRegistry/PluginRegistry.js +1 -1
- package/dist/components/PluginRegistry/PluginRegistry.test.d.ts +2 -0
- package/dist/components/PluginRegistry/PluginRegistry.test.d.ts.map +1 -0
- package/dist/components/PluginRegistry/PluginRegistry.test.js +1 -0
- package/dist/components/PluginRegistry/index.d.ts +1 -0
- package/dist/components/PluginRegistry/index.d.ts.map +1 -1
- package/dist/components/PluginRegistry/index.js +1 -1
- package/dist/components/PluginRegistry/legacy/PluginRegistry.d.ts +29 -0
- package/dist/components/PluginRegistry/legacy/PluginRegistry.d.ts.map +1 -0
- package/dist/components/PluginRegistry/legacy/PluginRegistry.js +1 -0
- package/dist/components/PluginRegistry/legacy/index.d.ts +2 -0
- package/dist/components/PluginRegistry/legacy/index.d.ts.map +1 -0
- package/dist/components/PluginRegistry/legacy/index.js +1 -0
- package/dist/components/PluginRegistry/{registry-state.d.ts → legacy/registry-state.d.ts} +4 -4
- package/dist/components/PluginRegistry/legacy/registry-state.d.ts.map +1 -0
- package/dist/components/PluginRegistry/legacy/registry-state.js +1 -0
- package/dist/components/PluginRegistry/plugin-indexes.d.ts +11 -0
- package/dist/components/PluginRegistry/plugin-indexes.d.ts.map +1 -0
- package/dist/components/PluginRegistry/plugin-indexes.js +1 -0
- package/dist/components/PluginRegistry/plugin-registry-model.d.ts +10 -0
- package/dist/components/PluginRegistry/plugin-registry-model.d.ts.map +1 -0
- package/dist/components/PluginRegistry/plugin-registry-model.js +1 -0
- package/dist/components/PluginRegistry/test-plugins/bert/index.d.ts +4 -0
- package/dist/components/PluginRegistry/test-plugins/bert/index.d.ts.map +1 -0
- package/dist/components/PluginRegistry/test-plugins/bert/index.js +1 -0
- package/dist/components/PluginRegistry/test-plugins/bert/plugin.json +32 -0
- package/dist/components/PluginRegistry/test-plugins/ernie/index.d.ts +3 -0
- package/dist/components/PluginRegistry/test-plugins/ernie/index.d.ts.map +1 -0
- package/dist/components/PluginRegistry/test-plugins/ernie/index.js +1 -0
- package/dist/components/PluginRegistry/test-plugins/ernie/plugin.json +24 -0
- package/dist/components/PluginRegistry/test-plugins/index.d.ts +6 -0
- package/dist/components/PluginRegistry/test-plugins/index.d.ts.map +1 -0
- package/dist/components/PluginRegistry/test-plugins/index.js +1 -0
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +1 -1
- package/dist/model/graph-queries.js +1 -1
- package/dist/model/index.d.ts +1 -0
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +1 -1
- package/dist/model/panels.d.ts +5 -2
- package/dist/model/panels.d.ts.map +1 -1
- package/dist/model/panels.js +1 -1
- package/dist/model/plugins.d.ts +20 -35
- package/dist/model/plugins.d.ts.map +1 -1
- package/dist/model/variables.d.ts +3 -3
- package/dist/model/variables.d.ts.map +1 -1
- package/dist/model/variables.js +1 -1
- package/dist/model/visual-editing.d.ts +18 -0
- package/dist/model/visual-editing.d.ts.map +1 -0
- package/dist/model/visual-editing.js +1 -0
- package/dist/runtime/index.d.ts +1 -0
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +1 -1
- package/dist/runtime/plugins.d.ts +23 -0
- package/dist/runtime/plugins.d.ts.map +1 -0
- package/dist/runtime/plugins.js +1 -0
- package/dist/runtime/query-string.d.ts +11 -0
- package/dist/runtime/query-string.d.ts.map +1 -0
- package/dist/runtime/query-string.js +1 -0
- package/dist/runtime/template-variables.d.ts +6 -15
- package/dist/runtime/template-variables.d.ts.map +1 -1
- package/dist/runtime/template-variables.js +1 -1
- package/dist/runtime/time-range.d.ts +2 -2
- package/dist/runtime/time-range.d.ts.map +1 -1
- package/dist/test/render.d.ts +7 -0
- package/dist/test/render.d.ts.map +1 -0
- package/dist/test/render.js +1 -0
- package/dist/test/setup-tests.d.ts +2 -0
- package/dist/test/setup-tests.d.ts.map +1 -0
- package/dist/test/setup-tests.js +1 -0
- package/dist/utils/cache-keys.d.ts +6 -0
- package/dist/utils/cache-keys.d.ts.map +1 -0
- package/dist/utils/cache-keys.js +1 -0
- package/package.json +6 -6
- package/dist/cjs/components/PluginRegistry/create-plugin.js +0 -118
- package/dist/components/PluginRegistry/create-plugin.d.ts +0 -27
- package/dist/components/PluginRegistry/create-plugin.d.ts.map +0 -1
- package/dist/components/PluginRegistry/create-plugin.js +0 -1
- package/dist/components/PluginRegistry/registry-state.d.ts.map +0 -1
- package/dist/components/PluginRegistry/registry-state.js +0 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"kind": "PluginModule",
|
|
3
|
+
"metadata": { "name": "Ernie" },
|
|
4
|
+
"spec": {
|
|
5
|
+
"plugins": [
|
|
6
|
+
{
|
|
7
|
+
"pluginType": "Variable",
|
|
8
|
+
"kind": "ErnieVariable",
|
|
9
|
+
"display": {
|
|
10
|
+
"name": "Ernie Variable",
|
|
11
|
+
"description": "A variable plugin that exists in the plugin module"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"pluginType": "Variable",
|
|
16
|
+
"kind": "MissingErnieVariable",
|
|
17
|
+
"display": {
|
|
18
|
+
"name": "Ernie Variable",
|
|
19
|
+
"description": "A variable plugin that exists here in the metadata, but is not in the plugin module"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2022 The Perses Authors
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
17
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
18
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
19
|
+
}
|
|
20
|
+
Object.defineProperty(o, k2, desc);
|
|
21
|
+
}) : (function(o, m, k, k2) {
|
|
22
|
+
if (k2 === undefined) k2 = k;
|
|
23
|
+
o[k2] = m[k];
|
|
24
|
+
}));
|
|
25
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
26
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
27
|
+
}) : function(o, v) {
|
|
28
|
+
o["default"] = v;
|
|
29
|
+
});
|
|
30
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
38
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
39
|
+
};
|
|
40
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
exports.testRegistryProps = void 0;
|
|
42
|
+
const plugin_json_1 = __importDefault(require("./bert/plugin.json"));
|
|
43
|
+
const plugin_json_2 = __importDefault(require("./ernie/plugin.json"));
|
|
44
|
+
// Put all the test plugins into a Map
|
|
45
|
+
const testPlugins = new Map();
|
|
46
|
+
testPlugins.set(plugin_json_1.default, () => Promise.resolve().then(() => __importStar(require('./bert'))));
|
|
47
|
+
testPlugins.set(plugin_json_2.default, () => Promise.resolve().then(() => __importStar(require('./ernie'))));
|
|
48
|
+
/**
|
|
49
|
+
* Some props for testing the PluginRegistry that use the test plugins/metadata in this folder.
|
|
50
|
+
*/
|
|
51
|
+
exports.testRegistryProps = {
|
|
52
|
+
getInstalledPlugins: () => {
|
|
53
|
+
const resources = Array.from(testPlugins.keys());
|
|
54
|
+
return Promise.resolve(resources);
|
|
55
|
+
},
|
|
56
|
+
importPluginModule: (resource) => {
|
|
57
|
+
const importFn = testPlugins.get(resource);
|
|
58
|
+
if (importFn === undefined) {
|
|
59
|
+
throw new Error('Plugin not found');
|
|
60
|
+
}
|
|
61
|
+
return importFn();
|
|
62
|
+
},
|
|
63
|
+
};
|
|
@@ -28,4 +28,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
__exportStar(require("./PluginBoundary"), exports);
|
|
30
30
|
__exportStar(require("./PluginLoadingBoundary"), exports);
|
|
31
|
-
__exportStar(require("./PluginRegistry"), exports);
|
|
31
|
+
__exportStar(require("./PluginRegistry/legacy"), exports);
|
|
@@ -18,7 +18,7 @@ const PluginLoadingBoundary_1 = require("../components/PluginLoadingBoundary");
|
|
|
18
18
|
* Use a Graph Query's results from a graph query plugin at runtime.
|
|
19
19
|
*/
|
|
20
20
|
const useGraphQuery = (definition) => {
|
|
21
|
-
const plugin = (0, PluginLoadingBoundary_1.usePlugin)('GraphQuery', definition);
|
|
21
|
+
const plugin = (0, PluginLoadingBoundary_1.usePlugin)('GraphQuery', definition.kind);
|
|
22
22
|
if (plugin === undefined) {
|
|
23
23
|
// Provide default values while the plugin is being loaded
|
|
24
24
|
return { loading: true };
|
package/dist/cjs/model/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Copyright
|
|
2
|
+
// Copyright 2022 The Perses Authors
|
|
3
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
// you may not use this file except in compliance with the License.
|
|
5
5
|
// You may obtain a copy of the License at
|
|
@@ -30,3 +30,4 @@ __exportStar(require("./graph-queries"), exports);
|
|
|
30
30
|
__exportStar(require("./panels"), exports);
|
|
31
31
|
__exportStar(require("./plugins"), exports);
|
|
32
32
|
__exportStar(require("./variables"), exports);
|
|
33
|
+
__exportStar(require("./visual-editing"), exports);
|
package/dist/cjs/model/panels.js
CHANGED
|
@@ -1,17 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// Copyright 2022 The Perses Authors
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
2
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
15
|
+
exports.usePanelPlugin = void 0;
|
|
5
16
|
const PluginLoadingBoundary_1 = require("../components/PluginLoadingBoundary");
|
|
6
17
|
/**
|
|
7
|
-
*
|
|
18
|
+
* Hook for using a panel plugin at runtime.
|
|
8
19
|
*/
|
|
9
|
-
|
|
10
|
-
const plugin = (0, PluginLoadingBoundary_1.usePlugin)('Panel',
|
|
11
|
-
if (plugin
|
|
12
|
-
return
|
|
20
|
+
function usePanelPlugin(kind) {
|
|
21
|
+
const plugin = (0, PluginLoadingBoundary_1.usePlugin)('Panel', kind);
|
|
22
|
+
if (plugin !== undefined) {
|
|
23
|
+
return plugin;
|
|
13
24
|
}
|
|
14
|
-
|
|
15
|
-
return
|
|
25
|
+
// Return a default/placeholder plugin while loading happens
|
|
26
|
+
return defaultPanelPlugin;
|
|
27
|
+
}
|
|
28
|
+
exports.usePanelPlugin = usePanelPlugin;
|
|
29
|
+
const defaultPanelPlugin = {
|
|
30
|
+
PanelComponent: () => null,
|
|
31
|
+
OptionsEditorComponent: () => null,
|
|
32
|
+
createInitialOptions: () => ({}),
|
|
16
33
|
};
|
|
17
|
-
exports.PanelComponent = PanelComponent;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Copyright
|
|
2
|
+
// Copyright 2022 The Perses Authors
|
|
3
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
// you may not use this file except in compliance with the License.
|
|
5
5
|
// You may obtain a copy of the License at
|
|
@@ -18,7 +18,7 @@ const PluginLoadingBoundary_1 = require("../components/PluginLoadingBoundary");
|
|
|
18
18
|
* Use the variable options from a variable plugin at runtime.
|
|
19
19
|
*/
|
|
20
20
|
const useVariableOptions = (definition) => {
|
|
21
|
-
const plugin = (0, PluginLoadingBoundary_1.usePlugin)('Variable', definition);
|
|
21
|
+
const plugin = (0, PluginLoadingBoundary_1.usePlugin)('Variable', definition.kind);
|
|
22
22
|
if (plugin === undefined) {
|
|
23
23
|
// Provide default values while the plugin is being loaded
|
|
24
24
|
return { data: [], loading: true };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2022 The Perses Authors
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -29,3 +29,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
29
|
__exportStar(require("./datasources"), exports);
|
|
30
30
|
__exportStar(require("./template-variables"), exports);
|
|
31
31
|
__exportStar(require("./time-range"), exports);
|
|
32
|
+
__exportStar(require("./query-string"), exports);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2022 The Perses Authors
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.useListPluginMetadata = exports.usePlugin = void 0;
|
|
16
|
+
const react_query_1 = require("react-query");
|
|
17
|
+
const PluginRegistry_1 = require("../components/PluginRegistry");
|
|
18
|
+
const cache_keys_1 = require("../utils/cache-keys");
|
|
19
|
+
/**
|
|
20
|
+
* Loads a plugin and returns the plugin implementation, along with loading/error state.
|
|
21
|
+
*/
|
|
22
|
+
function usePlugin(pluginType, kind, options) {
|
|
23
|
+
const { getPlugin } = (0, PluginRegistry_1.usePluginRegistry)();
|
|
24
|
+
const queryKey = (0, cache_keys_1.getTypeAndKindKey)(pluginType, kind);
|
|
25
|
+
const { data, isLoading, error } = (0, react_query_1.useQuery)(queryKey, () => getPlugin(pluginType, kind), options);
|
|
26
|
+
return { plugin: data, isLoading, error };
|
|
27
|
+
}
|
|
28
|
+
exports.usePlugin = usePlugin;
|
|
29
|
+
/**
|
|
30
|
+
* Gets a list of plugin metadata for the specified plugin type and returns it, along with loading/error state.
|
|
31
|
+
*/
|
|
32
|
+
function useListPluginMetadata(pluginType, options) {
|
|
33
|
+
const { listPluginMetadata } = (0, PluginRegistry_1.usePluginRegistry)();
|
|
34
|
+
const queryKey = pluginType;
|
|
35
|
+
const { data, isLoading, error } = (0, react_query_1.useQuery)(queryKey, () => listPluginMetadata(pluginType), options);
|
|
36
|
+
return { pluginMetadata: data, isLoading, error };
|
|
37
|
+
}
|
|
38
|
+
exports.useListPluginMetadata = useListPluginMetadata;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2022 The Perses Authors
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.useQueryString = exports.QueryStringContext = void 0;
|
|
16
|
+
const react_1 = require("react");
|
|
17
|
+
exports.QueryStringContext = (0, react_1.createContext)(undefined);
|
|
18
|
+
/**
|
|
19
|
+
* Gets the current query params at runtime.
|
|
20
|
+
*/
|
|
21
|
+
function useQueryString() {
|
|
22
|
+
const ctx = (0, react_1.useContext)(exports.QueryStringContext);
|
|
23
|
+
if (ctx === undefined) {
|
|
24
|
+
throw new Error('No QueryStringContext found. Did you forget a Provider?');
|
|
25
|
+
}
|
|
26
|
+
return ctx;
|
|
27
|
+
}
|
|
28
|
+
exports.useQueryString = useQueryString;
|
|
@@ -12,17 +12,28 @@
|
|
|
12
12
|
// See the License for the specific language governing permissions and
|
|
13
13
|
// limitations under the License.
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
15
|
+
exports.useTemplateVariableValues = exports.TemplateVariableContext = void 0;
|
|
16
16
|
const react_1 = require("react");
|
|
17
|
-
exports.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
*/
|
|
21
|
-
function useTemplateVariables() {
|
|
22
|
-
const ctx = (0, react_1.useContext)(exports.TemplateVariablesContext);
|
|
17
|
+
exports.TemplateVariableContext = (0, react_1.createContext)(undefined);
|
|
18
|
+
function useTemplateVariableContext() {
|
|
19
|
+
const ctx = (0, react_1.useContext)(exports.TemplateVariableContext);
|
|
23
20
|
if (ctx === undefined) {
|
|
24
|
-
throw new Error('No
|
|
21
|
+
throw new Error('No TemplateVariableContext found. Did you forget a Provider?');
|
|
25
22
|
}
|
|
26
23
|
return ctx;
|
|
27
24
|
}
|
|
28
|
-
|
|
25
|
+
function useTemplateVariableValues(names) {
|
|
26
|
+
const { state } = useTemplateVariableContext();
|
|
27
|
+
if (names === undefined) {
|
|
28
|
+
return state;
|
|
29
|
+
}
|
|
30
|
+
const values = {};
|
|
31
|
+
names.forEach((name) => {
|
|
32
|
+
const s = state[name];
|
|
33
|
+
if (s) {
|
|
34
|
+
values[name] = s;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
return values;
|
|
38
|
+
}
|
|
39
|
+
exports.useTemplateVariableValues = useTemplateVariableValues;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Copyright
|
|
2
|
+
// Copyright 2022 The Perses Authors
|
|
3
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
// you may not use this file except in compliance with the License.
|
|
5
5
|
// You may obtain a copy of the License at
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
// Copyright 2022 The Perses Authors
|
|
6
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
// you may not use this file except in compliance with the License.
|
|
8
|
+
// You may obtain a copy of the License at
|
|
9
|
+
//
|
|
10
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
//
|
|
12
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
// See the License for the specific language governing permissions and
|
|
16
|
+
// limitations under the License.
|
|
17
|
+
const react_1 = require("@testing-library/react");
|
|
18
|
+
const react_query_1 = require("react-query");
|
|
19
|
+
// Don't retry in tests
|
|
20
|
+
const queryClient = new react_query_1.QueryClient({ defaultOptions: { queries: { refetchOnWindowFocus: false, retry: false } } });
|
|
21
|
+
/**
|
|
22
|
+
* Test helper to render a React component with some common app-level providers wrapped around it.
|
|
23
|
+
*/
|
|
24
|
+
function renderWithContext(ui, options) {
|
|
25
|
+
return (0, react_1.render)((0, jsx_runtime_1.jsx)(react_query_1.QueryClientProvider, { client: queryClient, children: ui }), options);
|
|
26
|
+
}
|
|
27
|
+
exports.renderWithContext = renderWithContext;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2022 The Perses Authors
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const react_query_1 = require("react-query");
|
|
16
|
+
// Add testing library assertions
|
|
17
|
+
require("@testing-library/jest-dom/extend-expect");
|
|
18
|
+
(0, react_query_1.setLogger)({
|
|
19
|
+
log: console.log,
|
|
20
|
+
warn: console.warn,
|
|
21
|
+
error: () => {
|
|
22
|
+
// Don't log network errors to the console during tests
|
|
23
|
+
},
|
|
24
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2022 The Perses Authors
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.getTypeAndKindKey = void 0;
|
|
16
|
+
/**
|
|
17
|
+
* Gets a unique key for a plugin type/kind that can be used as a cache key.
|
|
18
|
+
*/
|
|
19
|
+
function getTypeAndKindKey(pluginType, kind) {
|
|
20
|
+
return `${pluginType}:${kind}`;
|
|
21
|
+
}
|
|
22
|
+
exports.getTypeAndKindKey = getTypeAndKindKey;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useQuery}from"react-query";import{usePluginRegistry}from"../PluginRegistry";export function PluginLoader(r){const{pluginType:e,kind:i}=r,{loadPlugin:u}=usePluginRegistry(),{error:n}=useQuery(`PluginLoader:${e}_${i}`,(()=>{if(void 0===u)throw new Error("PluginRegistry loadPlugin not available");return u(e,i)}),{enabled:void 0!==u});if(null!=n)throw n;return null}
|
|
1
|
+
import{useQuery}from"react-query";import{usePluginRegistry}from"../PluginRegistry/legacy";export function PluginLoader(r){const{pluginType:e,kind:i}=r,{loadPlugin:u}=usePluginRegistry(),{error:n}=useQuery(`PluginLoader:${e}_${i}`,(()=>{if(void 0===u)throw new Error("PluginRegistry loadPlugin not available");return u(e,i)}),{enabled:void 0!==u});if(null!=n)throw n;return null}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { JsonObject } from '@perses-dev/core';
|
|
3
|
-
import { PluginType,
|
|
3
|
+
import { PluginType, PluginImplementation } from '../../model';
|
|
4
4
|
export interface PluginLoadingBoundaryProps {
|
|
5
5
|
fallback: React.ReactNode;
|
|
6
6
|
children?: React.ReactNode;
|
|
@@ -22,6 +22,6 @@ export declare function usePluginLoadingBoundary(): PluginLoadingBoundaryContext
|
|
|
22
22
|
* Generic usePlugin that will register the dependency with the nearest LoadingBoundary and get the plugin if it's
|
|
23
23
|
* already loaded
|
|
24
24
|
*/
|
|
25
|
-
export declare function usePlugin<Type extends PluginType>(pluginType: Type,
|
|
25
|
+
export declare function usePlugin<Type extends PluginType>(pluginType: Type, kind: string): PluginImplementation<Type, JsonObject> | undefined;
|
|
26
26
|
export {};
|
|
27
27
|
//# sourceMappingURL=PluginLoadingBoundary.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PluginLoadingBoundary.d.ts","sourceRoot":"","sources":["../../../src/components/PluginLoadingBoundary/PluginLoadingBoundary.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C,OAAO,EAAE,UAAU,EAAoB,
|
|
1
|
+
{"version":3,"file":"PluginLoadingBoundary.d.ts","sourceRoot":"","sources":["../../../src/components/PluginLoadingBoundary/PluginLoadingBoundary.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C,OAAO,EAAE,UAAU,EAAoB,oBAAoB,EAAE,MAAM,aAAa,CAAC;AASjF,MAAM,WAAW,0BAA0B;IACzC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,0BAA0B,eAgEtE;AAED,UAAU,gCAAgC;IACxC,wBAAwB,EAAE,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAC1E;AAID;;GAEG;AACH,wBAAgB,wBAAwB,qCAMvC;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,IAAI,SAAS,UAAU,EAC/C,UAAU,EAAE,IAAI,EAChB,IAAI,EAAE,MAAM,GACX,oBAAoB,CAAC,IAAI,EAAE,UAAU,CAAC,GAAG,SAAS,CAUpD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{Fragment,createContext,useContext,useMemo,useCallback,useEffect}from"react";import{useImmer}from"use-immer";import{ALL_PLUGIN_TYPES}from"../../model";import{usePluginRegistry}from"../PluginRegistry";import{PluginLoader}from"./PluginLoader";export function PluginLoadingBoundary(e){const{fallback:n,children:o}=e,{plugins:r}=usePluginRegistry(),[t,
|
|
1
|
+
import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{Fragment,createContext,useContext,useMemo,useCallback,useEffect}from"react";import{useImmer}from"use-immer";import{ALL_PLUGIN_TYPES}from"../../model";import{usePluginRegistry}from"../PluginRegistry/legacy";import{PluginLoader}from"./PluginLoader";export function PluginLoadingBoundary(e){const{fallback:n,children:o}=e,{plugins:r}=usePluginRegistry(),[t,u]=useImmer((()=>{const e={};for(const n of ALL_PLUGIN_TYPES)e[n]={};return e})),i=useCallback(((e,n)=>{u((o=>{o[e][n]=!0}))}),[u]),s=useMemo((()=>({registerPluginDependency:i})),[i]),{loaders:g,fragmentKey:a}=useMemo((()=>{let e="";const n=[];for(const o of ALL_PLUGIN_TYPES){e+=`_${o}:`;const u=t[o];for(const t in u)e+=t,void 0===r[o][t]&&n.push(_jsx(PluginLoader,{pluginType:o,kind:t},`${o}:${t}`))}return{loaders:n,fragmentKey:e}}),[r,t]),l=0===g.length;return _jsxs(PluginLoadingBoundaryContext.Provider,{value:s,children:[g,l&&_jsx(Fragment,{children:o},a),!1===l&&n]})}const PluginLoadingBoundaryContext=createContext(void 0);export function usePluginLoadingBoundary(){const e=useContext(PluginLoadingBoundaryContext);if(void 0===e)throw new Error("PluginLoadingBoundary context not found. Did you forget a Provider?");return e}export function usePlugin(e,n){const{registerPluginDependency:o}=usePluginLoadingBoundary();useEffect((()=>{o(e,n)}),[e,n,o]);const{plugins:r}=usePluginRegistry();return r[e][n]}
|
|
@@ -1,29 +1,14 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { PluginModuleResource } from '../../model';
|
|
3
|
+
import { GetInstalledPlugins } from './plugin-indexes';
|
|
4
4
|
export interface PluginRegistryProps {
|
|
5
5
|
children?: React.ReactNode;
|
|
6
|
-
getInstalledPlugins:
|
|
7
|
-
importPluginModule: (resource:
|
|
6
|
+
getInstalledPlugins: GetInstalledPlugins;
|
|
7
|
+
importPluginModule: (resource: PluginModuleResource) => Promise<unknown>;
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
|
-
* PluginRegistryContext provider that keeps track of all available plugins and
|
|
11
|
-
*
|
|
10
|
+
* PluginRegistryContext provider that keeps track of all available plugins and provides an API for getting them or
|
|
11
|
+
* querying the metadata about them.
|
|
12
12
|
*/
|
|
13
13
|
export declare function PluginRegistry(props: PluginRegistryProps): JSX.Element;
|
|
14
|
-
export interface PluginRegistryContextType {
|
|
15
|
-
/**
|
|
16
|
-
* Plugins that have already been loaded and are available for use.
|
|
17
|
-
*/
|
|
18
|
-
plugins: LoadedPluginsByTypeAndKind;
|
|
19
|
-
/**
|
|
20
|
-
* Asks the plugin registry to load the specified plugin. This will be undefined until the list of available plugins
|
|
21
|
-
* has finished loading.
|
|
22
|
-
*/
|
|
23
|
-
loadPlugin?: (pluginType: PluginType, kind: string) => Promise<void>;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Gets the PluginRegistryContext, throwing if the provider is missing.
|
|
27
|
-
*/
|
|
28
|
-
export declare function usePluginRegistry(): PluginRegistryContextType;
|
|
29
14
|
//# sourceMappingURL=PluginRegistry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PluginRegistry.d.ts","sourceRoot":"","sources":["../../../src/components/PluginRegistry/PluginRegistry.tsx"],"names":[],"mappings":";AAeA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"PluginRegistry.d.ts","sourceRoot":"","sources":["../../../src/components/PluginRegistry/PluginRegistry.tsx"],"names":[],"mappings":";AAeA,OAAO,EAAE,oBAAoB,EAA4C,MAAM,aAAa,CAAC;AAE7F,OAAO,EAAE,mBAAmB,EAAoB,MAAM,kBAAkB,CAAC;AAGzE,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,mBAAmB,EAAE,mBAAmB,CAAC;IACzC,kBAAkB,EAAE,CAAC,QAAQ,EAAE,oBAAoB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CAC1E;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,eA6DxD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{useEvent}from"@perses-dev/core";import{useRef,useCallback,useMemo}from"react";import{getTypeAndKindKey}from"../../utils/cache-keys";import{usePluginIndexes}from"./plugin-indexes";import{PluginRegistryContext}from"./plugin-registry-model";export function PluginRegistry(e){const{getInstalledPlugins:t,importPluginModule:n,children:r}=e,i=usePluginIndexes(t),s=useRef(new Map),u=useEvent((e=>{let t=s.current.get(e);return void 0===t&&(t=n(e),s.current.set(e,t),t.catch((()=>s.current.delete(e)))),t})),o=useCallback((async(e,t)=>{const n=await i(),r=getTypeAndKindKey(e,t),s=n.pluginResourcesByTypeAndKind.get(r);if(void 0===s)throw new Error(`A ${e} plugin for kind '${t}' is not installed`);const o=(await u(s))[t];if(void 0===o)throw new Error(`The ${e} plugin for kind '${t}' is missing from the ${s.metadata.name} plugin module`);return o}),[i,u]),l=useCallback((async e=>{var t;return null!==(t=(await i()).pluginMetadataByType.get(e))&&void 0!==t?t:[]}),[i]),a=useMemo((()=>({getPlugin:o,listPluginMetadata:l})),[o,l]);return _jsx(PluginRegistryContext.Provider,{value:a,children:r})}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PluginRegistry.test.d.ts","sourceRoot":"","sources":["../../../src/components/PluginRegistry/PluginRegistry.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{screen}from"@testing-library/react";import{useListPluginMetadata,usePlugin}from"../../runtime/plugins";import{renderWithContext}from"../../test/render";import{PluginRegistry}from"./PluginRegistry";import{testRegistryProps}from"./test-plugins";describe("PluginRegistry",(()=>{const e=e=>{renderWithContext(_jsx(PluginRegistry,{...testRegistryProps,children:e}))};it("can load a plugin that exists",(async()=>{e(_jsx(PluginConsumer,{pluginType:"Variable",kind:"ErnieVariable"}));const t=await screen.findByText("Has plugin: true",void 0,{timeout:3e3});expect(t).toBeInTheDocument()})),it("errors when plugin is not installed",(async()=>{e(_jsx(PluginConsumer,{pluginType:"GraphQuery",kind:"NotInstalled"}));const t=await screen.findByText(/error:/i);expect(t).toBeInTheDocument(),expect(t).toHaveTextContent(/not installed/i)})),it("errors when plugin is missing from the module",(async()=>{e(_jsx(PluginConsumer,{pluginType:"Variable",kind:"MissingErnieVariable"}));const t=await screen.findByText(/error:/i);expect(t).toBeInTheDocument(),expect(t).toHaveTextContent(/missing/i)})),it("lists metadata for plugin metadata that exists",(async()=>{e(_jsx(MetadataConsumer,{pluginType:"Variable"}));const t=await screen.findByRole("table");expect(t).toBeInTheDocument();const n=screen.getAllByRole("row");expect(n).toHaveLength(3)})),it("lists metadata for plugin types with no plugins available",(async()=>{e(_jsx(MetadataConsumer,{pluginType:"GraphQuery"}));const t=await screen.findByRole("table");expect(t).toBeInTheDocument();const n=screen.queryAllByRole("row");expect(n).toHaveLength(0)}))}));const PluginConsumer=e=>{const{plugin:t,isLoading:n,error:i}=usePlugin(e.pluginType,e.kind);return i?_jsxs("div",{children:["Error: ",i.message]}):n?_jsx("div",{children:"Loading"}):_jsxs("div",{children:["Has plugin: ",(void 0!==t).toString()]})},MetadataConsumer=e=>{const{pluginMetadata:t,isLoading:n,error:i}=useListPluginMetadata(e.pluginType);return i?_jsxs("div",{children:["Error: ",i.message]}):n?_jsx("div",{children:"Loading"}):void 0===t?null:_jsx("table",{children:_jsx("tbody",{children:t.map((e=>_jsxs("tr",{children:[_jsx("td",{children:e.pluginType}),_jsx("td",{children:e.kind}),_jsx("td",{children:e.display.name}),_jsx("td",{children:e.display.description})]},e.kind)))})})};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/PluginRegistry/index.ts"],"names":[],"mappings":"AAaA,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/PluginRegistry/index.ts"],"names":[],"mappings":"AAaA,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"./PluginRegistry";
|
|
1
|
+
export*from"./plugin-registry-model";export*from"./PluginRegistry";
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { PluginModuleResource, PluginType } from '../../../model';
|
|
3
|
+
import { LoadedPluginsByTypeAndKind } from './registry-state';
|
|
4
|
+
export interface PluginRegistryProps {
|
|
5
|
+
children?: React.ReactNode;
|
|
6
|
+
getInstalledPlugins: () => Promise<PluginModuleResource[]>;
|
|
7
|
+
importPluginModule: (resource: PluginModuleResource) => Promise<unknown>;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* PluginRegistryContext provider that keeps track of all available plugins and
|
|
11
|
+
* their implementations once they've been loaded.
|
|
12
|
+
*/
|
|
13
|
+
export declare function PluginRegistry(props: PluginRegistryProps): JSX.Element;
|
|
14
|
+
export interface PluginRegistryContextType {
|
|
15
|
+
/**
|
|
16
|
+
* Plugins that have already been loaded and are available for use.
|
|
17
|
+
*/
|
|
18
|
+
plugins: LoadedPluginsByTypeAndKind;
|
|
19
|
+
/**
|
|
20
|
+
* Asks the plugin registry to load the specified plugin. This will be undefined until the list of available plugins
|
|
21
|
+
* has finished loading.
|
|
22
|
+
*/
|
|
23
|
+
loadPlugin?: (pluginType: PluginType, kind: string) => Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Gets the PluginRegistryContext, throwing if the provider is missing.
|
|
27
|
+
*/
|
|
28
|
+
export declare function usePluginRegistry(): PluginRegistryContextType;
|
|
29
|
+
//# sourceMappingURL=PluginRegistry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PluginRegistry.d.ts","sourceRoot":"","sources":["../../../../src/components/PluginRegistry/legacy/PluginRegistry.tsx"],"names":[],"mappings":";AAeA,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAE,0BAA0B,EAAoB,MAAM,kBAAkB,CAAC;AAEhF,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,mBAAmB,EAAE,MAAM,OAAO,CAAC,oBAAoB,EAAE,CAAC,CAAC;IAC3D,kBAAkB,EAAE,CAAC,QAAQ,EAAE,oBAAoB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CAC1E;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,eA+BxD;AAID,MAAM,WAAW,yBAAyB;IACxC;;OAEG;IACH,OAAO,EAAE,0BAA0B,CAAC;IAEpC;;;OAGG;IACH,UAAU,CAAC,EAAE,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACtE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,yBAAyB,CAM7D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{createContext,useContext,useMemo,useCallback}from"react";import{useQuery}from"react-query";import{useRegistryState}from"./registry-state";export function PluginRegistry(e){const{children:t,getInstalledPlugins:i,importPluginModule:r}=e,o=useQuery("installed-plugins",i),{loadablePlugins:n,plugins:s,register:u}=useRegistryState(o.data),l=useCallback((async(e,t)=>{if(void 0!==s[e][t])return;const i=n[e][t];if(void 0===i)throw new Error(`No ${e} plugin is available for kind ${t}`);const o=await r(i);u(i,o)}),[s,n,r,u]),a=useMemo((()=>({plugins:s,loadPlugin:o.isLoading?void 0:l})),[o.isLoading,s,l]);return _jsx(PluginRegistryContext.Provider,{value:a,children:t})}const PluginRegistryContext=createContext(void 0);export function usePluginRegistry(){const e=useContext(PluginRegistryContext);if(void 0===e)throw new Error("No PluginRegistry context found. Did you forget a Provider?");return e}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/PluginRegistry/legacy/index.ts"],"names":[],"mappings":"AAaA,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export*from"./PluginRegistry";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { JsonObject } from '@perses-dev/core';
|
|
2
|
-
import {
|
|
2
|
+
import { PluginModuleResource, PluginType, PluginImplementation } from '../../../model';
|
|
3
3
|
export declare type PluginResourcesByTypeAndKind = {
|
|
4
|
-
[K in PluginType]: Record<string,
|
|
4
|
+
[K in PluginType]: Record<string, PluginModuleResource>;
|
|
5
5
|
};
|
|
6
6
|
export declare type LoadedPluginsByTypeAndKind = {
|
|
7
7
|
[Type in PluginType]: Record<string, PluginImplementation<Type, JsonObject>>;
|
|
@@ -10,9 +10,9 @@ export declare type LoadedPluginsByTypeAndKind = {
|
|
|
10
10
|
* Hook for setting up plugin registry state. Returns the state, plus a function
|
|
11
11
|
* for registering plugins with that state.
|
|
12
12
|
*/
|
|
13
|
-
export declare function useRegistryState(installedPlugins?:
|
|
13
|
+
export declare function useRegistryState(installedPlugins?: PluginModuleResource[]): {
|
|
14
14
|
loadablePlugins: PluginResourcesByTypeAndKind;
|
|
15
15
|
plugins: LoadedPluginsByTypeAndKind;
|
|
16
|
-
register: (pluginModule:
|
|
16
|
+
register: (resource: PluginModuleResource, pluginModule: unknown) => void;
|
|
17
17
|
};
|
|
18
18
|
//# sourceMappingURL=registry-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry-state.d.ts","sourceRoot":"","sources":["../../../../src/components/PluginRegistry/legacy/registry-state.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAEL,oBAAoB,EACpB,UAAU,EAEV,oBAAoB,EAIrB,MAAM,gBAAgB,CAAC;AAGxB,oBAAY,4BAA4B,GAAG;KACxC,CAAC,IAAI,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC;CACxD,CAAC;AAGF,oBAAY,0BAA0B,GAAG;KACtC,IAAI,IAAI,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;CAC7E,CAAC;AAEF;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,gBAAgB,CAAC,EAAE,oBAAoB,EAAE;;;yBAsC3D,oBAAoB,gBAAgB,OAAO,KAAG,IAAI;EAgDhE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useCallback,useMemo,useRef}from"react";import{useImmer}from"use-immer";import{ALL_PLUGIN_TYPES}from"../../../model";export function useRegistryState(e){const n=useMemo((()=>{const n={};for(const e of ALL_PLUGIN_TYPES)n[e]={};if(void 0===e)return n;for(const r of e)for(const e of r.spec.plugins){const{pluginType:o,kind:s}=e,t=n[o];void 0===t[s]?t[s]=r:console.warn(`Got multiple ${o} plugin definitions for kind ${s}`)}return n}),[e]),[r,o]=useImmer((()=>{const e={};for(const n of ALL_PLUGIN_TYPES)e[n]={};return e})),s=useRef(new Set),t=useCallback(((e,n)=>{if(s.current.has(n))return;const r=n;o((n=>{for(const o of e.spec.plugins){const{pluginType:s,kind:t}=o,i=r[t];if(void 0!==i)switch(s){case"Variable":n.Variable[t]=i;break;case"Panel":n.Panel[t]=i;break;case"GraphQuery":n.GraphQuery[t]=i;break;default:throw new Error(`Unhandled plugin config: ${s}`)}else console.warn(`Could not find ${s} plugin for kind '${t}' in ${e.metadata.name}`)}})),s.current.add(n)}),[o]);return{loadablePlugins:n,plugins:r,register:t}}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PluginMetadata, PluginModuleResource } from '../../model';
|
|
2
|
+
export declare type GetInstalledPlugins = () => Promise<PluginModuleResource[]>;
|
|
3
|
+
export interface PluginIndexes {
|
|
4
|
+
pluginResourcesByTypeAndKind: Map<string, PluginModuleResource>;
|
|
5
|
+
pluginMetadataByType: Map<string, PluginMetadata[]>;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Returns an async callback for getting indexes of the installed plugin data.
|
|
9
|
+
*/
|
|
10
|
+
export declare function usePluginIndexes(getInstalledPlugins: GetInstalledPlugins): () => Promise<PluginIndexes>;
|
|
11
|
+
//# sourceMappingURL=plugin-indexes.d.ts.map
|