@perses-dev/plugin-system 0.7.0 → 0.8.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 (117) hide show
  1. package/dist/cjs/components/PluginLoadingBoundary/PluginLoader.js +2 -2
  2. package/dist/cjs/components/PluginLoadingBoundary/PluginLoadingBoundary.js +7 -7
  3. package/dist/cjs/components/PluginRegistry/PluginRegistry.js +48 -35
  4. package/dist/cjs/components/PluginRegistry/PluginRegistry.test.js +73 -0
  5. package/dist/cjs/components/PluginRegistry/index.js +2 -1
  6. package/dist/cjs/components/PluginRegistry/legacy/PluginRegistry.js +57 -0
  7. package/dist/cjs/components/PluginRegistry/legacy/index.js +29 -0
  8. package/dist/cjs/components/PluginRegistry/{registry-state.js → legacy/registry-state.js} +39 -39
  9. package/dist/cjs/components/PluginRegistry/plugin-indexes.js +67 -0
  10. package/dist/cjs/components/PluginRegistry/plugin-registry-model.js +25 -0
  11. package/dist/cjs/components/PluginRegistry/test-plugins/bert/index.js +26 -0
  12. package/dist/cjs/components/PluginRegistry/test-plugins/bert/plugin.json +32 -0
  13. package/dist/cjs/components/PluginRegistry/test-plugins/ernie/index.js +23 -0
  14. package/dist/cjs/components/PluginRegistry/test-plugins/ernie/plugin.json +24 -0
  15. package/dist/cjs/components/PluginRegistry/test-plugins/index.js +63 -0
  16. package/dist/cjs/components/index.js +1 -1
  17. package/dist/cjs/model/graph-queries.js +1 -1
  18. package/dist/cjs/model/index.js +2 -1
  19. package/dist/cjs/model/panels.js +26 -10
  20. package/dist/cjs/model/plugins.js +1 -1
  21. package/dist/cjs/model/variables.js +1 -1
  22. package/dist/cjs/model/visual-editing.js +14 -0
  23. package/dist/cjs/runtime/index.js +1 -0
  24. package/dist/cjs/runtime/plugins.js +38 -0
  25. package/dist/cjs/runtime/query-string.js +28 -0
  26. package/dist/cjs/runtime/template-variables.js +20 -9
  27. package/dist/cjs/runtime/time-range.js +1 -1
  28. package/dist/cjs/test/render.js +27 -0
  29. package/dist/cjs/test/setup-tests.js +24 -0
  30. package/dist/cjs/utils/cache-keys.js +22 -0
  31. package/dist/components/PluginLoadingBoundary/PluginLoader.js +1 -1
  32. package/dist/components/PluginLoadingBoundary/PluginLoadingBoundary.d.ts +2 -2
  33. package/dist/components/PluginLoadingBoundary/PluginLoadingBoundary.d.ts.map +1 -1
  34. package/dist/components/PluginLoadingBoundary/PluginLoadingBoundary.js +1 -1
  35. package/dist/components/PluginRegistry/PluginRegistry.d.ts +6 -21
  36. package/dist/components/PluginRegistry/PluginRegistry.d.ts.map +1 -1
  37. package/dist/components/PluginRegistry/PluginRegistry.js +1 -1
  38. package/dist/components/PluginRegistry/PluginRegistry.test.d.ts +2 -0
  39. package/dist/components/PluginRegistry/PluginRegistry.test.d.ts.map +1 -0
  40. package/dist/components/PluginRegistry/PluginRegistry.test.js +1 -0
  41. package/dist/components/PluginRegistry/index.d.ts +1 -0
  42. package/dist/components/PluginRegistry/index.d.ts.map +1 -1
  43. package/dist/components/PluginRegistry/index.js +1 -1
  44. package/dist/components/PluginRegistry/legacy/PluginRegistry.d.ts +29 -0
  45. package/dist/components/PluginRegistry/legacy/PluginRegistry.d.ts.map +1 -0
  46. package/dist/components/PluginRegistry/legacy/PluginRegistry.js +1 -0
  47. package/dist/components/PluginRegistry/legacy/index.d.ts +2 -0
  48. package/dist/components/PluginRegistry/legacy/index.d.ts.map +1 -0
  49. package/dist/components/PluginRegistry/legacy/index.js +1 -0
  50. package/dist/components/PluginRegistry/{registry-state.d.ts → legacy/registry-state.d.ts} +4 -4
  51. package/dist/components/PluginRegistry/legacy/registry-state.d.ts.map +1 -0
  52. package/dist/components/PluginRegistry/legacy/registry-state.js +1 -0
  53. package/dist/components/PluginRegistry/plugin-indexes.d.ts +11 -0
  54. package/dist/components/PluginRegistry/plugin-indexes.d.ts.map +1 -0
  55. package/dist/components/PluginRegistry/plugin-indexes.js +1 -0
  56. package/dist/components/PluginRegistry/plugin-registry-model.d.ts +10 -0
  57. package/dist/components/PluginRegistry/plugin-registry-model.d.ts.map +1 -0
  58. package/dist/components/PluginRegistry/plugin-registry-model.js +1 -0
  59. package/dist/components/PluginRegistry/test-plugins/bert/index.d.ts +4 -0
  60. package/dist/components/PluginRegistry/test-plugins/bert/index.d.ts.map +1 -0
  61. package/dist/components/PluginRegistry/test-plugins/bert/index.js +1 -0
  62. package/dist/components/PluginRegistry/test-plugins/bert/plugin.json +32 -0
  63. package/dist/components/PluginRegistry/test-plugins/ernie/index.d.ts +3 -0
  64. package/dist/components/PluginRegistry/test-plugins/ernie/index.d.ts.map +1 -0
  65. package/dist/components/PluginRegistry/test-plugins/ernie/index.js +1 -0
  66. package/dist/components/PluginRegistry/test-plugins/ernie/plugin.json +24 -0
  67. package/dist/components/PluginRegistry/test-plugins/index.d.ts +6 -0
  68. package/dist/components/PluginRegistry/test-plugins/index.d.ts.map +1 -0
  69. package/dist/components/PluginRegistry/test-plugins/index.js +1 -0
  70. package/dist/components/index.d.ts +1 -1
  71. package/dist/components/index.d.ts.map +1 -1
  72. package/dist/components/index.js +1 -1
  73. package/dist/model/graph-queries.js +1 -1
  74. package/dist/model/index.d.ts +1 -0
  75. package/dist/model/index.d.ts.map +1 -1
  76. package/dist/model/index.js +1 -1
  77. package/dist/model/panels.d.ts +5 -2
  78. package/dist/model/panels.d.ts.map +1 -1
  79. package/dist/model/panels.js +1 -1
  80. package/dist/model/plugins.d.ts +20 -35
  81. package/dist/model/plugins.d.ts.map +1 -1
  82. package/dist/model/variables.d.ts +3 -3
  83. package/dist/model/variables.d.ts.map +1 -1
  84. package/dist/model/variables.js +1 -1
  85. package/dist/model/visual-editing.d.ts +18 -0
  86. package/dist/model/visual-editing.d.ts.map +1 -0
  87. package/dist/model/visual-editing.js +1 -0
  88. package/dist/runtime/index.d.ts +1 -0
  89. package/dist/runtime/index.d.ts.map +1 -1
  90. package/dist/runtime/index.js +1 -1
  91. package/dist/runtime/plugins.d.ts +23 -0
  92. package/dist/runtime/plugins.d.ts.map +1 -0
  93. package/dist/runtime/plugins.js +1 -0
  94. package/dist/runtime/query-string.d.ts +11 -0
  95. package/dist/runtime/query-string.d.ts.map +1 -0
  96. package/dist/runtime/query-string.js +1 -0
  97. package/dist/runtime/template-variables.d.ts +6 -15
  98. package/dist/runtime/template-variables.d.ts.map +1 -1
  99. package/dist/runtime/template-variables.js +1 -1
  100. package/dist/runtime/time-range.d.ts +2 -2
  101. package/dist/runtime/time-range.d.ts.map +1 -1
  102. package/dist/test/render.d.ts +7 -0
  103. package/dist/test/render.d.ts.map +1 -0
  104. package/dist/test/render.js +1 -0
  105. package/dist/test/setup-tests.d.ts +2 -0
  106. package/dist/test/setup-tests.d.ts.map +1 -0
  107. package/dist/test/setup-tests.js +1 -0
  108. package/dist/utils/cache-keys.d.ts +6 -0
  109. package/dist/utils/cache-keys.d.ts.map +1 -0
  110. package/dist/utils/cache-keys.js +1 -0
  111. package/package.json +6 -6
  112. package/dist/cjs/components/PluginRegistry/create-plugin.js +0 -118
  113. package/dist/components/PluginRegistry/create-plugin.d.ts +0 -27
  114. package/dist/components/PluginRegistry/create-plugin.d.ts.map +0 -1
  115. package/dist/components/PluginRegistry/create-plugin.js +0 -1
  116. package/dist/components/PluginRegistry/registry-state.d.ts.map +0 -1
  117. package/dist/components/PluginRegistry/registry-state.js +0 -1
@@ -1,118 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InvalidPluginDefinitionError = exports.createGraphQueryPlugin = exports.createPanelPlugin = exports.createVariablePlugin = 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
- /**
19
- * Take a Variable plugin and wrap it so it works with AnyVariableDefinition,
20
- * doing runtime checking of the definition before delegating to the plugin.
21
- */
22
- function createVariablePlugin(config) {
23
- // Create runtime validation function
24
- const useRuntimeValidation = createValidationHook(config);
25
- // Wrap hook with validation (TODO: Can this wrapper become generic for all
26
- // plugin hooks?)
27
- function useVariableOptions(definition) {
28
- const { isValid, errorRef } = useRuntimeValidation();
29
- if (isValid(definition)) {
30
- return config.plugin.useVariableOptions(definition);
31
- }
32
- throw errorRef.current;
33
- }
34
- return {
35
- useVariableOptions,
36
- };
37
- }
38
- exports.createVariablePlugin = createVariablePlugin;
39
- /**
40
- * Take a Panel plugin and wraps it so it works with AnyPanelDefinition, doing
41
- * runtime checking of the definition before delegating to the plugin.
42
- */
43
- function createPanelPlugin(config) {
44
- const useRuntimeValidation = createValidationHook(config);
45
- // Wrap PanelComponent from config with validation (TODO: Can this wrapper
46
- // become generic for all Plugin components?)
47
- function PanelComponent(props) {
48
- const { definition, ...others } = props;
49
- const { isValid, errorRef } = useRuntimeValidation();
50
- if (isValid(definition)) {
51
- const { PanelComponent } = config.plugin;
52
- return (0, jsx_runtime_1.jsx)(PanelComponent, { definition: definition, ...others });
53
- }
54
- throw errorRef.current;
55
- }
56
- return {
57
- PanelComponent,
58
- };
59
- }
60
- exports.createPanelPlugin = createPanelPlugin;
61
- /**
62
- * Take a GraphQuery plugin and wrap it so it works with AnyChartQueryDefinition,
63
- * doing runtime validation of the definition before delegating to the plugin.
64
- */
65
- function createGraphQueryPlugin(config) {
66
- // Create runtime validation function
67
- const useRuntimeValidation = createValidationHook(config);
68
- // Wrap hook with validation (TODO: Can this wrapper become generic for all
69
- // plugin hooks?)
70
- function useGraphQuery(definition) {
71
- const { isValid, errorRef } = useRuntimeValidation();
72
- if (isValid(definition)) {
73
- return config.plugin.useGraphQuery(definition);
74
- }
75
- throw errorRef.current;
76
- }
77
- return {
78
- useGraphQuery,
79
- };
80
- }
81
- exports.createGraphQueryPlugin = createGraphQueryPlugin;
82
- // Create a hook for doing runtime validation of a plugin definition, given the
83
- // plugin's config
84
- function createValidationHook(config) {
85
- const useRuntimeValidation = () => {
86
- // Ref for storing any validation errors as a side-effect of calling isValid
87
- const errorRef = (0, react_1.useRef)(undefined);
88
- // Type guard that validates the generic runtime plugin definition data
89
- // is correct for Kind/Options
90
- const isValid = (definition) => {
91
- var _a, _b;
92
- // If they don't give us a validate function in the plugin config, not
93
- // much we can do so just assume we're OK
94
- const validateErrors = (_b = (_a = config.validate) === null || _a === void 0 ? void 0 : _a.call(config, definition)) !== null && _b !== void 0 ? _b : [];
95
- if (validateErrors.length === 0)
96
- return true;
97
- errorRef.current = new InvalidPluginDefinitionError(config.pluginType, config.kind, validateErrors);
98
- return false;
99
- };
100
- return {
101
- isValid,
102
- errorRef,
103
- };
104
- };
105
- return useRuntimeValidation;
106
- }
107
- /**
108
- * Thrown when ConfigData fails the runtime validation check for a plugin.
109
- */
110
- class InvalidPluginDefinitionError extends Error {
111
- constructor(pluginType, kind, validateErrors) {
112
- super(`Invalid ${pluginType} plugin definition for kind ${kind}`);
113
- this.pluginType = pluginType;
114
- this.kind = kind;
115
- this.validateErrors = validateErrors;
116
- }
117
- }
118
- exports.InvalidPluginDefinitionError = InvalidPluginDefinitionError;
@@ -1,27 +0,0 @@
1
- import { JsonObject } from '@perses-dev/core';
2
- import { PanelPlugin, PluginConfig, PluginType, VariablePlugin, GraphQueryPlugin } from '../../model';
3
- /**
4
- * Take a Variable plugin and wrap it so it works with AnyVariableDefinition,
5
- * doing runtime checking of the definition before delegating to the plugin.
6
- */
7
- export declare function createVariablePlugin<Options extends JsonObject>(config: PluginConfig<'Variable', Options>): VariablePlugin;
8
- /**
9
- * Take a Panel plugin and wraps it so it works with AnyPanelDefinition, doing
10
- * runtime checking of the definition before delegating to the plugin.
11
- */
12
- export declare function createPanelPlugin<Options extends JsonObject>(config: PluginConfig<'Panel', Options>): PanelPlugin;
13
- /**
14
- * Take a GraphQuery plugin and wrap it so it works with AnyChartQueryDefinition,
15
- * doing runtime validation of the definition before delegating to the plugin.
16
- */
17
- export declare function createGraphQueryPlugin<Options extends JsonObject>(config: PluginConfig<'GraphQuery', Options>): GraphQueryPlugin;
18
- /**
19
- * Thrown when ConfigData fails the runtime validation check for a plugin.
20
- */
21
- export declare class InvalidPluginDefinitionError extends Error {
22
- readonly pluginType: PluginType;
23
- readonly kind: string;
24
- readonly validateErrors: string[];
25
- constructor(pluginType: PluginType, kind: string, validateErrors: string[]);
26
- }
27
- //# sourceMappingURL=create-plugin.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-plugin.d.ts","sourceRoot":"","sources":["../../../src/components/PluginRegistry/create-plugin.tsx"],"names":[],"mappings":"AAcA,OAAO,EAAE,UAAU,EAAsB,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAEL,WAAW,EACX,YAAY,EAEZ,UAAU,EACV,cAAc,EACd,gBAAgB,EAEjB,MAAM,aAAa,CAAC;AAErB;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,SAAS,UAAU,EAC7D,MAAM,EAAE,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,GACxC,cAAc,CAiBhB;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,SAAS,UAAU,EAAE,MAAM,EAAE,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,WAAW,CAmBjH;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,SAAS,UAAU,EAC/D,MAAM,EAAE,YAAY,CAAC,YAAY,EAAE,OAAO,CAAC,GAC1C,gBAAgB,CAiBlB;AAsCD;;GAEG;AACH,qBAAa,4BAA6B,SAAQ,KAAK;IACzC,QAAQ,CAAC,UAAU,EAAE,UAAU;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM;IAAE,QAAQ,CAAC,cAAc,EAAE,MAAM,EAAE;gBAAhF,UAAU,EAAE,UAAU,EAAW,IAAI,EAAE,MAAM,EAAW,cAAc,EAAE,MAAM,EAAE;CAGtG"}
@@ -1 +0,0 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{useRef}from"react";export function createVariablePlugin(r){const n=createValidationHook(r);return{useVariableOptions:function(e){const{isValid:i,errorRef:t}=n();if(i(e))return r.plugin.useVariableOptions(e);throw t.current}}}export function createPanelPlugin(r){const n=createValidationHook(r);return{PanelComponent:function(e){const{definition:i,...t}=e,{isValid:o,errorRef:u}=n();if(o(i)){const{PanelComponent:n}=r.plugin;return _jsx(n,{definition:i,...t})}throw u.current}}}export function createGraphQueryPlugin(r){const n=createValidationHook(r);return{useGraphQuery:function(e){const{isValid:i,errorRef:t}=n();if(i(e))return r.plugin.useGraphQuery(e);throw t.current}}}function createValidationHook(r){return()=>{const n=useRef(void 0);return{isValid:e=>{var i,t;const o=null!==(t=null===(i=r.validate)||void 0===i?void 0:i.call(r,e))&&void 0!==t?t:[];return 0===o.length||(n.current=new InvalidPluginDefinitionError(r.pluginType,r.kind,o),!1)},errorRef:n}}}export class InvalidPluginDefinitionError extends Error{constructor(r,n,e){super(`Invalid ${r} plugin definition for kind ${n}`),this.pluginType=r,this.kind=n,this.validateErrors=e}}
@@ -1 +0,0 @@
1
- {"version":3,"file":"registry-state.d.ts","sourceRoot":"","sources":["../../../src/components/PluginRegistry/registry-state.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAEL,YAAY,EACZ,cAAc,EAEd,UAAU,EAEV,oBAAoB,EACrB,MAAM,aAAa,CAAC;AAIrB,oBAAY,4BAA4B,GAAG;KACxC,CAAC,IAAI,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC;CAClD,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,cAAc,EAAE;;;6BAuEjD,YAAY,KAAG,IAAI;EAerC"}
@@ -1 +0,0 @@
1
- import{useCallback,useMemo,useRef}from"react";import{useImmer}from"use-immer";import{ALL_PLUGIN_TYPES}from"../../model";import{createGraphQueryPlugin,createPanelPlugin,createVariablePlugin}from"./create-plugin";export function useRegistryState(e){const r=useMemo((()=>{const r={};for(const e of ALL_PLUGIN_TYPES)r[e]={};if(void 0===e)return r;const n=e=>{const n=e.spec.supported_kinds;for(const o in n){const t=n[o];if(void 0===t)continue;const i=r[t];void 0===i[o]?i[o]=e:console.warn(`Got multiple ${t} plugin definitions for kind ${o}`)}};for(const r of e)n(r);return r}),[e]),[n,o]=useImmer((()=>{const e={};for(const r of ALL_PLUGIN_TYPES)e[r]={};return e})),t=useCallback((e=>{switch(e.pluginType){case"Variable":return void o((r=>{r.Variable[e.kind]=createVariablePlugin(e)}));case"Panel":return void o((r=>{r.Panel[e.kind]=createPanelPlugin(e)}));case"GraphQuery":return void o((r=>{r.GraphQuery[e.kind]=createGraphQueryPlugin(e)}));default:throw new Error(`Unhandled plugin config: ${e}`)}}),[o]),i=useRef(new Set);return{loadablePlugins:r,plugins:n,register:useCallback((e=>{i.current.has(e)||(e.setup(t),i.current.add(e))}),[t])}}