@perses-dev/core 0.8.1 → 0.10.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.
- package/dist/cjs/index.js +18 -19
- package/dist/cjs/model/dashboard.js +5 -3
- package/dist/cjs/model/datasource.js +5 -3
- package/dist/cjs/model/definitions.js +7 -3
- package/dist/cjs/model/index.js +25 -26
- package/dist/cjs/model/layout.js +5 -3
- package/dist/cjs/model/panels.js +5 -3
- package/dist/cjs/model/resource.js +5 -3
- package/dist/cjs/model/{http.js → time-series-queries.js} +5 -8
- package/dist/cjs/model/time.js +41 -50
- package/dist/cjs/model/variables.js +5 -5
- package/dist/cjs/utils/event.js +12 -14
- package/dist/cjs/utils/fetch.js +17 -17
- package/dist/cjs/utils/index.js +19 -20
- package/dist/cjs/utils/memo.js +31 -25
- package/dist/cjs/utils/panel-refs.js +29 -11
- package/dist/index.js +16 -1
- package/dist/index.js.map +1 -0
- package/dist/model/dashboard.d.ts +2 -6
- package/dist/model/dashboard.d.ts.map +1 -1
- package/dist/model/dashboard.js +15 -1
- package/dist/model/dashboard.js.map +1 -0
- package/dist/model/datasource.d.ts +28 -10
- package/dist/model/datasource.d.ts.map +1 -1
- package/dist/model/datasource.js +15 -1
- package/dist/model/datasource.js.map +1 -0
- package/dist/model/definitions.d.ts +7 -12
- package/dist/model/definitions.d.ts.map +1 -1
- package/dist/model/definitions.js +17 -1
- package/dist/model/definitions.js.map +1 -0
- package/dist/model/index.d.ts +1 -1
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +23 -1
- package/dist/model/index.js.map +1 -0
- package/dist/model/layout.js +15 -1
- package/dist/model/layout.js.map +1 -0
- package/dist/model/panels.d.ts +6 -5
- package/dist/model/panels.d.ts.map +1 -1
- package/dist/model/panels.js +15 -1
- package/dist/model/panels.js.map +1 -0
- package/dist/model/resource.d.ts +4 -8
- package/dist/model/resource.d.ts.map +1 -1
- package/dist/model/resource.js +15 -1
- package/dist/model/resource.js.map +1 -0
- package/dist/model/time-series-queries.d.ts +8 -0
- package/dist/model/time-series-queries.d.ts.map +1 -0
- package/dist/model/time-series-queries.js +15 -0
- package/dist/model/time-series-queries.js.map +1 -0
- package/dist/model/time.js +88 -1
- package/dist/model/time.js.map +1 -0
- package/dist/model/variables.d.ts +17 -29
- package/dist/model/variables.d.ts.map +1 -1
- package/dist/model/variables.js +15 -1
- package/dist/model/variables.js.map +1 -0
- package/dist/utils/event.js +27 -1
- package/dist/utils/event.js.map +1 -0
- package/dist/utils/fetch.js +41 -1
- package/dist/utils/fetch.js.map +1 -0
- package/dist/utils/index.js +18 -1
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/memo.js +51 -1
- package/dist/utils/memo.js.map +1 -0
- package/dist/utils/panel-refs.d.ts +9 -4
- package/dist/utils/panel-refs.d.ts.map +1 -1
- package/dist/utils/panel-refs.js +40 -1
- package/dist/utils/panel-refs.js.map +1 -0
- package/package.json +6 -3
- package/dist/model/http.d.ts +0 -19
- package/dist/model/http.d.ts.map +0 -1
- package/dist/model/http.js +0 -1
|
@@ -1,41 +1,29 @@
|
|
|
1
|
-
import { Definition,
|
|
2
|
-
export declare const DEFAULT_ALL_VALUE: "$__all";
|
|
1
|
+
import { Definition, UnknownSpec } from './definitions';
|
|
3
2
|
export declare type VariableName = string;
|
|
4
|
-
export declare type VariableState = {
|
|
5
|
-
value: VariableValue;
|
|
6
|
-
options?: VariableOption[];
|
|
7
|
-
loading: boolean;
|
|
8
|
-
error?: Error;
|
|
9
|
-
};
|
|
10
|
-
export declare type VariableOption = {
|
|
11
|
-
label: string;
|
|
12
|
-
value: string;
|
|
13
|
-
};
|
|
14
|
-
export declare type VariableStateMap = Record<VariableName, VariableState>;
|
|
15
3
|
export declare type VariableValue = string | string[] | null;
|
|
16
|
-
|
|
17
|
-
kind: Kind;
|
|
4
|
+
interface VariableSpec {
|
|
18
5
|
name: VariableName;
|
|
19
6
|
display?: {
|
|
20
7
|
label?: string;
|
|
21
8
|
hidden?: boolean;
|
|
22
9
|
};
|
|
23
|
-
|
|
24
|
-
|
|
10
|
+
default_value?: VariableValue;
|
|
11
|
+
}
|
|
12
|
+
export interface TextVariableDefinition extends Definition<TextVariableSpec> {
|
|
13
|
+
kind: 'TextVariable';
|
|
25
14
|
}
|
|
26
|
-
export interface
|
|
15
|
+
export interface TextVariableSpec extends VariableSpec {
|
|
27
16
|
value: string;
|
|
28
17
|
}
|
|
29
|
-
export
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
};
|
|
39
|
-
export declare type ListVariableDefinition<Options extends JsonObject = JsonObject> = Variable<'ListVariable', ListVariableOptions<Options>>;
|
|
18
|
+
export interface ListVariableDefinition<PluginSpec = UnknownSpec> extends Definition<ListVariableSpec<PluginSpec>> {
|
|
19
|
+
kind: 'ListVariable';
|
|
20
|
+
}
|
|
21
|
+
export interface ListVariableSpec<PluginSpec> extends VariableSpec {
|
|
22
|
+
allow_multiple?: boolean;
|
|
23
|
+
allow_all_value?: boolean;
|
|
24
|
+
custom_all_value?: string;
|
|
25
|
+
plugin: Definition<PluginSpec>;
|
|
26
|
+
}
|
|
40
27
|
export declare type VariableDefinition = TextVariableDefinition | ListVariableDefinition;
|
|
28
|
+
export {};
|
|
41
29
|
//# sourceMappingURL=variables.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variables.d.ts","sourceRoot":"","sources":["../../src/model/variables.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"variables.d.ts","sourceRoot":"","sources":["../../src/model/variables.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAExD,oBAAY,YAAY,GAAG,MAAM,CAAC;AAElC,oBAAY,aAAa,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,CAAC;AAErD,UAAU,YAAY;IACpB,IAAI,EAAE,YAAY,CAAC;IACnB,OAAO,CAAC,EAAE;QACR,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,OAAO,CAAC;KAClB,CAAC;IACF,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B;AAED,MAAM,WAAW,sBAAuB,SAAQ,UAAU,CAAC,gBAAgB,CAAC;IAC1E,IAAI,EAAE,cAAc,CAAC;CACtB;AAED,MAAM,WAAW,gBAAiB,SAAQ,YAAY;IACpD,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,sBAAsB,CAAC,UAAU,GAAG,WAAW,CAAE,SAAQ,UAAU,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC;IAChH,IAAI,EAAE,cAAc,CAAC;CACtB;AAED,MAAM,WAAW,gBAAgB,CAAC,UAAU,CAAE,SAAQ,YAAY;IAChE,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,MAAM,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC;CAChC;AAED,oBAAY,kBAAkB,GAAG,sBAAsB,GAAG,sBAAsB,CAAC"}
|
package/dist/model/variables.js
CHANGED
|
@@ -1 +1,15 @@
|
|
|
1
|
-
|
|
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
|
+
export { };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=variables.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/model/variables.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 { Definition, UnknownSpec } from './definitions';\n\nexport type VariableName = string;\n\nexport type VariableValue = string | string[] | null;\n\ninterface VariableSpec {\n name: VariableName;\n display?: {\n label?: string;\n hidden?: boolean;\n };\n default_value?: VariableValue;\n}\n\nexport interface TextVariableDefinition extends Definition<TextVariableSpec> {\n kind: 'TextVariable';\n}\n\nexport interface TextVariableSpec extends VariableSpec {\n value: string;\n}\n\nexport interface ListVariableDefinition<PluginSpec = UnknownSpec> extends Definition<ListVariableSpec<PluginSpec>> {\n kind: 'ListVariable';\n}\n\nexport interface ListVariableSpec<PluginSpec> extends VariableSpec {\n allow_multiple?: boolean;\n allow_all_value?: boolean;\n custom_all_value?: string;\n plugin: Definition<PluginSpec>;\n}\n\nexport type VariableDefinition = TextVariableDefinition | ListVariableDefinition;\n"],"names":[],"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;AAEjC,WAkCiF"}
|
package/dist/utils/event.js
CHANGED
|
@@ -1 +1,27 @@
|
|
|
1
|
-
|
|
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
|
+
import { useRef, useLayoutEffect, useCallback } from 'react';
|
|
14
|
+
/**
|
|
15
|
+
* A (temporary) userland implementation of `useEvent` from this React RFC: https://github.com/reactjs/rfcs/pull/220.
|
|
16
|
+
*
|
|
17
|
+
* Typically useful for getting a stable reference to an "event" function (i.e. one that isn't called during render
|
|
18
|
+
* but is called later in a useEffect or event handler) that accesses state or props.
|
|
19
|
+
*/ export function useEvent(handler) {
|
|
20
|
+
const handlerRef = useRef(handler);
|
|
21
|
+
useLayoutEffect(()=>{
|
|
22
|
+
handlerRef.current = handler;
|
|
23
|
+
});
|
|
24
|
+
return useCallback((...args)=>handlerRef.current(...args), []);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=event.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/event.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 { useRef, useLayoutEffect, useCallback } from 'react';\n\n/**\n * A (temporary) userland implementation of `useEvent` from this React RFC: https://github.com/reactjs/rfcs/pull/220.\n *\n * Typically useful for getting a stable reference to an \"event\" function (i.e. one that isn't called during render\n * but is called later in a useEffect or event handler) that accesses state or props.\n */\nexport function useEvent<T extends unknown[], U>(handler: (...args: T) => U): (...args: T) => U {\n const handlerRef = useRef(handler);\n useLayoutEffect(() => {\n handlerRef.current = handler;\n });\n\n return useCallback((...args) => handlerRef.current(...args), []);\n}\n"],"names":["useRef","useLayoutEffect","useCallback","useEvent","handler","handlerRef","current","args"],"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;AAEjC,SAASA,MAAM,EAAEC,eAAe,EAAEC,WAAW,QAAQ,OAAO,CAAC;AAE7D;;;;;CAKC,GACD,OAAO,SAASC,QAAQ,CAAyBC,OAA0B,EAAqB;IAC9F,MAAMC,UAAU,GAAGL,MAAM,CAACI,OAAO,CAAC,AAAC;IACnCH,eAAe,CAAC,IAAM;QACpBI,UAAU,CAACC,OAAO,GAAGF,OAAO,CAAC;IAC/B,CAAC,CAAC,CAAC;IAEH,OAAOF,WAAW,CAAC,CAAIK,GAAAA,IAAI,GAAKF,UAAU,CAACC,OAAO,IAAIC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;AACnE,CAAC"}
|
package/dist/utils/fetch.js
CHANGED
|
@@ -1 +1,41 @@
|
|
|
1
|
-
|
|
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
|
+
* Calls `global.fetch`, but throws a `FetchError` for non-200 responses.
|
|
15
|
+
*/ export async function fetch(...args) {
|
|
16
|
+
const response = await global.fetch(...args);
|
|
17
|
+
if (response.ok === false) {
|
|
18
|
+
throw new FetchError(response);
|
|
19
|
+
}
|
|
20
|
+
return response;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Calls `global.fetch` and throws a `FetchError` on non-200 responses, but also
|
|
24
|
+
* decodes the response body as JSON, casting it to type `T`. Returns the
|
|
25
|
+
* decoded body.
|
|
26
|
+
*/ export async function fetchJson(...args) {
|
|
27
|
+
const response = await fetch(...args);
|
|
28
|
+
const json = await response.json();
|
|
29
|
+
return json;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Error thrown when fetch returns a non-200 response.
|
|
33
|
+
*/ export class FetchError extends Error {
|
|
34
|
+
constructor(response){
|
|
35
|
+
super(`${response.status} ${response.statusText}`);
|
|
36
|
+
this.response = response;
|
|
37
|
+
Object.setPrototypeOf(this, FetchError.prototype);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
//# sourceMappingURL=fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/fetch.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\n/**\n * Calls `global.fetch`, but throws a `FetchError` for non-200 responses.\n */\nexport async function fetch(...args: Parameters<typeof global.fetch>) {\n const response = await global.fetch(...args);\n if (response.ok === false) {\n throw new FetchError(response);\n }\n return response;\n}\n\n/**\n * Calls `global.fetch` and throws a `FetchError` on non-200 responses, but also\n * decodes the response body as JSON, casting it to type `T`. Returns the\n * decoded body.\n */\nexport async function fetchJson<T>(...args: Parameters<typeof global.fetch>) {\n const response = await fetch(...args);\n const json: T = await response.json();\n return json;\n}\n\n/**\n * Error thrown when fetch returns a non-200 response.\n */\nexport class FetchError extends Error {\n constructor(readonly response: Response) {\n super(`${response.status} ${response.statusText}`);\n Object.setPrototypeOf(this, FetchError.prototype);\n }\n}\n"],"names":["fetch","args","response","global","ok","FetchError","fetchJson","json","Error","constructor","status","statusText","Object","setPrototypeOf","prototype"],"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;AAEjC;;CAEC,GACD,OAAO,eAAeA,KAAK,CAAC,GAAGC,IAAI,AAAiC,EAAE;IACpE,MAAMC,QAAQ,GAAG,MAAMC,MAAM,CAACH,KAAK,IAAIC,IAAI,CAAC,AAAC;IAC7C,IAAIC,QAAQ,CAACE,EAAE,KAAK,KAAK,EAAE;QACzB,MAAM,IAAIC,UAAU,CAACH,QAAQ,CAAC,CAAC;IACjC,CAAC;IACD,OAAOA,QAAQ,CAAC;AAClB,CAAC;AAED;;;;CAIC,GACD,OAAO,eAAeI,SAAS,CAAI,GAAGL,IAAI,AAAiC,EAAE;IAC3E,MAAMC,QAAQ,GAAG,MAAMF,KAAK,IAAIC,IAAI,CAAC,AAAC;IACtC,MAAMM,IAAI,GAAM,MAAML,QAAQ,CAACK,IAAI,EAAE,AAAC;IACtC,OAAOA,IAAI,CAAC;AACd,CAAC;AAED;;CAEC,GACD,OAAO,MAAMF,UAAU,SAASG,KAAK;IACnCC,YAAqBP,QAAkB,CAAE;QACvC,KAAK,CAAC,CAAC,EAAEA,QAAQ,CAACQ,MAAM,CAAC,CAAC,EAAER,QAAQ,CAACS,UAAU,CAAC,CAAC,CAAC,CAAC;QADhCT,gBAAAA,QAAkB,CAAA;QAErCU,MAAM,CAACC,cAAc,CAAC,IAAI,EAAER,UAAU,CAACS,SAAS,CAAC,CAAC;IACpD;CACD"}
|
package/dist/utils/index.js
CHANGED
|
@@ -1 +1,18 @@
|
|
|
1
|
-
|
|
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
|
+
export * from './event';
|
|
14
|
+
export * from './fetch';
|
|
15
|
+
export * from './memo';
|
|
16
|
+
export * from './panel-refs';
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/index.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\nexport * from './event';\nexport * from './fetch';\nexport * from './memo';\nexport * from './panel-refs';\n"],"names":[],"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;AAEjC,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC"}
|
package/dist/utils/memo.js
CHANGED
|
@@ -1 +1,51 @@
|
|
|
1
|
-
|
|
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
|
+
import { useRef } from 'react';
|
|
14
|
+
import { isEqual } from 'lodash-es';
|
|
15
|
+
/**
|
|
16
|
+
* Like React's useMemo, but guarantees the value will only be recalulated if
|
|
17
|
+
* a dependency changes. Uses strict equality (===) for comparison. (React's
|
|
18
|
+
* useMemo does not offer this guarantee, it's only a performance optimization).
|
|
19
|
+
*/ export function useMemoized(factory, deps) {
|
|
20
|
+
const ref = useRef();
|
|
21
|
+
let areEqual = true;
|
|
22
|
+
for(let i = 0; i < deps.length; i++){
|
|
23
|
+
var ref1;
|
|
24
|
+
if (((ref1 = ref.current) === null || ref1 === void 0 ? void 0 : ref1.deps[i]) !== deps[i]) {
|
|
25
|
+
areEqual = false;
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (ref.current === undefined || areEqual === false) {
|
|
30
|
+
ref.current = {
|
|
31
|
+
value: factory(),
|
|
32
|
+
deps: deps
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
return ref.current.value;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Like React's useMemo, except it does a deep equality comparison with lodash's
|
|
39
|
+
* isEqual on the dependency list.
|
|
40
|
+
*/ export function useDeepMemo(factory, deps) {
|
|
41
|
+
const ref = useRef();
|
|
42
|
+
if (ref.current === undefined || isEqual(deps, ref.current.deps) === false) {
|
|
43
|
+
ref.current = {
|
|
44
|
+
value: factory(),
|
|
45
|
+
deps
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return ref.current.value;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=memo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/memo.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 { useRef, DependencyList } from 'react';\nimport { isEqual } from 'lodash-es';\n\ntype MemoRef<T> = {\n value: T;\n deps: DependencyList;\n};\n\n/**\n * Like React's useMemo, but guarantees the value will only be recalulated if\n * a dependency changes. Uses strict equality (===) for comparison. (React's\n * useMemo does not offer this guarantee, it's only a performance optimization).\n */\nexport function useMemoized<T>(factory: () => T, deps: DependencyList) {\n const ref = useRef<MemoRef<T>>();\n\n let areEqual = true;\n for (let i = 0; i < deps.length; i++) {\n if (ref.current?.deps[i] !== deps[i]) {\n areEqual = false;\n break;\n }\n }\n\n if (ref.current === undefined || areEqual === false) {\n ref.current = { value: factory(), deps: deps };\n }\n\n return ref.current.value;\n}\n\n/**\n * Like React's useMemo, except it does a deep equality comparison with lodash's\n * isEqual on the dependency list.\n */\nexport function useDeepMemo<T>(factory: () => T, deps: DependencyList): T {\n const ref = useRef<MemoRef<T>>();\n if (ref.current === undefined || isEqual(deps, ref.current.deps) === false) {\n ref.current = { value: factory(), deps };\n }\n return ref.current.value;\n}\n"],"names":["useRef","isEqual","useMemoized","factory","deps","ref","areEqual","i","length","current","undefined","value","useDeepMemo"],"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;AAEjC,SAASA,MAAM,QAAwB,OAAO,CAAC;AAC/C,SAASC,OAAO,QAAQ,WAAW,CAAC;AAOpC;;;;CAIC,GACD,OAAO,SAASC,WAAW,CAAIC,OAAgB,EAAEC,IAAoB,EAAE;IACrE,MAAMC,GAAG,GAAGL,MAAM,EAAc,AAAC;IAEjC,IAAIM,QAAQ,GAAG,IAAI,AAAC;IACpB,IAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGH,IAAI,CAACI,MAAM,EAAED,CAAC,EAAE,CAAE;YAChCF,IAAW;QAAf,IAAIA,CAAAA,CAAAA,IAAW,GAAXA,GAAG,CAACI,OAAO,cAAXJ,IAAW,WAAM,GAAjBA,KAAAA,CAAiB,GAAjBA,IAAW,CAAED,IAAI,CAACG,CAAC,CAAC,MAAKH,IAAI,CAACG,CAAC,CAAC,EAAE;YACpCD,QAAQ,GAAG,KAAK,CAAC;YACjB,MAAM;QACR,CAAC;IACH,CAAC;IAED,IAAID,GAAG,CAACI,OAAO,KAAKC,SAAS,IAAIJ,QAAQ,KAAK,KAAK,EAAE;QACnDD,GAAG,CAACI,OAAO,GAAG;YAAEE,KAAK,EAAER,OAAO,EAAE;YAAEC,IAAI,EAAEA,IAAI;SAAE,CAAC;IACjD,CAAC;IAED,OAAOC,GAAG,CAACI,OAAO,CAACE,KAAK,CAAC;AAC3B,CAAC;AAED;;;CAGC,GACD,OAAO,SAASC,WAAW,CAAIT,OAAgB,EAAEC,IAAoB,EAAK;IACxE,MAAMC,GAAG,GAAGL,MAAM,EAAc,AAAC;IACjC,IAAIK,GAAG,CAACI,OAAO,KAAKC,SAAS,IAAIT,OAAO,CAACG,IAAI,EAAEC,GAAG,CAACI,OAAO,CAACL,IAAI,CAAC,KAAK,KAAK,EAAE;QAC1EC,GAAG,CAACI,OAAO,GAAG;YAAEE,KAAK,EAAER,OAAO,EAAE;YAAEC,IAAI;SAAE,CAAC;IAC3C,CAAC;IACD,OAAOC,GAAG,CAACI,OAAO,CAACE,KAAK,CAAC;AAC3B,CAAC"}
|
|
@@ -3,8 +3,13 @@ import { DashboardSpec, PanelRef } from '../model';
|
|
|
3
3
|
* Resolve a PanelRef (JSON reference) against the provided DashboardSpec to
|
|
4
4
|
* a PanelDefinition.
|
|
5
5
|
*/
|
|
6
|
-
export declare function resolvePanelRef(spec: DashboardSpec, panelRef: PanelRef):
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
export declare function resolvePanelRef(spec: DashboardSpec, panelRef: PanelRef): import("../model").PanelDefinition<import("../model").UnknownSpec>;
|
|
7
|
+
/**
|
|
8
|
+
* Gets the unique key for a panel from a PanelRef.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getPanelKeyFromRef(panelRef: PanelRef): string;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a PanelRef for a panel with the given key.
|
|
13
|
+
*/
|
|
14
|
+
export declare function createPanelRef(panelKey: string): PanelRef;
|
|
10
15
|
//# sourceMappingURL=panel-refs.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"panel-refs.d.ts","sourceRoot":"","sources":["../../src/utils/panel-refs.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEnD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ
|
|
1
|
+
{"version":3,"file":"panel-refs.d.ts","sourceRoot":"","sources":["../../src/utils/panel-refs.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEnD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,sEAOtE;AAMD;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,UAEpD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ,CAEzD"}
|
package/dist/utils/panel-refs.js
CHANGED
|
@@ -1 +1,40 @@
|
|
|
1
|
-
|
|
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
|
+
* Resolve a PanelRef (JSON reference) against the provided DashboardSpec to
|
|
15
|
+
* a PanelDefinition.
|
|
16
|
+
*/ export function resolvePanelRef(spec, panelRef) {
|
|
17
|
+
const panelsKey = getPanelKeyFromRef(panelRef);
|
|
18
|
+
const panelDefinition = spec.panels[panelsKey];
|
|
19
|
+
if (panelDefinition === undefined) {
|
|
20
|
+
throw new Error(`Could not resolve panels reference ${panelRef.$ref}`);
|
|
21
|
+
}
|
|
22
|
+
return panelDefinition;
|
|
23
|
+
}
|
|
24
|
+
// Currently, panel refs are prefixed with `#/spec/panels/`. If that format changes, we'll definitely need to update
|
|
25
|
+
// the code in here relying on it being that format.
|
|
26
|
+
const REF_PREFIX_LENGTH = 14;
|
|
27
|
+
/**
|
|
28
|
+
* Gets the unique key for a panel from a PanelRef.
|
|
29
|
+
*/ export function getPanelKeyFromRef(panelRef) {
|
|
30
|
+
return panelRef.$ref.substring(REF_PREFIX_LENGTH);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Creates a PanelRef for a panel with the given key.
|
|
34
|
+
*/ export function createPanelRef(panelKey) {
|
|
35
|
+
return {
|
|
36
|
+
$ref: `#/spec/panels/${panelKey}`
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=panel-refs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/panel-refs.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 { DashboardSpec, PanelRef } from '../model';\n\n/**\n * Resolve a PanelRef (JSON reference) against the provided DashboardSpec to\n * a PanelDefinition.\n */\nexport function resolvePanelRef(spec: DashboardSpec, panelRef: PanelRef) {\n const panelsKey = getPanelKeyFromRef(panelRef);\n const panelDefinition = spec.panels[panelsKey];\n if (panelDefinition === undefined) {\n throw new Error(`Could not resolve panels reference ${panelRef.$ref}`);\n }\n return panelDefinition;\n}\n\n// Currently, panel refs are prefixed with `#/spec/panels/`. If that format changes, we'll definitely need to update\n// the code in here relying on it being that format.\nconst REF_PREFIX_LENGTH = 14;\n\n/**\n * Gets the unique key for a panel from a PanelRef.\n */\nexport function getPanelKeyFromRef(panelRef: PanelRef) {\n return panelRef.$ref.substring(REF_PREFIX_LENGTH);\n}\n\n/**\n * Creates a PanelRef for a panel with the given key.\n */\nexport function createPanelRef(panelKey: string): PanelRef {\n return { $ref: `#/spec/panels/${panelKey}` };\n}\n"],"names":["resolvePanelRef","spec","panelRef","panelsKey","getPanelKeyFromRef","panelDefinition","panels","undefined","Error","$ref","REF_PREFIX_LENGTH","substring","createPanelRef","panelKey"],"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;;;CAGC,GACD,OAAO,SAASA,eAAe,CAACC,IAAmB,EAAEC,QAAkB,EAAE;IACvE,MAAMC,SAAS,GAAGC,kBAAkB,CAACF,QAAQ,CAAC,AAAC;IAC/C,MAAMG,eAAe,GAAGJ,IAAI,CAACK,MAAM,CAACH,SAAS,CAAC,AAAC;IAC/C,IAAIE,eAAe,KAAKE,SAAS,EAAE;QACjC,MAAM,IAAIC,KAAK,CAAC,CAAC,mCAAmC,EAAEN,QAAQ,CAACO,IAAI,CAAC,CAAC,CAAC,CAAC;IACzE,CAAC;IACD,OAAOJ,eAAe,CAAC;AACzB,CAAC;AAED,oHAAoH;AACpH,oDAAoD;AACpD,MAAMK,iBAAiB,GAAG,EAAE,AAAC;AAE7B;;CAEC,GACD,OAAO,SAASN,kBAAkB,CAACF,QAAkB,EAAE;IACrD,OAAOA,QAAQ,CAACO,IAAI,CAACE,SAAS,CAACD,iBAAiB,CAAC,CAAC;AACpD,CAAC;AAED;;CAEC,GACD,OAAO,SAASE,cAAc,CAACC,QAAgB,EAAY;IACzD,OAAO;QAAEJ,IAAI,EAAE,CAAC,cAAc,EAAEI,QAAQ,CAAC,CAAC;KAAE,CAAC;AAC/C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@perses-dev/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Core functionality consumed by both the Perses UI and plugins",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/perses/perses/blob/main/README.md",
|
|
@@ -16,8 +16,11 @@
|
|
|
16
16
|
"types": "dist/index.d.ts",
|
|
17
17
|
"scripts": {
|
|
18
18
|
"clean": "rimraf dist/",
|
|
19
|
-
"build": "
|
|
20
|
-
"build:cjs": "
|
|
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": "echo 'no test to run' && exit 0",
|
|
22
25
|
"lint": "eslint src --ext .ts,.tsx",
|
|
23
26
|
"lint:fix": "eslint --fix src --ext .ts,.tsx"
|
package/dist/model/http.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export interface BasicAuth {
|
|
2
|
-
username: string;
|
|
3
|
-
password: string;
|
|
4
|
-
password_file: string;
|
|
5
|
-
}
|
|
6
|
-
export interface HTTPAuth {
|
|
7
|
-
insecure_tls: boolean;
|
|
8
|
-
bearer_token: string;
|
|
9
|
-
basic_auth?: BasicAuth;
|
|
10
|
-
cac_cert: string;
|
|
11
|
-
}
|
|
12
|
-
export interface HTTPConfig {
|
|
13
|
-
url: string;
|
|
14
|
-
access: 'browser' | 'server';
|
|
15
|
-
auth?: HTTPAuth;
|
|
16
|
-
headers?: Record<string, string>;
|
|
17
|
-
}
|
|
18
|
-
export declare function buildDatasourceURL(datasourceName: string, config: HTTPConfig): string;
|
|
19
|
-
//# sourceMappingURL=http.d.ts.map
|
package/dist/model/http.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/model/http.ts"],"names":[],"mappings":"AAaA,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,QAAQ;IACvB,YAAY,EAAE,OAAO,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC7B,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,wBAAgB,kBAAkB,CAAC,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAG,MAAM,CAErF"}
|
package/dist/model/http.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export function buildDatasourceURL(r,e){return"server"===e.access?`/proxy/globaldatasources/${r}`:e.url}
|