@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.
Files changed (149) hide show
  1. package/dist/cjs/components/PluginRegistry/PluginRegistry.js +43 -29
  2. package/dist/cjs/components/PluginRegistry/PluginRegistry.test.js +114 -38
  3. package/dist/cjs/components/PluginRegistry/index.js +17 -18
  4. package/dist/cjs/components/PluginRegistry/plugin-indexes.js +23 -20
  5. package/dist/cjs/components/PluginRegistry/plugin-registry-model.js +17 -7
  6. package/dist/cjs/components/PluginRegistry/test-plugins/bert/index.js +22 -12
  7. package/dist/cjs/components/PluginRegistry/test-plugins/ernie/index.js +20 -8
  8. package/dist/cjs/components/PluginRegistry/test-plugins/index.js +59 -39
  9. package/dist/cjs/components/index.js +17 -20
  10. package/dist/cjs/index.js +19 -20
  11. package/dist/cjs/model/datasource.js +16 -0
  12. package/dist/cjs/model/index.js +21 -21
  13. package/dist/cjs/model/panels.js +4 -21
  14. package/dist/cjs/model/plugins.js +4 -7
  15. package/dist/cjs/model/time-series-queries.js +16 -0
  16. package/dist/cjs/model/variables.js +5 -17
  17. package/dist/cjs/model/visual-editing.js +10 -2
  18. package/dist/cjs/runtime/datasources.js +20 -13
  19. package/dist/cjs/runtime/index.js +22 -21
  20. package/dist/cjs/runtime/plugins.js +25 -22
  21. package/dist/cjs/runtime/query-string.js +17 -10
  22. package/dist/cjs/runtime/template-variables.js +34 -16
  23. package/dist/cjs/runtime/time-range.js +17 -10
  24. package/dist/cjs/runtime/time-series-queries.js +58 -0
  25. package/dist/cjs/test/render.js +32 -13
  26. package/dist/cjs/test/setup-tests.js +4 -10
  27. package/dist/cjs/utils/cache-keys.js +8 -7
  28. package/dist/components/PluginRegistry/PluginRegistry.js +81 -1
  29. package/dist/components/PluginRegistry/PluginRegistry.js.map +1 -0
  30. package/dist/components/PluginRegistry/PluginRegistry.test.js +142 -1
  31. package/dist/components/PluginRegistry/PluginRegistry.test.js.map +1 -0
  32. package/dist/components/PluginRegistry/index.js +16 -1
  33. package/dist/components/PluginRegistry/index.js.map +1 -0
  34. package/dist/components/PluginRegistry/plugin-indexes.js +66 -1
  35. package/dist/components/PluginRegistry/plugin-indexes.js.map +1 -0
  36. package/dist/components/PluginRegistry/plugin-registry-model.d.ts +1 -2
  37. package/dist/components/PluginRegistry/plugin-registry-model.d.ts.map +1 -1
  38. package/dist/components/PluginRegistry/plugin-registry-model.js +23 -1
  39. package/dist/components/PluginRegistry/plugin-registry-model.js.map +1 -0
  40. package/dist/components/PluginRegistry/test-plugins/bert/index.js +25 -1
  41. package/dist/components/PluginRegistry/test-plugins/bert/index.js.map +1 -0
  42. package/dist/components/PluginRegistry/test-plugins/ernie/index.d.ts.map +1 -1
  43. package/dist/components/PluginRegistry/test-plugins/ernie/index.js +30 -1
  44. package/dist/components/PluginRegistry/test-plugins/ernie/index.js.map +1 -0
  45. package/dist/components/PluginRegistry/test-plugins/index.js +35 -1
  46. package/dist/components/PluginRegistry/test-plugins/index.js.map +1 -0
  47. package/dist/components/index.d.ts +1 -3
  48. package/dist/components/index.d.ts.map +1 -1
  49. package/dist/components/index.js +15 -1
  50. package/dist/components/index.js.map +1 -0
  51. package/dist/index.js +17 -1
  52. package/dist/index.js.map +1 -0
  53. package/dist/model/datasource.d.ts +9 -0
  54. package/dist/model/datasource.d.ts.map +1 -0
  55. package/dist/model/datasource.js +15 -0
  56. package/dist/model/datasource.js.map +1 -0
  57. package/dist/model/index.d.ts +2 -1
  58. package/dist/model/index.d.ts.map +1 -1
  59. package/dist/model/index.js +20 -1
  60. package/dist/model/index.js.map +1 -0
  61. package/dist/model/panels.d.ts +7 -11
  62. package/dist/model/panels.d.ts.map +1 -1
  63. package/dist/model/panels.js +15 -1
  64. package/dist/model/panels.js.map +1 -0
  65. package/dist/model/plugins.d.ts +16 -25
  66. package/dist/model/plugins.d.ts.map +1 -1
  67. package/dist/model/plugins.js +15 -1
  68. package/dist/model/plugins.js.map +1 -0
  69. package/dist/model/time-series-queries.d.ts +28 -0
  70. package/dist/model/time-series-queries.d.ts.map +1 -0
  71. package/dist/model/time-series-queries.js +15 -0
  72. package/dist/model/time-series-queries.js.map +1 -0
  73. package/dist/model/variables.d.ts +16 -11
  74. package/dist/model/variables.d.ts.map +1 -1
  75. package/dist/model/variables.js +15 -1
  76. package/dist/model/variables.js.map +1 -0
  77. package/dist/model/visual-editing.d.ts +5 -6
  78. package/dist/model/visual-editing.d.ts.map +1 -1
  79. package/dist/model/visual-editing.js +15 -1
  80. package/dist/model/visual-editing.js.map +1 -0
  81. package/dist/runtime/datasources.d.ts +5 -9
  82. package/dist/runtime/datasources.d.ts.map +1 -1
  83. package/dist/runtime/datasources.js +23 -1
  84. package/dist/runtime/datasources.js.map +1 -0
  85. package/dist/runtime/index.d.ts +3 -1
  86. package/dist/runtime/index.d.ts.map +1 -1
  87. package/dist/runtime/index.js +20 -1
  88. package/dist/runtime/index.js.map +1 -0
  89. package/dist/runtime/plugins.d.ts +5 -14
  90. package/dist/runtime/plugins.d.ts.map +1 -1
  91. package/dist/runtime/plugins.js +33 -1
  92. package/dist/runtime/plugins.js.map +1 -0
  93. package/dist/runtime/query-string.js +25 -1
  94. package/dist/runtime/query-string.js.map +1 -0
  95. package/dist/runtime/template-variables.d.ts +10 -1
  96. package/dist/runtime/template-variables.d.ts.map +1 -1
  97. package/dist/runtime/template-variables.js +44 -1
  98. package/dist/runtime/template-variables.js.map +1 -0
  99. package/dist/runtime/time-range.js +25 -1
  100. package/dist/runtime/time-range.js.map +1 -0
  101. package/dist/runtime/time-series-queries.d.ts +14 -0
  102. package/dist/runtime/time-series-queries.d.ts.map +1 -0
  103. package/dist/runtime/time-series-queries.js +54 -0
  104. package/dist/runtime/time-series-queries.js.map +1 -0
  105. package/dist/test/render.d.ts.map +1 -1
  106. package/dist/test/render.js +42 -1
  107. package/dist/test/render.js.map +1 -0
  108. package/dist/test/setup-tests.d.ts.map +1 -1
  109. package/dist/test/setup-tests.js +16 -1
  110. package/dist/test/setup-tests.js.map +1 -0
  111. package/dist/utils/cache-keys.js +19 -1
  112. package/dist/utils/cache-keys.js.map +1 -0
  113. package/package.json +11 -8
  114. package/dist/cjs/components/PluginBoundary.js +0 -14
  115. package/dist/cjs/components/PluginLoadingBoundary/PluginLoader.js +0 -39
  116. package/dist/cjs/components/PluginLoadingBoundary/PluginLoadingBoundary.js +0 -85
  117. package/dist/cjs/components/PluginLoadingBoundary/index.js +0 -29
  118. package/dist/cjs/components/PluginRegistry/legacy/PluginRegistry.js +0 -57
  119. package/dist/cjs/components/PluginRegistry/legacy/index.js +0 -29
  120. package/dist/cjs/components/PluginRegistry/legacy/registry-state.js +0 -97
  121. package/dist/cjs/components/PluginRegistry/test-plugins/bert/plugin.json +0 -32
  122. package/dist/cjs/components/PluginRegistry/test-plugins/ernie/plugin.json +0 -24
  123. package/dist/cjs/model/graph-queries.js +0 -28
  124. package/dist/components/PluginBoundary.d.ts +0 -13
  125. package/dist/components/PluginBoundary.d.ts.map +0 -1
  126. package/dist/components/PluginBoundary.js +0 -1
  127. package/dist/components/PluginLoadingBoundary/PluginLoader.d.ts +0 -11
  128. package/dist/components/PluginLoadingBoundary/PluginLoader.d.ts.map +0 -1
  129. package/dist/components/PluginLoadingBoundary/PluginLoader.js +0 -1
  130. package/dist/components/PluginLoadingBoundary/PluginLoadingBoundary.d.ts +0 -27
  131. package/dist/components/PluginLoadingBoundary/PluginLoadingBoundary.d.ts.map +0 -1
  132. package/dist/components/PluginLoadingBoundary/PluginLoadingBoundary.js +0 -1
  133. package/dist/components/PluginLoadingBoundary/index.d.ts +0 -2
  134. package/dist/components/PluginLoadingBoundary/index.d.ts.map +0 -1
  135. package/dist/components/PluginLoadingBoundary/index.js +0 -1
  136. package/dist/components/PluginRegistry/legacy/PluginRegistry.d.ts +0 -29
  137. package/dist/components/PluginRegistry/legacy/PluginRegistry.d.ts.map +0 -1
  138. package/dist/components/PluginRegistry/legacy/PluginRegistry.js +0 -1
  139. package/dist/components/PluginRegistry/legacy/index.d.ts +0 -2
  140. package/dist/components/PluginRegistry/legacy/index.d.ts.map +0 -1
  141. package/dist/components/PluginRegistry/legacy/index.js +0 -1
  142. package/dist/components/PluginRegistry/legacy/registry-state.d.ts +0 -18
  143. package/dist/components/PluginRegistry/legacy/registry-state.d.ts.map +0 -1
  144. package/dist/components/PluginRegistry/legacy/registry-state.js +0 -1
  145. package/dist/components/PluginRegistry/test-plugins/bert/plugin.json +0 -32
  146. package/dist/components/PluginRegistry/test-plugins/ernie/plugin.json +0 -24
  147. package/dist/model/graph-queries.d.ts +0 -36
  148. package/dist/model/graph-queries.d.ts.map +0 -1
  149. package/dist/model/graph-queries.js +0 -1
@@ -1 +1,19 @@
1
- export function getTypeAndKindKey(e,n){return`${e}:${n}`}
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
+ /**
14
+ * Gets a unique key for a plugin type/kind that can be used as a cache key.
15
+ */ export function getTypeAndKindKey(pluginType, kind) {
16
+ return `${pluginType}:${kind}`;
17
+ }
18
+
19
+ //# sourceMappingURL=cache-keys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/cache-keys.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\nimport { PluginType } from '../model';\n\n/**\n * Gets a unique key for a plugin type/kind that can be used as a cache key.\n */\nexport function getTypeAndKindKey(pluginType: PluginType, kind: string) {\n return `${pluginType}:${kind}`;\n}\n"],"names":["getTypeAndKindKey","pluginType","kind"],"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;AAIjC;;CAEC,GACD,OAAO,SAASA,iBAAiB,CAACC,UAAsB,EAAEC,IAAY,EAAE;IACtE,OAAO,CAAC,EAAED,UAAU,CAAC,CAAC,EAAEC,IAAI,CAAC,CAAC,CAAC;AACjC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perses-dev/plugin-system",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "The plugin feature in Pereses",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/perses/perses/blob/main/README.md",
@@ -12,26 +12,29 @@
12
12
  "url": "https://github.com/perses/perses/issues"
13
13
  },
14
14
  "module": "dist/index.js",
15
- "main": "dist/cjs/index.js",
15
+ "main": "dist//cjs/index.js",
16
16
  "types": "dist/index.d.ts",
17
17
  "scripts": {
18
18
  "clean": "rimraf dist/",
19
- "build": "tsc --build",
20
- "build:cjs": "tsc --project ./tsconfig.cjs.json",
19
+ "build": "concurrently \"npm:build:*\"",
20
+ "build:cjs": "swc ./src -d dist/cjs --config-file ../.cjs.swcrc",
21
+ "build:esm": "swc ./src -d dist --config-file ../.swcrc",
22
+ "build:types": "tsc --emitDeclarationOnly --declaration --preserveWatchOutput",
23
+ "start": "concurrently -P \"npm:build:* -- {*}\" -- --watch",
21
24
  "test": "TZ=UTC jest",
22
25
  "lint": "eslint src --ext .ts,.tsx",
23
26
  "lint:fix": "eslint --fix src --ext .ts,.tsx"
24
27
  },
25
28
  "dependencies": {
26
- "@perses-dev/components": "^0.8.0",
27
- "@perses-dev/core": "^0.8.0",
29
+ "@perses-dev/components": "^0.9.0",
30
+ "@perses-dev/core": "^0.9.0",
28
31
  "immer": "^9.0.15",
29
32
  "use-immer": "^0.7.0"
30
33
  },
31
34
  "peerDependencies": {
35
+ "@tanstack/react-query": "^4.7.1",
32
36
  "react": "^17.0.2 || ^18.0.0",
33
- "react-dom": "^17.0.2 || ^18.0.0",
34
- "react-query": "^3.34.16"
37
+ "react-dom": "^17.0.2 || ^18.0.0"
35
38
  },
36
39
  "files": [
37
40
  "dist"
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PluginBoundary = void 0;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
- const components_1 = require("@perses-dev/components");
6
- const PluginLoadingBoundary_1 = require("./PluginLoadingBoundary");
7
- /**
8
- * Combination ErrorBoundary and PluginLoadingBoundary.
9
- */
10
- function PluginBoundary(props) {
11
- const { ErrorFallbackComponent, loadingFallback, children } = props;
12
- return ((0, jsx_runtime_1.jsx)(components_1.ErrorBoundary, { FallbackComponent: ErrorFallbackComponent, children: (0, jsx_runtime_1.jsx)(PluginLoadingBoundary_1.PluginLoadingBoundary, { fallback: loadingFallback, children: children }) }));
13
- }
14
- exports.PluginBoundary = PluginBoundary;
@@ -1,39 +0,0 @@
1
- "use strict";
2
- // Copyright 2021 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.PluginLoader = void 0;
16
- const react_query_1 = require("react-query");
17
- const legacy_1 = require("../PluginRegistry/legacy");
18
- /**
19
- * Uses the PluginRegistry to load the specified plugin and throws any errors
20
- * encountered while loading.
21
- */
22
- function PluginLoader(props) {
23
- const { pluginType, kind } = props;
24
- // Load the plugin and throw any loading/not found errors
25
- const { loadPlugin } = (0, legacy_1.usePluginRegistry)();
26
- const { error } = (0, react_query_1.useQuery)(`PluginLoader:${pluginType}_${kind}`, () => {
27
- // The enabled option below should prevent this from being run until loadPlugin is available, but check here to
28
- // make Typescript happy
29
- if (loadPlugin === undefined) {
30
- throw new Error('PluginRegistry loadPlugin not available');
31
- }
32
- return loadPlugin(pluginType, kind);
33
- }, { enabled: loadPlugin !== undefined });
34
- if (error !== undefined && error !== null) {
35
- throw error;
36
- }
37
- return null;
38
- }
39
- exports.PluginLoader = PluginLoader;
@@ -1,85 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.usePlugin = exports.usePluginLoadingBoundary = exports.PluginLoadingBoundary = void 0;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
- const react_1 = require("react");
6
- const use_immer_1 = require("use-immer");
7
- const model_1 = require("../../model");
8
- const legacy_1 = require("../PluginRegistry/legacy");
9
- const PluginLoader_1 = require("./PluginLoader");
10
- /**
11
- * Plugin dependencies are registered here by children. This takes care of loading
12
- * those dependencies on demand and acts similar to React's Suspense in that it
13
- * will show a loading fallback while those plugins are being loaded.
14
- */
15
- function PluginLoadingBoundary(props) {
16
- const { fallback, children } = props;
17
- const { plugins } = (0, legacy_1.usePluginRegistry)();
18
- // Keep track of all plugin dependencies registered by child components
19
- const [dependencies, setDependencies] = (0, use_immer_1.useImmer)(() => {
20
- const deps = {};
21
- for (const pluginType of model_1.ALL_PLUGIN_TYPES) {
22
- deps[pluginType] = {};
23
- }
24
- return deps;
25
- });
26
- // When children are rendered, they can register a dependency here to tell us
27
- // what plugins they need so we can load them if necessary
28
- const registerPluginDependency = (0, react_1.useCallback)((pluginType, kind) => {
29
- setDependencies((draft) => {
30
- draft[pluginType][kind] = true;
31
- });
32
- }, [setDependencies]);
33
- const context = (0, react_1.useMemo)(() => ({ registerPluginDependency }), [registerPluginDependency]);
34
- const { loaders, fragmentKey } = (0, react_1.useMemo)(() => {
35
- let fragmentKey = '';
36
- const loaders = [];
37
- for (const pluginType of model_1.ALL_PLUGIN_TYPES) {
38
- // Build an overall key for the dependencies by combining pluginType and
39
- // kind of all dependencies
40
- fragmentKey += `_${pluginType}:`;
41
- const kinds = dependencies[pluginType];
42
- for (const kind in kinds) {
43
- fragmentKey += kind;
44
- // Is this plugin already loaded?
45
- const plugin = plugins[pluginType][kind];
46
- if (plugin !== undefined)
47
- continue;
48
- // Nope, add it to the loaders list
49
- loaders.push((0, jsx_runtime_1.jsx)(PluginLoader_1.PluginLoader, { pluginType: pluginType, kind: kind }, `${pluginType}:${kind}`));
50
- }
51
- }
52
- return { loaders, fragmentKey };
53
- }, [plugins, dependencies]);
54
- // All dependencies are loaded once we don't have any loaders to render
55
- const isLoaded = loaders.length === 0;
56
- return ((0, jsx_runtime_1.jsxs)(PluginLoadingBoundaryContext.Provider, { value: context, children: [loaders, isLoaded && (0, jsx_runtime_1.jsx)(react_1.Fragment, { children: children }, fragmentKey), isLoaded === false && fallback] }));
57
- }
58
- exports.PluginLoadingBoundary = PluginLoadingBoundary;
59
- const PluginLoadingBoundaryContext = (0, react_1.createContext)(undefined);
60
- /**
61
- * Gets the PluginLoadingBoundary context and throws if the Provider is missing.
62
- */
63
- function usePluginLoadingBoundary() {
64
- const ctx = (0, react_1.useContext)(PluginLoadingBoundaryContext);
65
- if (ctx === undefined) {
66
- throw new Error(`PluginLoadingBoundary context not found. Did you forget a Provider?`);
67
- }
68
- return ctx;
69
- }
70
- exports.usePluginLoadingBoundary = usePluginLoadingBoundary;
71
- /**
72
- * Generic usePlugin that will register the dependency with the nearest LoadingBoundary and get the plugin if it's
73
- * already loaded
74
- */
75
- function usePlugin(pluginType, kind) {
76
- // Tell the loading boundary about the dependency
77
- const { registerPluginDependency } = usePluginLoadingBoundary();
78
- (0, react_1.useEffect)(() => {
79
- registerPluginDependency(pluginType, kind);
80
- }, [pluginType, kind, registerPluginDependency]);
81
- // Get the plugin, which could be undefined if it hasn't loaded yet
82
- const { plugins } = (0, legacy_1.usePluginRegistry)();
83
- return plugins[pluginType][kind];
84
- }
85
- exports.usePlugin = usePlugin;
@@ -1,29 +0,0 @@
1
- "use strict";
2
- // Copyright 2021 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 __exportStar = (this && this.__exportStar) || function(m, exports) {
26
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- __exportStar(require("./PluginLoadingBoundary"), exports);
@@ -1,57 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.usePluginRegistry = exports.PluginRegistry = void 0;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
- // Copyright 2021 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("react");
18
- const react_query_1 = require("react-query");
19
- const registry_state_1 = require("./registry-state");
20
- /**
21
- * PluginRegistryContext provider that keeps track of all available plugins and
22
- * their implementations once they've been loaded.
23
- */
24
- function PluginRegistry(props) {
25
- const { children, getInstalledPlugins, importPluginModule } = props;
26
- const installedPlugins = (0, react_query_1.useQuery)('installed-plugins', getInstalledPlugins);
27
- const { loadablePlugins, plugins, register } = (0, registry_state_1.useRegistryState)(installedPlugins.data);
28
- const loadPlugin = (0, react_1.useCallback)(async (pluginType, kind) => {
29
- // Is it already loaded?
30
- const plugin = plugins[pluginType][kind];
31
- if (plugin !== undefined)
32
- return;
33
- // Is it a valid plugin we know about?
34
- const resource = loadablePlugins[pluginType][kind];
35
- if (resource === undefined) {
36
- throw new Error(`No ${pluginType} plugin is available for kind ${kind}`);
37
- }
38
- // Load and register the resource
39
- const pluginModule = await importPluginModule(resource);
40
- register(resource, pluginModule);
41
- }, [plugins, loadablePlugins, importPluginModule, register]);
42
- const registry = (0, react_1.useMemo)(() => ({ plugins, loadPlugin: installedPlugins.isLoading ? undefined : loadPlugin }), [installedPlugins.isLoading, plugins, loadPlugin]);
43
- return (0, jsx_runtime_1.jsx)(PluginRegistryContext.Provider, { value: registry, children: children });
44
- }
45
- exports.PluginRegistry = PluginRegistry;
46
- const PluginRegistryContext = (0, react_1.createContext)(undefined);
47
- /**
48
- * Gets the PluginRegistryContext, throwing if the provider is missing.
49
- */
50
- function usePluginRegistry() {
51
- const ctx = (0, react_1.useContext)(PluginRegistryContext);
52
- if (ctx === undefined) {
53
- throw new Error('No PluginRegistry context found. Did you forget a Provider?');
54
- }
55
- return ctx;
56
- }
57
- exports.usePluginRegistry = usePluginRegistry;
@@ -1,29 +0,0 @@
1
- "use strict";
2
- // Copyright 2021 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 __exportStar = (this && this.__exportStar) || function(m, exports) {
26
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- __exportStar(require("./PluginRegistry"), exports);
@@ -1,97 +0,0 @@
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.useRegistryState = void 0;
16
- const react_1 = require("react");
17
- const use_immer_1 = require("use-immer");
18
- const model_1 = require("../../../model");
19
- /**
20
- * Hook for setting up plugin registry state. Returns the state, plus a function
21
- * for registering plugins with that state.
22
- */
23
- function useRegistryState(installedPlugins) {
24
- // Go through all installed plugins and bundled plugins and build an index of
25
- // those resources by type and kind
26
- const loadablePlugins = (0, react_1.useMemo)(() => {
27
- const loadableProps = {};
28
- for (const pluginType of model_1.ALL_PLUGIN_TYPES) {
29
- loadableProps[pluginType] = {};
30
- }
31
- // If no plugins installed or waiting on that data, nothing else to do
32
- if (installedPlugins === undefined)
33
- return loadableProps;
34
- for (const resource of installedPlugins) {
35
- for (const plugin of resource.spec.plugins) {
36
- const { pluginType, kind } = plugin;
37
- const map = loadableProps[pluginType];
38
- if (map[kind] !== undefined) {
39
- console.warn(`Got multiple ${pluginType} plugin definitions for kind ${kind}`);
40
- continue;
41
- }
42
- map[kind] = resource;
43
- }
44
- }
45
- return loadableProps;
46
- }, [installedPlugins]);
47
- const [plugins, setPlugins] = (0, use_immer_1.useImmer)(() => {
48
- const loadedPlugins = {};
49
- for (const pluginType of model_1.ALL_PLUGIN_TYPES) {
50
- loadedPlugins[pluginType] = {};
51
- }
52
- return loadedPlugins;
53
- });
54
- const registeredModules = (0, react_1.useRef)(new Set());
55
- const register = (0, react_1.useCallback)((resource, pluginModule) => {
56
- // De-dupe register calls in case multiple plugin loading boundaries
57
- // are waiting for the same module in parallel
58
- if (registeredModules.current.has(pluginModule)) {
59
- return;
60
- }
61
- // Treat plugin module as JS module with named exports that are each a Plugin
62
- const plugins = pluginModule;
63
- setPlugins((draft) => {
64
- // Look for all the plugins specified in the metadata
65
- for (const pluginMetadata of resource.spec.plugins) {
66
- // Assume that plugins will be exported under the same named export as the kind they handle
67
- // TODO: Do we need to allow for different named exports and an option in the metadata to tell us the name?
68
- const { pluginType, kind } = pluginMetadata;
69
- const plugin = plugins[kind];
70
- if (plugin === undefined) {
71
- // TODO: How to handle missing plugins?
72
- console.warn(`Could not find ${pluginType} plugin for kind '${kind}' in ${resource.metadata.name}`);
73
- continue;
74
- }
75
- // Add to registry state
76
- switch (pluginType) {
77
- case 'Variable':
78
- draft.Variable[kind] = plugin;
79
- break;
80
- case 'Panel':
81
- draft.Panel[kind] = plugin;
82
- break;
83
- case 'GraphQuery':
84
- draft.GraphQuery[kind] = plugin;
85
- break;
86
- default:
87
- const exhaustive = pluginType;
88
- throw new Error(`Unhandled plugin config: ${exhaustive}`);
89
- }
90
- }
91
- });
92
- // Remember this module has been registered
93
- registeredModules.current.add(pluginModule);
94
- }, [setPlugins]);
95
- return { loadablePlugins, plugins, register };
96
- }
97
- exports.useRegistryState = useRegistryState;
@@ -1,32 +0,0 @@
1
- {
2
- "kind": "PluginModule",
3
- "metadata": { "name": "Bert" },
4
- "spec": {
5
- "plugins": [
6
- {
7
- "pluginType": "Panel",
8
- "kind": "BertPanel1",
9
- "display": {
10
- "name": "Bert Panel 1",
11
- "description": ""
12
- }
13
- },
14
- {
15
- "pluginType": "Panel",
16
- "kind": "BertPanel2",
17
- "display": {
18
- "name": "Bert Panel 2",
19
- "description": ""
20
- }
21
- },
22
- {
23
- "pluginType": "Variable",
24
- "kind": "BertVariable",
25
- "display": {
26
- "name": "Bert Variable",
27
- "description": ""
28
- }
29
- }
30
- ]
31
- }
32
- }
@@ -1,24 +0,0 @@
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
- }
@@ -1,28 +0,0 @@
1
- "use strict";
2
- // Copyright 2021 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.useGraphQuery = void 0;
16
- const PluginLoadingBoundary_1 = require("../components/PluginLoadingBoundary");
17
- /**
18
- * Use a Graph Query's results from a graph query plugin at runtime.
19
- */
20
- const useGraphQuery = (definition) => {
21
- const plugin = (0, PluginLoadingBoundary_1.usePlugin)('GraphQuery', definition.kind);
22
- if (plugin === undefined) {
23
- // Provide default values while the plugin is being loaded
24
- return { loading: true };
25
- }
26
- return plugin.useGraphQuery(definition);
27
- };
28
- exports.useGraphQuery = useGraphQuery;
@@ -1,13 +0,0 @@
1
- import { ReactNode } from 'react';
2
- import { ErrorBoundaryProps } from '@perses-dev/components';
3
- import { PluginLoadingBoundaryProps } from './PluginLoadingBoundary';
4
- export interface PluginBoundaryProps {
5
- loadingFallback: PluginLoadingBoundaryProps['fallback'];
6
- ErrorFallbackComponent: Required<ErrorBoundaryProps>['FallbackComponent'];
7
- children: ReactNode;
8
- }
9
- /**
10
- * Combination ErrorBoundary and PluginLoadingBoundary.
11
- */
12
- export declare function PluginBoundary(props: PluginBoundaryProps): JSX.Element;
13
- //# sourceMappingURL=PluginBoundary.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PluginBoundary.d.ts","sourceRoot":"","sources":["../../src/components/PluginBoundary.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAiB,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC3E,OAAO,EAAyB,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AAE5F,MAAM,WAAW,mBAAmB;IAClC,eAAe,EAAE,0BAA0B,CAAC,UAAU,CAAC,CAAC;IACxD,sBAAsB,EAAE,QAAQ,CAAC,kBAAkB,CAAC,CAAC,mBAAmB,CAAC,CAAC;IAC1E,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,eAQxD"}
@@ -1 +0,0 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{ErrorBoundary}from"@perses-dev/components";import{PluginLoadingBoundary}from"./PluginLoadingBoundary";export function PluginBoundary(r){const{ErrorFallbackComponent:n,loadingFallback:o,children:a}=r;return _jsx(ErrorBoundary,{FallbackComponent:n,children:_jsx(PluginLoadingBoundary,{fallback:o,children:a})})}
@@ -1,11 +0,0 @@
1
- import { PluginType } from '../../model';
2
- export interface PluginLoaderProps {
3
- pluginType: PluginType;
4
- kind: string;
5
- }
6
- /**
7
- * Uses the PluginRegistry to load the specified plugin and throws any errors
8
- * encountered while loading.
9
- */
10
- export declare function PluginLoader(props: PluginLoaderProps): null;
11
- //# sourceMappingURL=PluginLoader.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PluginLoader.d.ts","sourceRoot":"","sources":["../../../src/components/PluginLoadingBoundary/PluginLoader.tsx"],"names":[],"mappings":"AAcA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,UAAU,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,QAsBpD"}
@@ -1 +0,0 @@
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,27 +0,0 @@
1
- /// <reference types="react" />
2
- import { JsonObject } from '@perses-dev/core';
3
- import { PluginType, PluginImplementation } from '../../model';
4
- export interface PluginLoadingBoundaryProps {
5
- fallback: React.ReactNode;
6
- children?: React.ReactNode;
7
- }
8
- /**
9
- * Plugin dependencies are registered here by children. This takes care of loading
10
- * those dependencies on demand and acts similar to React's Suspense in that it
11
- * will show a loading fallback while those plugins are being loaded.
12
- */
13
- export declare function PluginLoadingBoundary(props: PluginLoadingBoundaryProps): JSX.Element;
14
- interface PluginLoadingBoundaryContextType {
15
- registerPluginDependency: (pluginType: PluginType, kind: string) => void;
16
- }
17
- /**
18
- * Gets the PluginLoadingBoundary context and throws if the Provider is missing.
19
- */
20
- export declare function usePluginLoadingBoundary(): PluginLoadingBoundaryContextType;
21
- /**
22
- * Generic usePlugin that will register the dependency with the nearest LoadingBoundary and get the plugin if it's
23
- * already loaded
24
- */
25
- export declare function usePlugin<Type extends PluginType>(pluginType: Type, kind: string): PluginImplementation<Type, JsonObject> | undefined;
26
- export {};
27
- //# sourceMappingURL=PluginLoadingBoundary.d.ts.map
@@ -1 +0,0 @@
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 +0,0 @@
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,2 +0,0 @@
1
- export * from './PluginLoadingBoundary';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/PluginLoadingBoundary/index.ts"],"names":[],"mappings":"AAaA,cAAc,yBAAyB,CAAC"}
@@ -1 +0,0 @@
1
- export*from"./PluginLoadingBoundary";
@@ -1,29 +0,0 @@
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
@@ -1 +0,0 @@
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"}