@perses-dev/prometheus-plugin 0.4.1 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// limitations under the License.
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.useReplaceTemplateString = exports.useReplaceTemplateStrings = void 0;
|
|
16
|
-
const lezer_promql_1 = require("lezer-promql");
|
|
16
|
+
const lezer_promql_1 = require("@prometheus-io/lezer-promql");
|
|
17
17
|
const core_1 = require("@perses-dev/core");
|
|
18
18
|
const plugin_system_1 = require("@perses-dev/plugin-system");
|
|
19
19
|
const REPLACE_IN_NODE_TYPES = new Set([lezer_promql_1.StringLiteral, lezer_promql_1.Duration]);
|
package/dist/model/templating.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Duration,parser,StringLiteral}from"lezer-promql";import{useMemoized,DEFAULT_ALL_VALUE}from"@perses-dev/core";import{useTemplateVariables}from"@perses-dev/plugin-system";const REPLACE_IN_NODE_TYPES=new Set([StringLiteral,Duration]);export function useReplaceTemplateStrings(e){const{variables:r}=useTemplateVariables();return useMemoized((()=>{const t=[],a=new Set;for(const s of null!=e?e:[]){const e=replaceTemplateVariables(s,r);t.push(e.result);for(const r of e.needsVariableValuesFor)a.add(r)}return{result:t,needsVariableValuesFor:a}}),[e,r])}export function useReplaceTemplateString(e){const{variables:r}=useTemplateVariables();return useMemoized((()=>void 0===e?{result:"",needsVariableValuesFor:new Set}:replaceTemplateVariables(e,r)),[e,r])}function replaceTemplateVariables(e,r){const t=new Set;let a=0;const s=parser.parse(e).cursor();do{if(REPLACE_IN_NODE_TYPES.has(s.node.type.id))continue;let{from:l,to:n}=s.node;l+=a,n+=a;let o=e.substring(l,n);o=o.replaceAll(/\$([a-zA-Z0-9_-]+)/g,((e,a)=>{const s=r[a];if(void 0===s)throw new Error(`Unknown variable '${a}'`);const{value:l,options:n}=s;let o;if(Array.isArray(l)){let r=l;if(1===l.length&&l[0]===DEFAULT_ALL_VALUE){if(void 0===n)return t.add(a),e;r=n}o=r.map((e=>e)).join("|")}else o=escapeVariableValue(l);return o}));const i=n-l;a+=o.length-i,e=e.substring(0,l)+o+e.substring(l+i)}while(s.next());return{result:e,needsVariableValuesFor:t}}const SINGLE_BACKSLASH="\\",DOUBLE_BACKSLASH="\\\\";function escapeVariableValue(e){return e.replaceAll("\\","\\\\")}
|
|
1
|
+
import{Duration,parser,StringLiteral}from"@prometheus-io/lezer-promql";import{useMemoized,DEFAULT_ALL_VALUE}from"@perses-dev/core";import{useTemplateVariables}from"@perses-dev/plugin-system";const REPLACE_IN_NODE_TYPES=new Set([StringLiteral,Duration]);export function useReplaceTemplateStrings(e){const{variables:r}=useTemplateVariables();return useMemoized((()=>{const t=[],a=new Set;for(const s of null!=e?e:[]){const e=replaceTemplateVariables(s,r);t.push(e.result);for(const r of e.needsVariableValuesFor)a.add(r)}return{result:t,needsVariableValuesFor:a}}),[e,r])}export function useReplaceTemplateString(e){const{variables:r}=useTemplateVariables();return useMemoized((()=>void 0===e?{result:"",needsVariableValuesFor:new Set}:replaceTemplateVariables(e,r)),[e,r])}function replaceTemplateVariables(e,r){const t=new Set;let a=0;const s=parser.parse(e).cursor();do{if(REPLACE_IN_NODE_TYPES.has(s.node.type.id))continue;let{from:l,to:n}=s.node;l+=a,n+=a;let o=e.substring(l,n);o=o.replaceAll(/\$([a-zA-Z0-9_-]+)/g,((e,a)=>{const s=r[a];if(void 0===s)throw new Error(`Unknown variable '${a}'`);const{value:l,options:n}=s;let o;if(Array.isArray(l)){let r=l;if(1===l.length&&l[0]===DEFAULT_ALL_VALUE){if(void 0===n)return t.add(a),e;r=n}o=r.map((e=>e)).join("|")}else o=escapeVariableValue(l);return o}));const i=n-l;a+=o.length-i,e=e.substring(0,l)+o+e.substring(l+i)}while(s.next());return{result:e,needsVariableValuesFor:t}}const SINGLE_BACKSLASH="\\",DOUBLE_BACKSLASH="\\\\";function escapeVariableValue(e){return e.replaceAll("\\","\\\\")}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@perses-dev/prometheus-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Prometheus plugin for Perses",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/perses/perses/blob/main/README.md",
|
|
@@ -23,11 +23,12 @@
|
|
|
23
23
|
"lint:fix": "eslint --fix src --ext .ts,.tsx"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@lezer/
|
|
27
|
-
"@
|
|
28
|
-
"@perses-dev/
|
|
29
|
-
"
|
|
30
|
-
"lezer-promql": "^0.
|
|
26
|
+
"@lezer/highlight": "^1.0.0",
|
|
27
|
+
"@lezer/lr": "^1.2.0",
|
|
28
|
+
"@perses-dev/core": "^0.5.1",
|
|
29
|
+
"@perses-dev/plugin-system": "^0.5.1",
|
|
30
|
+
"@prometheus-io/lezer-promql": "^0.37.0",
|
|
31
|
+
"date-fns": "^2.28.0"
|
|
31
32
|
},
|
|
32
33
|
"peerDependencies": {
|
|
33
34
|
"react": "^17.0.2",
|