@perses-dev/plugin-system 0.50.1 → 0.51.0-beta.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 (176) hide show
  1. package/dist/cjs/components/DatasourceEditorForm/DatasourceEditorForm.js +17 -71
  2. package/dist/cjs/components/DatasourceSelect.js +8 -13
  3. package/dist/cjs/components/HTTPSettingsEditor/HTTPSettingsEditor.js +534 -0
  4. package/dist/cjs/components/HTTPSettingsEditor/index.js +30 -0
  5. package/dist/cjs/components/LegendOptionsEditor/LegendOptionsEditor.js +4 -4
  6. package/dist/cjs/components/MetricLabelInput/MetricLabelInput.js +1 -1
  7. package/dist/cjs/components/MetricLabelInput/index.js +1 -1
  8. package/dist/cjs/components/MultiQueryEditor/MultiQueryEditor.js +15 -14
  9. package/dist/cjs/components/PanelSpecEditor/PanelSpecEditor.js +7 -11
  10. package/dist/cjs/components/PluginEditor/PluginEditor.js +10 -6
  11. package/dist/cjs/components/PluginEditor/plugin-editor-api.js +4 -5
  12. package/dist/cjs/components/PluginKindSelect/PluginKindSelect.js +7 -8
  13. package/dist/cjs/components/PluginRegistry/PluginRegistry.js +7 -10
  14. package/dist/cjs/components/PluginRegistry/plugin-indexes.js +17 -14
  15. package/dist/cjs/components/ProjectSelect.js +2 -3
  16. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +46 -92
  17. package/dist/cjs/components/Variables/VariableEditorForm/VariablePreview.js +6 -6
  18. package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +6 -11
  19. package/dist/cjs/components/Variables/variable-model.js +4 -7
  20. package/dist/cjs/components/index.js +1 -0
  21. package/dist/cjs/index.js +1 -0
  22. package/dist/cjs/model/explore.js +16 -0
  23. package/dist/cjs/remote/PersesPlugin.types.js +16 -0
  24. package/dist/cjs/remote/PluginLoaderComponent.js +75 -0
  25. package/dist/cjs/remote/PluginRuntime.js +267 -0
  26. package/dist/cjs/remote/index.js +31 -0
  27. package/dist/cjs/remote/remotePluginLoader.js +61 -0
  28. package/dist/cjs/runtime/DataQueriesProvider/DataQueriesProvider.js +4 -10
  29. package/dist/cjs/runtime/DataQueriesProvider/model.js +4 -7
  30. package/dist/cjs/runtime/TimeRangeProvider/TimeRangeProvider.js +2 -2
  31. package/dist/cjs/runtime/builtin-variables.js +1 -1
  32. package/dist/cjs/runtime/datasources.js +3 -3
  33. package/dist/cjs/runtime/plugin-registry.js +5 -6
  34. package/dist/cjs/runtime/time-series-queries.js +11 -18
  35. package/dist/cjs/runtime/trace-queries.js +1 -2
  36. package/dist/cjs/runtime/variables.js +10 -28
  37. package/dist/cjs/stories/shared-utils/decorators/WithDataQueries.js +1 -1
  38. package/dist/cjs/stories/shared-utils/decorators/WithPluginRegistry.js +1 -67
  39. package/dist/cjs/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.js +1 -1
  40. package/dist/cjs/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.js +4 -4
  41. package/dist/cjs/stories/shared-utils/decorators/WithPluginSystemVariables.js +1 -1
  42. package/dist/cjs/stories/shared-utils/decorators/WithTimeRange.js +1 -1
  43. package/dist/cjs/test/render.js +1 -2
  44. package/dist/cjs/test-utils/mock-plugin-registry.js +10 -10
  45. package/dist/cjs/utils/variables.js +1 -1
  46. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts.map +1 -1
  47. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js +17 -30
  48. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js.map +1 -1
  49. package/dist/components/DatasourceSelect.d.ts +2 -2
  50. package/dist/components/DatasourceSelect.d.ts.map +1 -1
  51. package/dist/components/DatasourceSelect.js +8 -13
  52. package/dist/components/DatasourceSelect.js.map +1 -1
  53. package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.d.ts +11 -0
  54. package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.d.ts.map +1 -0
  55. package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.js +480 -0
  56. package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.js.map +1 -0
  57. package/dist/components/HTTPSettingsEditor/index.d.ts +2 -0
  58. package/dist/components/HTTPSettingsEditor/index.d.ts.map +1 -0
  59. package/dist/components/HTTPSettingsEditor/index.js +15 -0
  60. package/dist/components/HTTPSettingsEditor/index.js.map +1 -0
  61. package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js +4 -4
  62. package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js.map +1 -1
  63. package/dist/components/MetricLabelInput/MetricLabelInput.js +1 -1
  64. package/dist/components/MetricLabelInput/MetricLabelInput.js.map +1 -1
  65. package/dist/components/MetricLabelInput/index.js +1 -1
  66. package/dist/components/MetricLabelInput/index.js.map +1 -1
  67. package/dist/components/MultiQueryEditor/MultiQueryEditor.d.ts.map +1 -1
  68. package/dist/components/MultiQueryEditor/MultiQueryEditor.js +15 -14
  69. package/dist/components/MultiQueryEditor/MultiQueryEditor.js.map +1 -1
  70. package/dist/components/PanelSpecEditor/PanelSpecEditor.js +7 -11
  71. package/dist/components/PanelSpecEditor/PanelSpecEditor.js.map +1 -1
  72. package/dist/components/PluginEditor/PluginEditor.d.ts.map +1 -1
  73. package/dist/components/PluginEditor/PluginEditor.js +10 -6
  74. package/dist/components/PluginEditor/PluginEditor.js.map +1 -1
  75. package/dist/components/PluginEditor/plugin-editor-api.js +4 -5
  76. package/dist/components/PluginEditor/plugin-editor-api.js.map +1 -1
  77. package/dist/components/PluginKindSelect/PluginKindSelect.js +7 -8
  78. package/dist/components/PluginKindSelect/PluginKindSelect.js.map +1 -1
  79. package/dist/components/PluginRegistry/PluginRegistry.js +7 -10
  80. package/dist/components/PluginRegistry/PluginRegistry.js.map +1 -1
  81. package/dist/components/PluginRegistry/plugin-indexes.d.ts +4 -4
  82. package/dist/components/PluginRegistry/plugin-indexes.d.ts.map +1 -1
  83. package/dist/components/PluginRegistry/plugin-indexes.js +17 -14
  84. package/dist/components/PluginRegistry/plugin-indexes.js.map +1 -1
  85. package/dist/components/ProjectSelect.js +2 -3
  86. package/dist/components/ProjectSelect.js.map +1 -1
  87. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +46 -92
  88. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
  89. package/dist/components/Variables/VariableEditorForm/VariablePreview.js +6 -6
  90. package/dist/components/Variables/VariableEditorForm/VariablePreview.js.map +1 -1
  91. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +6 -11
  92. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -1
  93. package/dist/components/Variables/variable-model.js +4 -7
  94. package/dist/components/Variables/variable-model.js.map +1 -1
  95. package/dist/components/index.d.ts +1 -0
  96. package/dist/components/index.d.ts.map +1 -1
  97. package/dist/components/index.js +1 -0
  98. package/dist/components/index.js.map +1 -1
  99. package/dist/index.d.ts +1 -0
  100. package/dist/index.d.ts.map +1 -1
  101. package/dist/index.js +1 -0
  102. package/dist/index.js.map +1 -1
  103. package/dist/model/explore.d.ts +13 -0
  104. package/dist/model/explore.d.ts.map +1 -0
  105. package/dist/model/explore.js +17 -0
  106. package/dist/model/explore.js.map +1 -0
  107. package/dist/model/panels.d.ts +13 -3
  108. package/dist/model/panels.d.ts.map +1 -1
  109. package/dist/model/panels.js.map +1 -1
  110. package/dist/model/plugins.d.ts +31 -17
  111. package/dist/model/plugins.d.ts.map +1 -1
  112. package/dist/model/plugins.js.map +1 -1
  113. package/dist/remote/PersesPlugin.types.d.ts +7 -0
  114. package/dist/remote/PersesPlugin.types.d.ts.map +1 -0
  115. package/dist/remote/PersesPlugin.types.js +15 -0
  116. package/dist/remote/PersesPlugin.types.js.map +1 -0
  117. package/dist/remote/PluginLoaderComponent.d.ts +10 -0
  118. package/dist/remote/PluginLoaderComponent.d.ts.map +1 -0
  119. package/dist/remote/PluginLoaderComponent.js +67 -0
  120. package/dist/remote/PluginLoaderComponent.js.map +1 -0
  121. package/dist/remote/PluginRuntime.d.ts +11 -0
  122. package/dist/remote/PluginRuntime.d.ts.map +1 -0
  123. package/dist/remote/PluginRuntime.js +202 -0
  124. package/dist/remote/PluginRuntime.js.map +1 -0
  125. package/dist/remote/index.d.ts +3 -0
  126. package/dist/remote/index.d.ts.map +1 -0
  127. package/dist/remote/index.js +16 -0
  128. package/dist/remote/index.js.map +1 -0
  129. package/dist/remote/remotePluginLoader.d.ts +3 -0
  130. package/dist/remote/remotePluginLoader.d.ts.map +1 -0
  131. package/dist/remote/remotePluginLoader.js +53 -0
  132. package/dist/remote/remotePluginLoader.js.map +1 -0
  133. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js +4 -10
  134. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js.map +1 -1
  135. package/dist/runtime/DataQueriesProvider/model.d.ts.map +1 -1
  136. package/dist/runtime/DataQueriesProvider/model.js +4 -7
  137. package/dist/runtime/DataQueriesProvider/model.js.map +1 -1
  138. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js +2 -2
  139. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js.map +1 -1
  140. package/dist/runtime/builtin-variables.js +1 -1
  141. package/dist/runtime/builtin-variables.js.map +1 -1
  142. package/dist/runtime/datasources.d.ts +2 -2
  143. package/dist/runtime/datasources.js +3 -3
  144. package/dist/runtime/datasources.js.map +1 -1
  145. package/dist/runtime/plugin-registry.d.ts +6 -6
  146. package/dist/runtime/plugin-registry.d.ts.map +1 -1
  147. package/dist/runtime/plugin-registry.js +5 -6
  148. package/dist/runtime/plugin-registry.js.map +1 -1
  149. package/dist/runtime/time-series-queries.js +11 -18
  150. package/dist/runtime/time-series-queries.js.map +1 -1
  151. package/dist/runtime/trace-queries.js +1 -2
  152. package/dist/runtime/trace-queries.js.map +1 -1
  153. package/dist/runtime/variables.js +10 -28
  154. package/dist/runtime/variables.js.map +1 -1
  155. package/dist/stories/shared-utils/decorators/WithDataQueries.js +1 -1
  156. package/dist/stories/shared-utils/decorators/WithDataQueries.js.map +1 -1
  157. package/dist/stories/shared-utils/decorators/WithPluginRegistry.d.ts.map +1 -1
  158. package/dist/stories/shared-utils/decorators/WithPluginRegistry.js +2 -22
  159. package/dist/stories/shared-utils/decorators/WithPluginRegistry.js.map +1 -1
  160. package/dist/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.js +1 -1
  161. package/dist/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.js.map +1 -1
  162. package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.js +4 -4
  163. package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.js.map +1 -1
  164. package/dist/stories/shared-utils/decorators/WithPluginSystemVariables.js +1 -1
  165. package/dist/stories/shared-utils/decorators/WithPluginSystemVariables.js.map +1 -1
  166. package/dist/stories/shared-utils/decorators/WithTimeRange.js +1 -1
  167. package/dist/stories/shared-utils/decorators/WithTimeRange.js.map +1 -1
  168. package/dist/test/render.js +1 -2
  169. package/dist/test/render.js.map +1 -1
  170. package/dist/test-utils/mock-plugin-registry.d.ts +5 -3
  171. package/dist/test-utils/mock-plugin-registry.d.ts.map +1 -1
  172. package/dist/test-utils/mock-plugin-registry.js +10 -10
  173. package/dist/test-utils/mock-plugin-registry.js.map +1 -1
  174. package/dist/utils/variables.js +1 -1
  175. package/dist/utils/variables.js.map +1 -1
  176. package/package.json +6 -5
@@ -0,0 +1,267 @@
1
+ /* eslint-disable @typescript-eslint/no-require-imports */ // Copyright 2024 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
+ 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
+ loadPlugin: function() {
25
+ return loadPlugin;
26
+ },
27
+ pluginRuntime: function() {
28
+ return pluginRuntime;
29
+ },
30
+ usePluginRuntime: function() {
31
+ return usePluginRuntime;
32
+ }
33
+ });
34
+ const _runtime = require("@module-federation/enhanced/runtime");
35
+ const _reactquery = /*#__PURE__*/ _interop_require_wildcard(require("@tanstack/react-query"));
36
+ const _react = /*#__PURE__*/ _interop_require_default(require("react"));
37
+ const _reactdom = /*#__PURE__*/ _interop_require_default(require("react-dom"));
38
+ const _reactrouterdom = /*#__PURE__*/ _interop_require_wildcard(require("react-router-dom"));
39
+ const _reacthookform = /*#__PURE__*/ _interop_require_wildcard(require("react-hook-form"));
40
+ function _interop_require_default(obj) {
41
+ return obj && obj.__esModule ? obj : {
42
+ default: obj
43
+ };
44
+ }
45
+ function _getRequireWildcardCache(nodeInterop) {
46
+ if (typeof WeakMap !== "function") return null;
47
+ var cacheBabelInterop = new WeakMap();
48
+ var cacheNodeInterop = new WeakMap();
49
+ return (_getRequireWildcardCache = function(nodeInterop) {
50
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
51
+ })(nodeInterop);
52
+ }
53
+ function _interop_require_wildcard(obj, nodeInterop) {
54
+ if (!nodeInterop && obj && obj.__esModule) {
55
+ return obj;
56
+ }
57
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
58
+ return {
59
+ default: obj
60
+ };
61
+ }
62
+ var cache = _getRequireWildcardCache(nodeInterop);
63
+ if (cache && cache.has(obj)) {
64
+ return cache.get(obj);
65
+ }
66
+ var newObj = {
67
+ __proto__: null
68
+ };
69
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
70
+ for(var key in obj){
71
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
72
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
73
+ if (desc && (desc.get || desc.set)) {
74
+ Object.defineProperty(newObj, key, desc);
75
+ } else {
76
+ newObj[key] = obj[key];
77
+ }
78
+ }
79
+ }
80
+ newObj.default = obj;
81
+ if (cache) {
82
+ cache.set(obj, newObj);
83
+ }
84
+ return newObj;
85
+ }
86
+ const pluginRuntime = (0, _runtime.init)({
87
+ name: '@perses/perses-ui-host',
88
+ remotes: [],
89
+ shared: {
90
+ react: {
91
+ version: _react.default.version,
92
+ lib: ()=>_react.default,
93
+ shareConfig: {
94
+ singleton: true,
95
+ requiredVersion: `^${_react.default.version}`
96
+ }
97
+ },
98
+ 'react-dom': {
99
+ version: '18.3.1',
100
+ lib: ()=>_reactdom.default,
101
+ shareConfig: {
102
+ singleton: true,
103
+ requiredVersion: `^18.3.1`
104
+ }
105
+ },
106
+ 'react-router-dom': {
107
+ version: '6.26.0',
108
+ lib: ()=>_reactrouterdom,
109
+ shareConfig: {
110
+ singleton: true,
111
+ requiredVersion: '^6.26.0'
112
+ }
113
+ },
114
+ '@tanstack/react-query': {
115
+ version: '4.36.1',
116
+ lib: ()=>_reactquery,
117
+ shareConfig: {
118
+ singleton: true,
119
+ requiredVersion: '^4.36.1'
120
+ }
121
+ },
122
+ 'react-hook-form': {
123
+ version: '7.52.2',
124
+ lib: ()=>_reacthookform,
125
+ shareConfig: {
126
+ singleton: true,
127
+ requiredVersion: '^7.52.2'
128
+ }
129
+ },
130
+ echarts: {
131
+ version: '5.5.0',
132
+ lib: ()=>require('echarts'),
133
+ shareConfig: {
134
+ singleton: true,
135
+ requiredVersion: '^5.5.0'
136
+ }
137
+ },
138
+ '@perses-dev/components': {
139
+ version: '0.50.0',
140
+ lib: ()=>require('@perses-dev/components'),
141
+ shareConfig: {
142
+ singleton: true,
143
+ requiredVersion: '^0.50.0'
144
+ }
145
+ },
146
+ '@perses-dev/plugin-system': {
147
+ version: '0.50.0',
148
+ lib: ()=>require('@perses-dev/plugin-system'),
149
+ shareConfig: {
150
+ singleton: true,
151
+ requiredVersion: '^0.50.0'
152
+ }
153
+ },
154
+ '@perses-dev/explore': {
155
+ version: '0.50.0',
156
+ lib: ()=>require('@perses-dev/explore'),
157
+ shareConfig: {
158
+ singleton: true,
159
+ requiredVersion: '^0.50.0'
160
+ }
161
+ },
162
+ '@perses-dev/dashboards': {
163
+ version: '0.50.0',
164
+ lib: ()=>require('@perses-dev/dashboards'),
165
+ shareConfig: {
166
+ singleton: true,
167
+ requiredVersion: '^0.50.0'
168
+ }
169
+ },
170
+ // Below are the shared modules that are used by the plugins, this can be part of the SDK
171
+ 'date-fns': {
172
+ version: '2.29.3',
173
+ lib: ()=>require('date-fns'),
174
+ shareConfig: {
175
+ singleton: true,
176
+ requiredVersion: '^2.29.3'
177
+ }
178
+ },
179
+ 'date-fns-tz': {
180
+ version: '1.3.8',
181
+ lib: ()=>require('date-fns-tz'),
182
+ shareConfig: {
183
+ singleton: true,
184
+ requiredVersion: '^1.3.8'
185
+ }
186
+ },
187
+ lodash: {
188
+ version: '4.17.21',
189
+ lib: ()=>require('lodash'),
190
+ shareConfig: {
191
+ singleton: true,
192
+ requiredVersion: '^4.17.21'
193
+ }
194
+ },
195
+ '@emotion/react': {
196
+ version: '11.11.3',
197
+ lib: ()=>require('@emotion/react'),
198
+ shareConfig: {
199
+ singleton: true,
200
+ requiredVersion: '^11.11.3'
201
+ }
202
+ },
203
+ '@emotion/styled': {
204
+ version: '11.11.0',
205
+ lib: ()=>require('@emotion/styled'),
206
+ shareConfig: {
207
+ singleton: true,
208
+ requiredVersion: '^11.11.0'
209
+ }
210
+ },
211
+ '@hookform/resolvers/zod': {
212
+ version: '3.3.4',
213
+ lib: ()=>require('@hookform/resolvers/zod'),
214
+ shareConfig: {
215
+ singleton: true,
216
+ requiredVersion: '^3.3.4'
217
+ }
218
+ },
219
+ 'use-resize-observer': {
220
+ version: '9.1.0',
221
+ lib: ()=>require('use-resize-observer'),
222
+ shareConfig: {
223
+ singleton: true,
224
+ requiredVersion: '^9.1.0'
225
+ }
226
+ },
227
+ 'mdi-material-ui': {
228
+ version: '7.4.0',
229
+ lib: ()=>require('mdi-material-ui'),
230
+ shareConfig: {
231
+ singleton: true,
232
+ requiredVersion: '^7.4.0'
233
+ }
234
+ },
235
+ immer: {
236
+ version: '9.0.15',
237
+ lib: ()=>require('immer'),
238
+ shareConfig: {
239
+ singleton: true,
240
+ requiredVersion: '^9.0.15'
241
+ }
242
+ }
243
+ }
244
+ });
245
+ const registerRemote = (name, baseURL)=>{
246
+ const existingRemote = pluginRuntime.options.remotes.find((remote)=>remote.name === name);
247
+ if (!existingRemote) {
248
+ const remoteEntryURL = baseURL ? `${baseURL}/${name}/mf-manifest.json` : `/plugins/${name}/mf-manifest.json`;
249
+ pluginRuntime.registerRemotes([
250
+ {
251
+ name,
252
+ entry: remoteEntryURL,
253
+ alias: name
254
+ }
255
+ ]);
256
+ }
257
+ };
258
+ const loadPlugin = async (moduleName, pluginName, baseURL)=>{
259
+ registerRemote(moduleName, baseURL);
260
+ return (0, _runtime.loadRemote)(`${moduleName}/${pluginName}`);
261
+ };
262
+ function usePluginRuntime({ plugin }) {
263
+ return {
264
+ pluginRuntime,
265
+ loadPlugin: ()=>loadPlugin(plugin.moduleName, plugin.name, plugin.baseURL)
266
+ };
267
+ }
@@ -0,0 +1,31 @@
1
+ // Copyright 2023 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
+ _export_star(require("./PluginLoaderComponent"), exports);
18
+ _export_star(require("./remotePluginLoader"), exports);
19
+ function _export_star(from, to) {
20
+ Object.keys(from).forEach(function(k) {
21
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
22
+ Object.defineProperty(to, k, {
23
+ enumerable: true,
24
+ get: function() {
25
+ return from[k];
26
+ }
27
+ });
28
+ }
29
+ });
30
+ return from;
31
+ }
@@ -0,0 +1,61 @@
1
+ // Copyright 2024 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, "remotePluginLoader", {
18
+ enumerable: true,
19
+ get: function() {
20
+ return remotePluginLoader;
21
+ }
22
+ });
23
+ const _PluginRuntime = require("./PluginRuntime");
24
+ const isPluginMetadata = (plugin)=>{
25
+ return typeof plugin === 'object' && plugin !== null && 'kind' in plugin && 'spec' in plugin && typeof plugin.spec === 'object' && plugin.spec !== null && 'name' in plugin.spec;
26
+ };
27
+ const isPluginModuleResource = (pluginModule)=>{
28
+ return typeof pluginModule === 'object' && pluginModule !== null && 'metadata' in pluginModule && 'spec' in pluginModule && typeof pluginModule.spec === 'object' && pluginModule.spec !== null && 'plugins' in pluginModule.spec && Array.isArray(pluginModule.spec.plugins) && pluginModule.spec.plugins.every(isPluginMetadata);
29
+ };
30
+ const remotePluginLoader = (baseURL)=>{
31
+ return {
32
+ getInstalledPlugins: async ()=>{
33
+ const pluginsResponse = await fetch(`${baseURL ? baseURL : ''}/api/v1/plugins`);
34
+ const plugins = await pluginsResponse.json();
35
+ let pluginModules = [];
36
+ if (Array.isArray(plugins)) {
37
+ pluginModules = plugins.filter(isPluginModuleResource);
38
+ } else {
39
+ console.error('RemotePluginLoader: Error loading plugins, response is not an array');
40
+ }
41
+ if (!pluginModules.length) {
42
+ console.error('RemotePluginLoader: No valid plugins found');
43
+ }
44
+ return pluginModules;
45
+ },
46
+ importPluginModule: async (resource)=>{
47
+ const pluginModuleName = resource.metadata.name;
48
+ const pluginModule = {};
49
+ for (const plugin of resource.spec.plugins){
50
+ const remotePluginModule = await (0, _PluginRuntime.loadPlugin)(pluginModuleName, plugin.spec.name);
51
+ const remotePlugin = remotePluginModule?.[plugin.spec.name];
52
+ if (remotePlugin) {
53
+ pluginModule[plugin.spec.name] = remotePlugin;
54
+ } else {
55
+ console.error(`RemotePluginLoader: Error loading plugin ${plugin.spec.name}`);
56
+ }
57
+ }
58
+ return pluginModule;
59
+ }
60
+ };
61
+ };
@@ -51,15 +51,9 @@ function useDataQueriesContext() {
51
51
  function useDataQueries(queryType) {
52
52
  const ctx = useDataQueriesContext();
53
53
  // Filter the query results based on the specified query type
54
- const filteredQueryResults = ctx.queryResults.filter((queryResult)=>{
55
- var _queryResult_definition;
56
- return (queryResult === null || queryResult === void 0 ? void 0 : (_queryResult_definition = queryResult.definition) === null || _queryResult_definition === void 0 ? void 0 : _queryResult_definition.kind) === queryType;
57
- });
54
+ const filteredQueryResults = ctx.queryResults.filter((queryResult)=>queryResult?.definition?.kind === queryType);
58
55
  // Filter the errors based on the specified query type
59
- const filteredErrors = ctx.errors.filter((errors, index)=>{
60
- var _ctx_queryResults_index_definition, _ctx_queryResults_index;
61
- return ((_ctx_queryResults_index = ctx.queryResults[index]) === null || _ctx_queryResults_index === void 0 ? void 0 : (_ctx_queryResults_index_definition = _ctx_queryResults_index.definition) === null || _ctx_queryResults_index_definition === void 0 ? void 0 : _ctx_queryResults_index_definition.kind) === queryType;
62
- });
56
+ const filteredErrors = ctx.errors.filter((errors, index)=>ctx.queryResults[index]?.definition?.kind === queryType);
63
57
  // Create a new context object with the filtered results and errors
64
58
  const filteredCtx = {
65
59
  queryResults: filteredQueryResults,
@@ -101,7 +95,7 @@ function DataQueriesProvider(props) {
101
95
  ...(0, _model.transformQueryResults)(timeSeriesResults, timeSeriesQueries),
102
96
  ...(0, _model.transformQueryResults)(traceResults, traceQueries)
103
97
  ];
104
- if (queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.enabled) {
98
+ if (queryOptions?.enabled) {
105
99
  for (const result of mergedQueryResults){
106
100
  if (!result.isLoading && !result.isFetching && !result.error) {
107
101
  usageMetrics.markQuery(result.definition, 'success');
@@ -125,7 +119,7 @@ function DataQueriesProvider(props) {
125
119
  traceQueries,
126
120
  traceResults,
127
121
  refetchAll,
128
- queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.enabled,
122
+ queryOptions?.enabled,
129
123
  usageMetrics
130
124
  ]);
131
125
  return /*#__PURE__*/ (0, _jsxruntime.jsx)(DataQueriesContext.Provider, {
@@ -57,14 +57,12 @@ function useQueryType() {
57
57
  };
58
58
  if (timeSeriesQueryPlugins) {
59
59
  timeSeriesQueryPlugins.forEach((plugin)=>{
60
- var _map_plugin_pluginType;
61
- (_map_plugin_pluginType = map[plugin.pluginType]) === null || _map_plugin_pluginType === void 0 ? void 0 : _map_plugin_pluginType.push(plugin.kind);
60
+ map[plugin.kind]?.push(plugin.spec.name);
62
61
  });
63
62
  }
64
63
  if (traceQueryPlugins) {
65
64
  traceQueryPlugins.forEach((plugin)=>{
66
- var _map_plugin_pluginType;
67
- (_map_plugin_pluginType = map[plugin.pluginType]) === null || _map_plugin_pluginType === void 0 ? void 0 : _map_plugin_pluginType.push(plugin.kind);
65
+ map[plugin.kind]?.push(plugin.spec.name);
68
66
  });
69
67
  }
70
68
  return map;
@@ -80,14 +78,13 @@ function useQueryType() {
80
78
  case 'TempoTraceQuery':
81
79
  return isTraceQueryPluginLoading;
82
80
  }
83
- throw new Error(`Unable to determine the query type: ${pluginKind}`);
81
+ return isTraceQueryPluginLoading || isTimeSeriesQueryLoading;
84
82
  };
85
83
  if (isLoading(pluginKind)) {
86
84
  return undefined;
87
85
  }
88
86
  for(const queryType in queryTypeMap){
89
- var _queryTypeMap_queryType;
90
- if ((_queryTypeMap_queryType = queryTypeMap[queryType]) === null || _queryTypeMap_queryType === void 0 ? void 0 : _queryTypeMap_queryType.includes(pluginKind)) {
87
+ if (queryTypeMap[queryType]?.includes(pluginKind)) {
91
88
  return queryType;
92
89
  }
93
90
  }
@@ -135,13 +135,13 @@ function TimeRangeProvider(props) {
135
135
  const absoluteTimeRange = (0, _core.isRelativeTimeRange)(localTimeRange) ? (0, _core.toAbsoluteTimeRange)(localTimeRange) : localTimeRange;
136
136
  return {
137
137
  timeRange: localTimeRange,
138
- setTimeRange: setTimeRange !== null && setTimeRange !== void 0 ? setTimeRange : setLocalTimeRange,
138
+ setTimeRange: setTimeRange ?? setLocalTimeRange,
139
139
  absoluteTimeRange,
140
140
  refresh,
141
141
  refreshKey: `${absoluteTimeRange.start}:${absoluteTimeRange.end}:${localRefreshInterval}:${refreshCounter}`,
142
142
  refreshInterval: localRefreshInterval,
143
143
  refreshIntervalInMs: refreshIntervalInMs,
144
- setRefreshInterval: setRefreshInterval !== null && setRefreshInterval !== void 0 ? setRefreshInterval : setLocalRefreshInterval
144
+ setRefreshInterval: setRefreshInterval ?? setLocalRefreshInterval
145
145
  };
146
146
  }, [
147
147
  localTimeRange,
@@ -59,7 +59,7 @@ function useBuiltinVariableValues(names) {
59
59
  ]);
60
60
  const values = (0, _react.useMemo)(()=>{
61
61
  const values = {};
62
- names === null || names === void 0 ? void 0 : names.forEach((name)=>{
62
+ names?.forEach((name)=>{
63
63
  const s = states[name];
64
64
  if (s) {
65
65
  values[name] = s;
@@ -47,15 +47,15 @@ function useDatasourceStore() {
47
47
  }
48
48
  return ctx;
49
49
  }
50
- function useListDatasourceSelectItems(datasourcePluginKind, project) {
50
+ function useListDatasourceSelectItems(datasourcePluginName, project) {
51
51
  const { listDatasourceSelectItems } = useDatasourceStore();
52
52
  return (0, _reactquery.useQuery)({
53
53
  queryKey: [
54
54
  'listDatasourceSelectItems',
55
- datasourcePluginKind,
55
+ datasourcePluginName,
56
56
  project
57
57
  ],
58
- queryFn: ()=>listDatasourceSelectItems(datasourcePluginKind)
58
+ queryFn: ()=>listDatasourceSelectItems(datasourcePluginName)
59
59
  });
60
60
  }
61
61
  function useDatasourceClient(selector) {
@@ -40,8 +40,8 @@ _export(exports, {
40
40
  return usePlugins;
41
41
  }
42
42
  });
43
- const _react = require("react");
44
43
  const _reactquery = require("@tanstack/react-query");
44
+ const _react = require("react");
45
45
  const PluginRegistryContext = (0, _react.createContext)(undefined);
46
46
  function usePluginRegistry() {
47
47
  const ctx = (0, _react.useContext)(PluginRegistryContext);
@@ -51,11 +51,10 @@ function usePluginRegistry() {
51
51
  return ctx;
52
52
  }
53
53
  function usePlugin(pluginType, kind, options) {
54
- var _options_enabled;
55
54
  // We never want to ask for a plugin when the kind isn't set yet, so disable those queries automatically
56
55
  options = {
57
56
  ...options,
58
- enabled: ((_options_enabled = options === null || options === void 0 ? void 0 : options.enabled) !== null && _options_enabled !== void 0 ? _options_enabled : true) && pluginType !== undefined && kind !== ''
57
+ enabled: (options?.enabled ?? true) && pluginType !== undefined && kind !== ''
59
58
  };
60
59
  const { getPlugin } = usePluginRegistry();
61
60
  return (0, _reactquery.useQuery)({
@@ -104,10 +103,10 @@ function usePluginBuiltinVariableDefinitions() {
104
103
  const datasources = await listPluginMetadata([
105
104
  'Datasource'
106
105
  ]);
107
- const datasourceKinds = new Set(datasources.map((datasource)=>datasource.kind));
106
+ const datasourceNames = new Set(datasources.map((datasource)=>datasource.spec.name));
108
107
  const result = [];
109
- for (const kind of datasourceKinds){
110
- const plugin = await getPlugin('Datasource', kind);
108
+ for (const name of datasourceNames){
109
+ const plugin = await getPlugin('Datasource', name);
111
110
  if (plugin.getBuiltinVariableDefinitions) {
112
111
  plugin.getBuiltinVariableDefinitions().forEach((definition)=>result.push(definition));
113
112
  }
@@ -56,8 +56,8 @@ function filterVariableStateMap(v, names) {
56
56
  }
57
57
  function getQueryOptions({ plugin, definition, context }) {
58
58
  const { timeRange, datasourceStore, suggestedStepMs, mode, variableState, refreshKey } = context;
59
- const dependencies = (plugin === null || plugin === void 0 ? void 0 : plugin.dependsOn) ? plugin.dependsOn(definition.spec.plugin.spec, context) : {};
60
- const variableDependencies = dependencies === null || dependencies === void 0 ? void 0 : dependencies.variables;
59
+ const dependencies = plugin?.dependsOn ? plugin.dependsOn(definition.spec.plugin.spec, context) : {};
60
+ const variableDependencies = dependencies?.variables;
61
61
  // Determine queryKey
62
62
  const filteredVariabledState = filterVariableStateMap(variableState, variableDependencies);
63
63
  const variablesValueKey = getVariableValuesKey(filteredVariabledState);
@@ -73,10 +73,7 @@ function getQueryOptions({ plugin, definition, context }) {
73
73
  // Determine queryEnabled
74
74
  let waitToLoad = false;
75
75
  if (variableDependencies) {
76
- waitToLoad = variableDependencies.some((v)=>{
77
- var _variableState_v;
78
- return (_variableState_v = variableState[v]) === null || _variableState_v === void 0 ? void 0 : _variableState_v.loading;
79
- });
76
+ waitToLoad = variableDependencies.some((v)=>variableState[v]?.loading);
80
77
  }
81
78
  const queryEnabled = plugin !== undefined && !waitToLoad;
82
79
  return {
@@ -92,9 +89,8 @@ const useTimeSeriesQuery = (definition, options, queryOptions)=>{
92
89
  definition,
93
90
  context
94
91
  });
95
- var _queryOptions_enabled;
96
92
  return (0, _reactquery.useQuery)({
97
- enabled: ((_queryOptions_enabled = queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.enabled) !== null && _queryOptions_enabled !== void 0 ? _queryOptions_enabled : true) || queryEnabled,
93
+ enabled: (queryOptions?.enabled ?? true) || queryEnabled,
98
94
  queryKey: queryKey,
99
95
  queryFn: ()=>{
100
96
  // The 'enabled' option should prevent this from happening, but make TypeScript happy by checking
@@ -104,7 +100,7 @@ const useTimeSeriesQuery = (definition, options, queryOptions)=>{
104
100
  // Keep options out of query key so we don't re-run queries because suggested step changes
105
101
  const ctx = {
106
102
  ...context,
107
- suggestedStepMs: options === null || options === void 0 ? void 0 : options.suggestedStepMs
103
+ suggestedStepMs: options?.suggestedStepMs
108
104
  };
109
105
  return plugin.getTimeSeriesData(definition.spec.plugin.spec, ctx);
110
106
  }
@@ -115,29 +111,27 @@ function useTimeSeriesQueries(definitions, options, queryOptions) {
115
111
  const context = {
116
112
  ...useTimeSeriesQueryContext(),
117
113
  // We need mode to be part query key because this drives the type of query done (instant VS range query)
118
- mode: options === null || options === void 0 ? void 0 : options.mode
114
+ mode: options?.mode
119
115
  };
120
116
  const pluginLoaderResponse = (0, _pluginregistry.usePlugins)(TIME_SERIES_QUERY_KEY, definitions.map((d)=>({
121
117
  kind: d.spec.plugin.kind
122
118
  })));
123
119
  return (0, _reactquery.useQueries)({
124
120
  queries: definitions.map((definition, idx)=>{
125
- var _pluginLoaderResponse_idx;
126
- const plugin = (_pluginLoaderResponse_idx = pluginLoaderResponse[idx]) === null || _pluginLoaderResponse_idx === void 0 ? void 0 : _pluginLoaderResponse_idx.data;
121
+ const plugin = pluginLoaderResponse[idx]?.data;
127
122
  const { queryEnabled, queryKey } = getQueryOptions({
128
123
  plugin,
129
124
  definition,
130
125
  context
131
126
  });
132
- var _queryOptions_enabled;
133
127
  return {
134
- enabled: ((_queryOptions_enabled = queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.enabled) !== null && _queryOptions_enabled !== void 0 ? _queryOptions_enabled : true) && queryEnabled,
128
+ enabled: (queryOptions?.enabled ?? true) && queryEnabled,
135
129
  queryKey: queryKey,
136
130
  queryFn: async ()=>{
137
131
  const ctx = {
138
132
  ...context,
139
133
  // Keep suggested step changes out of the query key, so we don´t have to run again query when it changes
140
- suggestedStepMs: options === null || options === void 0 ? void 0 : options.suggestedStepMs
134
+ suggestedStepMs: options?.suggestedStepMs
141
135
  };
142
136
  const plugin = await getPlugin(TIME_SERIES_QUERY_KEY, definition.spec.plugin.kind);
143
137
  const data = await plugin.getTimeSeriesData(definition.spec.plugin.spec, ctx);
@@ -170,9 +164,8 @@ function getActiveTimeSeriesQueries(cache) {
170
164
  for (const query of cache.findAll({
171
165
  type: 'active'
172
166
  })){
173
- var _query_queryKey;
174
- const firstPart = (_query_queryKey = query.queryKey) === null || _query_queryKey === void 0 ? void 0 : _query_queryKey[0];
175
- if ((firstPart === null || firstPart === void 0 ? void 0 : firstPart.kind) && firstPart.kind.startsWith(TIME_SERIES_QUERY_KEY)) {
167
+ const firstPart = query.queryKey?.[0];
168
+ if (firstPart?.kind && firstPart.kind.startsWith(TIME_SERIES_QUERY_KEY)) {
176
169
  queries.push(query);
177
170
  }
178
171
  }
@@ -56,13 +56,12 @@ function useTraceQueries(definitions) {
56
56
  // https://tanstack.com/query/v4/docs/react/reference/useQuery
57
57
  return (0, _reactquery.useQueries)({
58
58
  queries: definitions.map((definition)=>{
59
- var _definition_spec_plugin, _definition_spec;
60
59
  const queryKey = [
61
60
  definition,
62
61
  datasourceStore,
63
62
  absoluteTimeRange
64
63
  ]; // `queryKey` watches and reruns `queryFn` if keys in the array change
65
- const traceQueryKind = definition === null || definition === void 0 ? void 0 : (_definition_spec = definition.spec) === null || _definition_spec === void 0 ? void 0 : (_definition_spec_plugin = _definition_spec.plugin) === null || _definition_spec_plugin === void 0 ? void 0 : _definition_spec_plugin.kind;
64
+ const traceQueryKind = definition?.spec?.plugin?.kind;
66
65
  return {
67
66
  queryKey: queryKey,
68
67
  queryFn: async ()=>{