@perses-dev/core 0.1.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 (61) hide show
  1. package/dist/context/PluginRuntimeContext.d.ts +26 -0
  2. package/dist/context/PluginRuntimeContext.d.ts.map +1 -0
  3. package/dist/context/PluginRuntimeContext.js +31 -0
  4. package/dist/hooks/dashboard.d.ts +22 -0
  5. package/dist/hooks/dashboard.d.ts.map +1 -0
  6. package/dist/hooks/dashboard.js +31 -0
  7. package/dist/hooks/datasource.d.ts +5 -0
  8. package/dist/hooks/datasource.d.ts.map +1 -0
  9. package/dist/hooks/datasource.js +26 -0
  10. package/dist/hooks/graph-query.d.ts +4 -0
  11. package/dist/hooks/graph-query.d.ts.map +1 -0
  12. package/dist/hooks/graph-query.js +16 -0
  13. package/dist/hooks/memo.d.ts +13 -0
  14. package/dist/hooks/memo.d.ts.map +1 -0
  15. package/dist/hooks/memo.js +45 -0
  16. package/dist/hooks/panel.d.ts +11 -0
  17. package/dist/hooks/panel.d.ts.map +1 -0
  18. package/dist/hooks/panel.js +19 -0
  19. package/dist/index.d.ts +20 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +31 -0
  22. package/dist/model/dashboard.d.ts +23 -0
  23. package/dist/model/dashboard.d.ts.map +1 -0
  24. package/dist/model/dashboard.js +13 -0
  25. package/dist/model/datasource.d.ts +17 -0
  26. package/dist/model/datasource.d.ts.map +1 -0
  27. package/dist/model/datasource.js +13 -0
  28. package/dist/model/definitions.d.ts +18 -0
  29. package/dist/model/definitions.d.ts.map +1 -0
  30. package/dist/model/definitions.js +13 -0
  31. package/dist/model/graph-query.d.ts +28 -0
  32. package/dist/model/graph-query.d.ts.map +1 -0
  33. package/dist/model/graph-query.js +13 -0
  34. package/dist/model/http.d.ts +19 -0
  35. package/dist/model/http.d.ts.map +1 -0
  36. package/dist/model/http.js +15 -0
  37. package/dist/model/json-references.d.ts +12 -0
  38. package/dist/model/json-references.d.ts.map +1 -0
  39. package/dist/model/json-references.js +24 -0
  40. package/dist/model/layout.d.ts +20 -0
  41. package/dist/model/layout.d.ts.map +1 -0
  42. package/dist/model/layout.js +13 -0
  43. package/dist/model/panels.d.ts +21 -0
  44. package/dist/model/panels.d.ts.map +1 -0
  45. package/dist/model/panels.js +13 -0
  46. package/dist/model/plugins.d.ts +87 -0
  47. package/dist/model/plugins.d.ts.map +1 -0
  48. package/dist/model/plugins.js +16 -0
  49. package/dist/model/resource.d.ts +13 -0
  50. package/dist/model/resource.d.ts.map +1 -0
  51. package/dist/model/resource.js +13 -0
  52. package/dist/model/time.d.ts +33 -0
  53. package/dist/model/time.d.ts.map +1 -0
  54. package/dist/model/time.js +53 -0
  55. package/dist/model/variables.d.ts +38 -0
  56. package/dist/model/variables.d.ts.map +1 -0
  57. package/dist/model/variables.js +13 -0
  58. package/dist/utils/fetch.d.ts +18 -0
  59. package/dist/utils/fetch.d.ts.map +1 -0
  60. package/dist/utils/fetch.js +42 -0
  61. package/package.json +28 -0
@@ -0,0 +1,26 @@
1
+ /// <reference types="react" />
2
+ import { useGraphQuery } from '../hooks/graph-query';
3
+ import { useDashboardSpec, useDashboardTimeRange, useDashboardVariables } from '../hooks/dashboard';
4
+ import { useDataSources } from '../hooks/datasource';
5
+ import { usePanelState } from '../hooks/panel';
6
+ /**
7
+ * Hooks exposed to plugins at runtime. This is so we don't have to put
8
+ * implementation details here in core (i.e. a plugin doesn't need to worry
9
+ * about whether these are using Context, Redux, etc).
10
+ */
11
+ export interface PluginRuntime {
12
+ useDashboardSpec: typeof useDashboardSpec;
13
+ useDashboardVariables: typeof useDashboardVariables;
14
+ useDashboardTimeRange: typeof useDashboardTimeRange;
15
+ useDataSources: typeof useDataSources;
16
+ useGraphQuery: typeof useGraphQuery;
17
+ usePanelState: typeof usePanelState;
18
+ }
19
+ export declare const PluginRuntimeContext: import("react").Context<PluginRuntime | undefined>;
20
+ export interface PluginRuntimeProviderProps {
21
+ value: PluginRuntime;
22
+ children: React.ReactNode;
23
+ }
24
+ export declare function PluginRuntimeProvider(props: PluginRuntimeProviderProps): JSX.Element;
25
+ export declare function usePluginRuntime<T extends keyof PluginRuntime>(hook: T): PluginRuntime[T];
26
+ //# sourceMappingURL=PluginRuntimeContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PluginRuntimeContext.d.ts","sourceRoot":"","sources":["../../src/context/PluginRuntimeContext.tsx"],"names":[],"mappings":";AAcA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AACpG,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,gBAAgB,EAAE,OAAO,gBAAgB,CAAC;IAC1C,qBAAqB,EAAE,OAAO,qBAAqB,CAAC;IACpD,qBAAqB,EAAE,OAAO,qBAAqB,CAAC;IACpD,cAAc,EAAE,OAAO,cAAc,CAAC;IACtC,aAAa,EAAE,OAAO,aAAa,CAAC;IACpC,aAAa,EAAE,OAAO,aAAa,CAAC;CACrC;AAED,eAAO,MAAM,oBAAoB,oDAAsD,CAAC;AAExF,MAAM,WAAW,0BAA0B;IACzC,KAAK,EAAE,aAAa,CAAC;IACrB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,0BAA0B,eAStE;AAED,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,aAAa,EAAE,IAAI,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAMzF"}
@@ -0,0 +1,31 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ // Copyright 2021 The Perses Authors
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ import { createContext, useContext, useRef } from 'react';
15
+ export const PluginRuntimeContext = createContext(undefined);
16
+ export function PluginRuntimeProvider(props) {
17
+ // Initialize once, then always pass the same value down so we don't have
18
+ // the possibility of hook implementations changing (i.e. conditional hooks)
19
+ const context = useRef();
20
+ if (context.current === undefined) {
21
+ context.current = props.value;
22
+ }
23
+ return _jsx(PluginRuntimeContext.Provider, { value: context.current, children: props.children }, void 0);
24
+ }
25
+ export function usePluginRuntime(hook) {
26
+ const context = useContext(PluginRuntimeContext);
27
+ if (context === undefined) {
28
+ throw new Error('Could not find ExposeToPlugin context. Did you forget a provider?');
29
+ }
30
+ return context[hook];
31
+ }
@@ -0,0 +1,22 @@
1
+ import { DashboardSpec } from '../model/dashboard';
2
+ import { AbsoluteTimeRange } from '../model/time';
3
+ /**
4
+ * Gets the spec for the current Dashboard.
5
+ */
6
+ export declare function useDashboardSpec(): DashboardSpec;
7
+ /**
8
+ * The value and options for a Dashboard variable.
9
+ */
10
+ export interface VariableState {
11
+ value: string | string[];
12
+ options?: string[];
13
+ }
14
+ /**
15
+ * Gets the variable values and options for the current Dashboard.
16
+ */
17
+ export declare function useDashboardVariables(): Record<string, VariableState>;
18
+ /**
19
+ * Gets the selected time range for the current Dashboard.
20
+ */
21
+ export declare function useDashboardTimeRange(): AbsoluteTimeRange;
22
+ //# sourceMappingURL=dashboard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dashboard.d.ts","sourceRoot":"","sources":["../../src/hooks/dashboard.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAElD;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,aAAa,CAEhD;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAErE;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,iBAAiB,CAEzD"}
@@ -0,0 +1,31 @@
1
+ // Copyright 2021 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 { usePluginRuntime } from '../context/PluginRuntimeContext';
14
+ /**
15
+ * Gets the spec for the current Dashboard.
16
+ */
17
+ export function useDashboardSpec() {
18
+ return usePluginRuntime('useDashboardSpec')();
19
+ }
20
+ /**
21
+ * Gets the variable values and options for the current Dashboard.
22
+ */
23
+ export function useDashboardVariables() {
24
+ return usePluginRuntime('useDashboardVariables')();
25
+ }
26
+ /**
27
+ * Gets the selected time range for the current Dashboard.
28
+ */
29
+ export function useDashboardTimeRange() {
30
+ return usePluginRuntime('useDashboardTimeRange')();
31
+ }
@@ -0,0 +1,5 @@
1
+ import { AnyDatasourceSpecDefinition, DatasourceSpecDefinition, GlobalDatasourceModel } from '../model/datasource';
2
+ import { DatasourceSelector } from '../model/dashboard';
3
+ export declare function useDataSources(selector: DatasourceSelector): GlobalDatasourceModel[];
4
+ export declare function useDataSourceConfig<T extends DatasourceSpecDefinition>(selector: DatasourceSelector, validate: (value: AnyDatasourceSpecDefinition) => value is T): T;
5
+ //# sourceMappingURL=datasource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"datasource.d.ts","sourceRoot":"","sources":["../../src/hooks/datasource.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,2BAA2B,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AACnH,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAExD,wBAAgB,cAAc,CAAC,QAAQ,EAAE,kBAAkB,GAAG,qBAAqB,EAAE,CAEpF;AAED,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,wBAAwB,EACpE,QAAQ,EAAE,kBAAkB,EAC5B,QAAQ,EAAE,CAAC,KAAK,EAAE,2BAA2B,KAAK,KAAK,IAAI,CAAC,GAC3D,CAAC,CAYH"}
@@ -0,0 +1,26 @@
1
+ // Copyright 2021 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 { usePluginRuntime } from '../context/PluginRuntimeContext';
14
+ export function useDataSources(selector) {
15
+ return usePluginRuntime('useDataSources')(selector);
16
+ }
17
+ export function useDataSourceConfig(selector, validate) {
18
+ const datasources = useDataSources(selector);
19
+ if (datasources.length !== 1 || datasources[0] === undefined) {
20
+ throw new Error(`Could not find Datasource for selector ${selector}`);
21
+ }
22
+ if (validate(datasources[0].spec)) {
23
+ return datasources[0].spec;
24
+ }
25
+ throw new Error(`Datasource spec for selector ${selector} is not valid`);
26
+ }
@@ -0,0 +1,4 @@
1
+ import { UseGraphQueryHook } from '../model/graph-query';
2
+ import { JsonObject } from '../model/definitions';
3
+ export declare const useGraphQuery: UseGraphQueryHook<JsonObject>;
4
+ //# sourceMappingURL=graph-query.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph-query.d.ts","sourceRoot":"","sources":["../../src/hooks/graph-query.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,eAAO,MAAM,aAAa,EAAE,iBAAiB,CAAC,UAAU,CAEvD,CAAC"}
@@ -0,0 +1,16 @@
1
+ // Copyright 2021 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 { usePluginRuntime } from '../context/PluginRuntimeContext';
14
+ export const useGraphQuery = (definition) => {
15
+ return usePluginRuntime('useGraphQuery')(definition);
16
+ };
@@ -0,0 +1,13 @@
1
+ import { DependencyList } from 'react';
2
+ /**
3
+ * Like React's useMemo, but guarantees the value will only be recalulated if
4
+ * a dependency changes. Uses strict equality (===) for comparison. (React's
5
+ * useMemo does not offer this guarantee, it's only a performance optimization).
6
+ */
7
+ export declare function useMemoized<T>(factory: () => T, deps: DependencyList): T;
8
+ /**
9
+ * Like React's useMemo, except it does a deep equality comparison with lodash's
10
+ * isEqual on the dependency list.
11
+ */
12
+ export declare function useDeepMemo<T>(factory: () => T, deps: DependencyList): T;
13
+ //# sourceMappingURL=memo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memo.d.ts","sourceRoot":"","sources":["../../src/hooks/memo.ts"],"names":[],"mappings":"AAaA,OAAO,EAAU,cAAc,EAAE,MAAM,OAAO,CAAC;AAQ/C;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,IAAI,EAAE,cAAc,KAgBpE;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,IAAI,EAAE,cAAc,GAAG,CAAC,CAMxE"}
@@ -0,0 +1,45 @@
1
+ // Copyright 2021 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
+ */
20
+ export function useMemoized(factory, deps) {
21
+ var _a;
22
+ const ref = useRef();
23
+ let areEqual = true;
24
+ for (let i = 0; i < deps.length; i++) {
25
+ if (((_a = ref.current) === null || _a === void 0 ? void 0 : _a.deps[i]) !== deps[i]) {
26
+ areEqual = false;
27
+ break;
28
+ }
29
+ }
30
+ if (ref.current === undefined || areEqual === false) {
31
+ ref.current = { value: factory(), deps: deps };
32
+ }
33
+ return ref.current.value;
34
+ }
35
+ /**
36
+ * Like React's useMemo, except it does a deep equality comparison with lodash's
37
+ * isEqual on the dependency list.
38
+ */
39
+ export function useDeepMemo(factory, deps) {
40
+ const ref = useRef();
41
+ if (ref.current === undefined || isEqual(deps, ref.current.deps) === false) {
42
+ ref.current = { value: factory(), deps };
43
+ }
44
+ return ref.current.value;
45
+ }
@@ -0,0 +1,11 @@
1
+ export interface PanelState {
2
+ contentDimensions?: {
3
+ width: number;
4
+ height: number;
5
+ };
6
+ }
7
+ /**
8
+ * Gets the state of the current panel being rendered.
9
+ */
10
+ export declare function usePanelState(): PanelState;
11
+ //# sourceMappingURL=panel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"panel.d.ts","sourceRoot":"","sources":["../../src/hooks/panel.ts"],"names":[],"mappings":"AAeA,MAAM,WAAW,UAAU;IACzB,iBAAiB,CAAC,EAAE;QAClB,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,UAAU,CAE1C"}
@@ -0,0 +1,19 @@
1
+ // Copyright 2021 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 { usePluginRuntime } from '../context/PluginRuntimeContext';
14
+ /**
15
+ * Gets the state of the current panel being rendered.
16
+ */
17
+ export function usePanelState() {
18
+ return usePluginRuntime('usePanelState')();
19
+ }
@@ -0,0 +1,20 @@
1
+ export * from './context/PluginRuntimeContext';
2
+ export * from './hooks/graph-query';
3
+ export * from './hooks/dashboard';
4
+ export * from './hooks/datasource';
5
+ export * from './hooks/memo';
6
+ export * from './hooks/panel';
7
+ export * from './model/graph-query';
8
+ export * from './model/definitions';
9
+ export * from './model/dashboard';
10
+ export * from './model/datasource';
11
+ export * from './model/json-references';
12
+ export * from './model/layout';
13
+ export * from './model/panels';
14
+ export * from './model/plugins';
15
+ export * from './model/resource';
16
+ export * from './model/time';
17
+ export * from './model/variables';
18
+ export * from './model/http';
19
+ export * from './utils/fetch';
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,31 @@
1
+ // Copyright 2021 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 './context/PluginRuntimeContext';
14
+ export * from './hooks/graph-query';
15
+ export * from './hooks/dashboard';
16
+ export * from './hooks/datasource';
17
+ export * from './hooks/memo';
18
+ export * from './hooks/panel';
19
+ export * from './model/graph-query';
20
+ export * from './model/definitions';
21
+ export * from './model/dashboard';
22
+ export * from './model/datasource';
23
+ export * from './model/json-references';
24
+ export * from './model/layout';
25
+ export * from './model/panels';
26
+ export * from './model/plugins';
27
+ export * from './model/resource';
28
+ export * from './model/time';
29
+ export * from './model/variables';
30
+ export * from './model/http';
31
+ export * from './utils/fetch';
@@ -0,0 +1,23 @@
1
+ import { LayoutDefinition } from './layout';
2
+ import { AnyPanelDefinition } from './panels';
3
+ import { ProjectMetadata } from './resource';
4
+ import { AnyVariableDefinition } from './variables';
5
+ import { DurationString } from './time';
6
+ export interface DatasourceSelector {
7
+ name: string;
8
+ kind: string;
9
+ global: boolean;
10
+ }
11
+ export interface DashboardResource {
12
+ kind: 'Dashboard';
13
+ metadata: ProjectMetadata;
14
+ spec: DashboardSpec;
15
+ }
16
+ export interface DashboardSpec {
17
+ datasource: DatasourceSelector;
18
+ duration: DurationString;
19
+ variables: Record<string, AnyVariableDefinition>;
20
+ panels: Record<string, AnyPanelDefinition>;
21
+ layouts: LayoutDefinition[];
22
+ }
23
+ //# sourceMappingURL=dashboard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dashboard.d.ts","sourceRoot":"","sources":["../../src/model/dashboard.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAExC,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,WAAW,CAAC;IAClB,QAAQ,EAAE,eAAe,CAAC;IAC1B,IAAI,EAAE,aAAa,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,kBAAkB,CAAC;IAC/B,QAAQ,EAAE,cAAc,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;IACjD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAC3C,OAAO,EAAE,gBAAgB,EAAE,CAAC;CAC7B"}
@@ -0,0 +1,13 @@
1
+ // Copyright 2021 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 {};
@@ -0,0 +1,17 @@
1
+ import { Metadata, ProjectMetadata } from './resource';
2
+ export interface DatasourceSpecDefinition {
3
+ kind: string;
4
+ default: boolean;
5
+ }
6
+ export declare type AnyDatasourceSpecDefinition = DatasourceSpecDefinition;
7
+ export interface DatasourceModel {
8
+ kind: 'Datasource';
9
+ metadata: ProjectMetadata;
10
+ spec: AnyDatasourceSpecDefinition;
11
+ }
12
+ export interface GlobalDatasourceModel {
13
+ kind: 'GlobalDatasource';
14
+ metadata: Metadata;
15
+ spec: AnyDatasourceSpecDefinition;
16
+ }
17
+ //# sourceMappingURL=datasource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"datasource.d.ts","sourceRoot":"","sources":["../../src/model/datasource.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAGvD,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,oBAAY,2BAA2B,GAAG,wBAAwB,CAAC;AAEnE,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,YAAY,CAAC;IACnB,QAAQ,EAAE,eAAe,CAAC;IAC1B,IAAI,EAAE,2BAA2B,CAAC;CACnC;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,kBAAkB,CAAC;IACzB,QAAQ,EAAE,QAAQ,CAAC;IACnB,IAAI,EAAE,2BAA2B,CAAC;CACnC"}
@@ -0,0 +1,13 @@
1
+ // Copyright 2021 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 {};
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Json config object.
3
+ */
4
+ export interface JsonObject {
5
+ [key: string]: Json | undefined;
6
+ }
7
+ /**
8
+ * Json definition values.
9
+ */
10
+ export declare type Json = string | number | boolean | null | JsonObject | Json[];
11
+ /**
12
+ * Base type for definitions in JSON config resources.
13
+ */
14
+ export interface Definition<Options extends JsonObject> extends JsonObject {
15
+ kind: string;
16
+ options: Options;
17
+ }
18
+ //# sourceMappingURL=definitions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definitions.d.ts","sourceRoot":"","sources":["../../src/model/definitions.ts"],"names":[],"mappings":"AAaA;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;CACjC;AAED;;GAEG;AACH,oBAAY,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,UAAU,GAAG,IAAI,EAAE,CAAC;AAE1E;;GAEG;AACH,MAAM,WAAW,UAAU,CAAC,OAAO,SAAS,UAAU,CAAE,SAAQ,UAAU;IACxE,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;CAClB"}
@@ -0,0 +1,13 @@
1
+ // Copyright 2021 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 {};
@@ -0,0 +1,28 @@
1
+ import { AbsoluteTimeRange, UnixTimeMs } from './time';
2
+ import { Definition, JsonObject } from './definitions';
3
+ import { AnyPluginDefinition, AnyPluginImplementation } from './plugins';
4
+ import { ResourceSelector } from './resource';
5
+ export interface GraphQueryDefinition<Options extends JsonObject> extends Definition<Options> {
6
+ datasource?: ResourceSelector;
7
+ }
8
+ export interface GraphQueryPlugin<Options extends JsonObject> {
9
+ useGraphQuery: UseGraphQueryHook<Options>;
10
+ }
11
+ export declare type UseGraphQueryHook<Options extends JsonObject> = (definition: GraphQueryDefinition<Options>) => {
12
+ data?: GraphData;
13
+ loading: boolean;
14
+ error?: Error;
15
+ };
16
+ export interface GraphData {
17
+ timeRange: AbsoluteTimeRange;
18
+ stepMs: number;
19
+ series: Iterable<GraphSeries>;
20
+ }
21
+ export interface GraphSeries {
22
+ name: string;
23
+ values: Iterable<GraphSeriesValueTuple>;
24
+ }
25
+ export declare type GraphSeriesValueTuple = [timestamp: UnixTimeMs, value: number];
26
+ export declare type AnyGraphQueryDefinition = AnyPluginDefinition<'GraphQuery'>;
27
+ export declare type AnyGraphQueryPlugin = AnyPluginImplementation<'GraphQuery'>;
28
+ //# sourceMappingURL=graph-query.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph-query.d.ts","sourceRoot":"","sources":["../../src/model/graph-query.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AACzE,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,WAAW,oBAAoB,CAAC,OAAO,SAAS,UAAU,CAAE,SAAQ,UAAU,CAAC,OAAO,CAAC;IAC3F,UAAU,CAAC,EAAE,gBAAgB,CAAC;CAC/B;AAED,MAAM,WAAW,gBAAgB,CAAC,OAAO,SAAS,UAAU;IAC1D,aAAa,EAAE,iBAAiB,CAAC,OAAO,CAAC,CAAC;CAC3C;AAED,oBAAY,iBAAiB,CAAC,OAAO,SAAS,UAAU,IAAI,CAAC,UAAU,EAAE,oBAAoB,CAAC,OAAO,CAAC,KAAK;IACzG,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,KAAK,CAAC;CACf,CAAC;AAEF,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,iBAAiB,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;CAC/B;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,QAAQ,CAAC,qBAAqB,CAAC,CAAC;CACzC;AAED,oBAAY,qBAAqB,GAAG,CAAC,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AAE3E,oBAAY,uBAAuB,GAAG,mBAAmB,CAAC,YAAY,CAAC,CAAC;AAExE,oBAAY,mBAAmB,GAAG,uBAAuB,CAAC,YAAY,CAAC,CAAC"}
@@ -0,0 +1,13 @@
1
+ // Copyright 2021 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 {};
@@ -0,0 +1,19 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,15 @@
1
+ // Copyright 2021 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 function buildDatasourceURL(datasourceName, config) {
14
+ return config.access === 'server' ? `/proxy/globaldatasources/${datasourceName}` : config.url;
15
+ }
@@ -0,0 +1,12 @@
1
+ import { DashboardSpec } from './dashboard';
2
+ import { JsonObject } from './definitions';
3
+ export interface PanelRef extends JsonObject {
4
+ $ref: PanelPointer;
5
+ }
6
+ export declare type PanelPointer = `#/panels/${string}`;
7
+ /**
8
+ * Resolve a PanelRef (JSON reference) against the provided DashboardSpec to
9
+ * a PanelDefinition.
10
+ */
11
+ export declare function resolvePanelRef(spec: DashboardSpec, panelRef: PanelRef): import("./panels").PanelDefinition<JsonObject>;
12
+ //# sourceMappingURL=json-references.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-references.d.ts","sourceRoot":"","sources":["../../src/model/json-references.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,MAAM,WAAW,QAAS,SAAQ,UAAU;IAC1C,IAAI,EAAE,YAAY,CAAC;CACpB;AAED,oBAAY,YAAY,GAAG,YAAY,MAAM,EAAE,CAAC;AAEhD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,kDAOtE"}
@@ -0,0 +1,24 @@
1
+ // Copyright 2021 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
+ */
17
+ export function resolvePanelRef(spec, panelRef) {
18
+ const panelsKey = panelRef.$ref.substring(9);
19
+ const panelDefinition = spec.panels[panelsKey];
20
+ if (panelDefinition === undefined) {
21
+ throw new Error(`Could not resolve panels reference ${panelRef.$ref}`);
22
+ }
23
+ return panelDefinition;
24
+ }
@@ -0,0 +1,20 @@
1
+ import { PanelRef } from './json-references';
2
+ export declare type LayoutDefinition = GridDefinition;
3
+ export interface GridDefinition {
4
+ kind: 'Grid';
5
+ display?: {
6
+ title: string;
7
+ collapse?: {
8
+ open: boolean;
9
+ };
10
+ };
11
+ items: GridItemDefinition[];
12
+ }
13
+ export interface GridItemDefinition {
14
+ x: number;
15
+ y: number;
16
+ width: number;
17
+ height: number;
18
+ content: PanelRef;
19
+ }
20
+ //# sourceMappingURL=layout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../../src/model/layout.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,oBAAY,gBAAgB,GAAG,cAAc,CAAC;AAE9C,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE;QACR,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,CAAC,EAAE;YACT,IAAI,EAAE,OAAO,CAAC;SACf,CAAC;KACH,CAAC;IACF,KAAK,EAAE,kBAAkB,EAAE,CAAC;CAC7B;AAED,MAAM,WAAW,kBAAkB;IACjC,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,QAAQ,CAAC;CACnB"}
@@ -0,0 +1,13 @@
1
+ // Copyright 2021 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 {};
@@ -0,0 +1,21 @@
1
+ /// <reference types="react" />
2
+ import { Definition, JsonObject } from './definitions';
3
+ import { AnyPluginDefinition, AnyPluginImplementation } from './plugins';
4
+ export interface PanelDefinition<Options extends JsonObject> extends Definition<Options> {
5
+ display: {
6
+ name: string;
7
+ };
8
+ }
9
+ /**
10
+ * Plugin the provides custom visualizations inside of a Panel.
11
+ */
12
+ export interface PanelPlugin<Options extends JsonObject> {
13
+ PanelComponent: PanelComponent<Options>;
14
+ }
15
+ export declare type PanelComponent<Options extends JsonObject> = React.ComponentType<PanelProps<Options>>;
16
+ export interface PanelProps<Options extends JsonObject> {
17
+ definition: PanelDefinition<Options>;
18
+ }
19
+ export declare type AnyPanelDefinition = AnyPluginDefinition<'Panel'>;
20
+ export declare type AnyPanelPlugin = AnyPluginImplementation<'Panel'>;
21
+ //# sourceMappingURL=panels.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"panels.d.ts","sourceRoot":"","sources":["../../src/model/panels.ts"],"names":[],"mappings":";AAaA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AAEzE,MAAM,WAAW,eAAe,CAAC,OAAO,SAAS,UAAU,CAAE,SAAQ,UAAU,CAAC,OAAO,CAAC;IACtF,OAAO,EAAE;QACP,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,OAAO,SAAS,UAAU;IACrD,cAAc,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC;CACzC;AAED,oBAAY,cAAc,CAAC,OAAO,SAAS,UAAU,IAAI,KAAK,CAAC,aAAa,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;AAElG,MAAM,WAAW,UAAU,CAAC,OAAO,SAAS,UAAU;IACpD,UAAU,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC;CACtC;AAED,oBAAY,kBAAkB,GAAG,mBAAmB,CAAC,OAAO,CAAC,CAAC;AAE9D,oBAAY,cAAc,GAAG,uBAAuB,CAAC,OAAO,CAAC,CAAC"}
@@ -0,0 +1,13 @@
1
+ // Copyright 2021 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 {};
@@ -0,0 +1,87 @@
1
+ import { GraphQueryDefinition, GraphQueryPlugin } from './graph-query';
2
+ import { JsonObject } from './definitions';
3
+ import { PanelDefinition, PanelPlugin } from './panels';
4
+ import { ResourceMetadata } from './resource';
5
+ import { VariableDefinition, VariablePlugin } from './variables';
6
+ export interface PluginResource {
7
+ kind: 'Plugin';
8
+ metadata: ResourceMetadata;
9
+ spec: PluginSpec;
10
+ }
11
+ export interface PluginSpec {
12
+ supported_kinds: Record<string, PluginType>;
13
+ plugin_module_path: string;
14
+ }
15
+ /**
16
+ * A JavaScript module with Perses plugins.
17
+ */
18
+ export interface PluginModule {
19
+ setup: PluginSetupFunction;
20
+ }
21
+ /**
22
+ * When a PluginModule is loaded, this function is called to allow the module
23
+ * to register plugins with Perses.
24
+ */
25
+ export declare type PluginSetupFunction = (registerPlugin: RegisterPlugin) => void;
26
+ /**
27
+ * Callback function that registers a plugin with Perses.
28
+ */
29
+ export declare type RegisterPlugin = <Options extends JsonObject>(config: PluginRegistrationConfig<Options>) => void;
30
+ /**
31
+ * All supported plugin type values as an array for use at runtime.
32
+ */
33
+ export declare const ALL_PLUGIN_TYPES: readonly ["Variable", "Panel", "GraphQuery"];
34
+ /**
35
+ * All supported plugin types.
36
+ */
37
+ export declare type PluginType = typeof ALL_PLUGIN_TYPES[number];
38
+ declare type SupportedPlugins<Options extends JsonObject> = {
39
+ Variable: {
40
+ Def: VariableDefinition<Options>;
41
+ Impl: VariablePlugin<Options>;
42
+ };
43
+ Panel: {
44
+ Def: PanelDefinition<Options>;
45
+ Impl: PanelPlugin<Options>;
46
+ };
47
+ GraphQuery: {
48
+ Def: GraphQueryDefinition<Options>;
49
+ Impl: GraphQueryPlugin<Options>;
50
+ };
51
+ };
52
+ /**
53
+ * The definition handled for a given plugin type.
54
+ */
55
+ export declare type PluginDefinition<Type extends PluginType, Options extends JsonObject> = SupportedPlugins<Options>[Type]['Def'];
56
+ /**
57
+ * The implementation for a given plugin type.
58
+ */
59
+ export declare type PluginImplementation<Type extends PluginType, Options extends JsonObject> = SupportedPlugins<Options>[Type]['Impl'];
60
+ /**
61
+ * Configuration (including the plugin implementation) that's expected when
62
+ * registering a plugin with Perses.
63
+ */
64
+ export declare type PluginRegistrationConfig<Options extends JsonObject> = {
65
+ [Type in PluginType]: PluginConfig<Type, Options>;
66
+ }[PluginType];
67
+ /**
68
+ * Configuration expected for a particular plugin type.
69
+ */
70
+ export declare type PluginConfig<Type extends PluginType, Options extends JsonObject> = {
71
+ pluginType: Type;
72
+ kind: string;
73
+ validate?: (config: AnyPluginDefinition<Type>) => string[];
74
+ plugin: PluginImplementation<Type, Options>;
75
+ };
76
+ /**
77
+ * A PluginDefinition at runtime where we know the plugin type, but not the
78
+ * specific Kind/Options that it handles.
79
+ */
80
+ export declare type AnyPluginDefinition<Type extends PluginType> = PluginDefinition<Type, JsonObject>;
81
+ /**
82
+ * A PluginImplementation at runtime where we know the plugin type, but not the
83
+ * specific Kind/Options that it handles.
84
+ */
85
+ export declare type AnyPluginImplementation<Type extends PluginType> = PluginImplementation<Type, JsonObject>;
86
+ export {};
87
+ //# sourceMappingURL=plugins.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugins.d.ts","sourceRoot":"","sources":["../../src/model/plugins.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAEjE,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,QAAQ,CAAC;IACf,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,IAAI,EAAE,UAAU,CAAC;CAClB;AAED,MAAM,WAAW,UAAU;IACzB,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAE5C,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,mBAAmB,CAAC;CAC5B;AAED;;;GAGG;AACH,oBAAY,mBAAmB,GAAG,CAAC,cAAc,EAAE,cAAc,KAAK,IAAI,CAAC;AAE3E;;GAEG;AACH,oBAAY,cAAc,GAAG,CAAC,OAAO,SAAS,UAAU,EAAE,MAAM,EAAE,wBAAwB,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC;AAE7G;;GAEG;AACH,eAAO,MAAM,gBAAgB,8CAA+C,CAAC;AAE7E;;GAEG;AACH,oBAAY,UAAU,GAAG,OAAO,gBAAgB,CAAC,MAAM,CAAC,CAAC;AAGzD,aAAK,gBAAgB,CAAC,OAAO,SAAS,UAAU,IAAI;IAClD,QAAQ,EAAE;QACR,GAAG,EAAE,kBAAkB,CAAC,OAAO,CAAC,CAAC;QACjC,IAAI,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC;KAC/B,CAAC;IACF,KAAK,EAAE;QACL,GAAG,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC;QAC9B,IAAI,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;KAC5B,CAAC;IACF,UAAU,EAAE;QACV,GAAG,EAAE,oBAAoB,CAAC,OAAO,CAAC,CAAC;QACnC,IAAI,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC;KACjC,CAAC;CACH,CAAC;AAEF;;GAEG;AACH,oBAAY,gBAAgB,CAC1B,IAAI,SAAS,UAAU,EACvB,OAAO,SAAS,UAAU,IACxB,gBAAgB,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC;AAE3C;;GAEG;AACH,oBAAY,oBAAoB,CAC9B,IAAI,SAAS,UAAU,EACvB,OAAO,SAAS,UAAU,IACxB,gBAAgB,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC;AAE5C;;;GAGG;AACH,oBAAY,wBAAwB,CAAC,OAAO,SAAS,UAAU,IAAI;KAChE,IAAI,IAAI,UAAU,GAAG,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC;CAClD,CAAC,UAAU,CAAC,CAAC;AAEd;;GAEG;AACH,oBAAY,YAAY,CAAC,IAAI,SAAS,UAAU,EAAE,OAAO,SAAS,UAAU,IAAI;IAC9E,UAAU,EAAE,IAAI,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,mBAAmB,CAAC,IAAI,CAAC,KAAK,MAAM,EAAE,CAAC;IAC3D,MAAM,EAAE,oBAAoB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;CAC7C,CAAC;AAEF;;;GAGG;AACH,oBAAY,mBAAmB,CAAC,IAAI,SAAS,UAAU,IAAI,gBAAgB,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;AAE9F;;;GAGG;AACH,oBAAY,uBAAuB,CAAC,IAAI,SAAS,UAAU,IAAI,oBAAoB,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC"}
@@ -0,0 +1,16 @@
1
+ // Copyright 2021 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
+ * All supported plugin type values as an array for use at runtime.
15
+ */
16
+ export const ALL_PLUGIN_TYPES = ['Variable', 'Panel', 'GraphQuery'];
@@ -0,0 +1,13 @@
1
+ export declare type ResourceSelector = Record<string, string>;
2
+ export declare type ResourceMetadata = Record<string, string> & {
3
+ name: string;
4
+ };
5
+ export declare type Metadata = {
6
+ name: string;
7
+ created_at: string;
8
+ updated_at: string;
9
+ };
10
+ export declare type ProjectMetadata = Metadata & {
11
+ project: string;
12
+ };
13
+ //# sourceMappingURL=resource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../../src/model/resource.ts"],"names":[],"mappings":"AAaA,oBAAY,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAItD,oBAAY,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEzE,oBAAY,QAAQ,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,oBAAY,eAAe,GAAG,QAAQ,GAAG;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC"}
@@ -0,0 +1,13 @@
1
+ // Copyright 2021 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 {};
@@ -0,0 +1,33 @@
1
+ import { Duration } from 'date-fns';
2
+ export declare type UnixTimeMs = number;
3
+ export interface AbsoluteTimeRange {
4
+ start: Date;
5
+ end: Date;
6
+ }
7
+ export interface RelativeTimeRange {
8
+ end?: Date;
9
+ pastDuration: DurationString;
10
+ }
11
+ /**
12
+ * Returns an absolute time range from a RelativeTimeRange.
13
+ */
14
+ export declare function toAbsoluteTimeRange(timeRange: RelativeTimeRange): AbsoluteTimeRange;
15
+ declare type MillisecondsDurationString = `${number}ms`;
16
+ declare type SecondsDurationString = `${number}s`;
17
+ declare type MinutesDurationString = `${number}m`;
18
+ declare type HoursDurationString = `${number}h`;
19
+ declare type DaysDurationString = `${number}d`;
20
+ declare type WeeksDurationString = `${number}w`;
21
+ declare type YearsDurationString = `${number}y`;
22
+ export declare type DurationString = Exclude<`${YearsDurationString | ''}${WeeksDurationString | ''}${DaysDurationString | ''}${HoursDurationString | ''}${MinutesDurationString | ''}${SecondsDurationString | ''}${MillisecondsDurationString | ''}`, ''>;
23
+ /**
24
+ * Parses a DurationString into a Duration object with numeric values that can
25
+ * be used to do Date math. Throws if not a valid duration string.
26
+ */
27
+ export declare function parseDurationString(durationString: string): Duration;
28
+ /**
29
+ * Returns true if the given string is a valid DurationString.
30
+ */
31
+ export declare function isDurationString(maybeDuration: string): maybeDuration is DurationString;
32
+ export {};
33
+ //# sourceMappingURL=time.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../src/model/time.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,QAAQ,EAAO,MAAM,UAAU,CAAC;AAEzC,oBAAY,UAAU,GAAG,MAAM,CAAC;AAEhC,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,IAAI,CAAC;IACZ,GAAG,EAAE,IAAI,CAAC;CACX;AAED,MAAM,WAAW,iBAAiB;IAEhC,GAAG,CAAC,EAAE,IAAI,CAAC;IACX,YAAY,EAAE,cAAc,CAAC;CAC9B;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,iBAAiB,GAAG,iBAAiB,CAOnF;AAED,aAAK,0BAA0B,GAAG,GAAG,MAAM,IAAI,CAAC;AAChD,aAAK,qBAAqB,GAAG,GAAG,MAAM,GAAG,CAAC;AAC1C,aAAK,qBAAqB,GAAG,GAAG,MAAM,GAAG,CAAC;AAC1C,aAAK,mBAAmB,GAAG,GAAG,MAAM,GAAG,CAAC;AACxC,aAAK,kBAAkB,GAAG,GAAG,MAAM,GAAG,CAAC;AACvC,aAAK,mBAAmB,GAAG,GAAG,MAAM,GAAG,CAAC;AACxC,aAAK,mBAAmB,GAAG,GAAG,MAAM,GAAG,CAAC;AAExC,oBAAY,cAAc,GAAG,OAAO,CAClC,GAAG,mBAAmB,GAAG,EAAE,GAAG,mBAAmB,GAAG,EAAE,GAAG,kBAAkB,GAAG,EAAE,GAAG,mBAAmB,GAAG,EAAE,GACvG,qBAAqB,GACrB,EAAE,GAAG,qBAAqB,GAAG,EAAE,GAAG,0BAA0B,GAAG,EAAE,EAAE,EACvE,EAAE,CACH,CAAC;AAIF;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,cAAc,EAAE,MAAM,GAAG,QAAQ,CAepE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,aAAa,EAAE,MAAM,GAAG,aAAa,IAAI,cAAc,CAGvF"}
@@ -0,0 +1,53 @@
1
+ // Copyright 2021 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 { sub } from 'date-fns';
14
+ /**
15
+ * Returns an absolute time range from a RelativeTimeRange.
16
+ */
17
+ export function toAbsoluteTimeRange(timeRange) {
18
+ var _a;
19
+ const end = (_a = timeRange.end) !== null && _a !== void 0 ? _a : new Date();
20
+ return {
21
+ start: sub(end, parseDurationString(timeRange.pastDuration)),
22
+ end,
23
+ };
24
+ }
25
+ const DURATION_REGEX = /^(?:(\d+)y)?(?:(\d+)w)?(?:(\d+)d)?(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s)?(?:(\d+)ms)?$/;
26
+ /**
27
+ * Parses a DurationString into a Duration object with numeric values that can
28
+ * be used to do Date math. Throws if not a valid duration string.
29
+ */
30
+ export function parseDurationString(durationString) {
31
+ var _a, _b, _c, _d, _e, _f, _g;
32
+ const matches = DURATION_REGEX.exec(durationString);
33
+ if (matches === null) {
34
+ throw new Error(`Invalid duration string '${durationString}'`);
35
+ }
36
+ return {
37
+ years: parseInt((_a = matches[1]) !== null && _a !== void 0 ? _a : '0'),
38
+ months: 0,
39
+ weeks: parseInt((_b = matches[2]) !== null && _b !== void 0 ? _b : '0'),
40
+ days: parseInt((_c = matches[3]) !== null && _c !== void 0 ? _c : '0'),
41
+ hours: parseInt((_d = matches[4]) !== null && _d !== void 0 ? _d : '0'),
42
+ minutes: parseInt((_e = matches[5]) !== null && _e !== void 0 ? _e : '0'),
43
+ seconds: parseInt((_f = matches[6]) !== null && _f !== void 0 ? _f : '0') + parseInt((_g = matches[7]) !== null && _g !== void 0 ? _g : '0') / 1000,
44
+ };
45
+ }
46
+ /**
47
+ * Returns true if the given string is a valid DurationString.
48
+ */
49
+ export function isDurationString(maybeDuration) {
50
+ if (maybeDuration === '')
51
+ return false;
52
+ return DURATION_REGEX.test(maybeDuration);
53
+ }
@@ -0,0 +1,38 @@
1
+ import { Definition, JsonObject } from './definitions';
2
+ import { AnyPluginDefinition, AnyPluginImplementation } from './plugins';
3
+ export interface VariableDefinition<Options extends JsonObject> extends Definition<Options> {
4
+ display: VariableDisplayOptions;
5
+ selection: VariableSelectionOptions;
6
+ capturing_regexp?: string;
7
+ }
8
+ export interface VariableDisplayOptions extends JsonObject {
9
+ hide?: boolean;
10
+ label: string;
11
+ }
12
+ export declare type VariableSelectionOptions = SingleSelectOptions | MultiSelectOptions;
13
+ export declare type SingleSelectOptions = {
14
+ default_value: string;
15
+ };
16
+ export declare type MultiSelectOptions = {
17
+ default_value: string[];
18
+ all_value?: string | typeof DEFAULT_ALL_VALUE;
19
+ };
20
+ export declare const DEFAULT_ALL_VALUE: "$__all";
21
+ /**
22
+ * Plugin for handling custom VariableDefinitions.
23
+ */
24
+ export interface VariablePlugin<Options extends JsonObject> {
25
+ useVariableOptions: UseVariableOptionsHook<Options>;
26
+ }
27
+ /**
28
+ * Plugin hook responsible for getting the options of a custom variable
29
+ * definition.
30
+ */
31
+ export declare type UseVariableOptionsHook<Options extends JsonObject> = (definition: VariableDefinition<Options>) => {
32
+ data: string[];
33
+ loading: boolean;
34
+ error?: Error;
35
+ };
36
+ export declare type AnyVariableDefinition = AnyPluginDefinition<'Variable'>;
37
+ export declare type AnyVariablePlugin = AnyPluginImplementation<'Variable'>;
38
+ //# sourceMappingURL=variables.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"variables.d.ts","sourceRoot":"","sources":["../../src/model/variables.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AAEzE,MAAM,WAAW,kBAAkB,CAAC,OAAO,SAAS,UAAU,CAAE,SAAQ,UAAU,CAAC,OAAO,CAAC;IACzF,OAAO,EAAE,sBAAsB,CAAC;IAChC,SAAS,EAAE,wBAAwB,CAAC;IACpC,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,sBAAuB,SAAQ,UAAU;IACxD,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf;AAED,oBAAY,wBAAwB,GAAG,mBAAmB,GAAG,kBAAkB,CAAC;AAEhF,oBAAY,mBAAmB,GAAG;IAChC,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,oBAAY,kBAAkB,GAAG;IAC/B,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,iBAAiB,CAAC;CAC/C,CAAC;AAEF,eAAO,MAAM,iBAAiB,UAAoB,CAAC;AAEnD;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,OAAO,SAAS,UAAU;IACxD,kBAAkB,EAAE,sBAAsB,CAAC,OAAO,CAAC,CAAC;CACrD;AAED;;;GAGG;AACH,oBAAY,sBAAsB,CAAC,OAAO,SAAS,UAAU,IAAI,CAAC,UAAU,EAAE,kBAAkB,CAAC,OAAO,CAAC,KAAK;IAC5G,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,KAAK,CAAC;CACf,CAAC;AAEF,oBAAY,qBAAqB,GAAG,mBAAmB,CAAC,UAAU,CAAC,CAAC;AAEpE,oBAAY,iBAAiB,GAAG,uBAAuB,CAAC,UAAU,CAAC,CAAC"}
@@ -0,0 +1,13 @@
1
+ // Copyright 2021 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 const DEFAULT_ALL_VALUE = '$__all';
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Calls `global.fetch`, but throws a `FetchError` for non-200 responses.
3
+ */
4
+ export declare function fetch(...args: Parameters<typeof global.fetch>): Promise<Response>;
5
+ /**
6
+ * Calls `global.fetch` and throws a `FetchError` on non-200 responses, but also
7
+ * decodes the response body as JSON, casting it to type `T`. Returns the
8
+ * decoded body.
9
+ */
10
+ export declare function fetchJson<T>(...args: Parameters<typeof global.fetch>): Promise<T>;
11
+ /**
12
+ * Error thrown when fetch returns a non-200 response.
13
+ */
14
+ export declare class FetchError extends Error {
15
+ readonly response: Response;
16
+ constructor(response: Response);
17
+ }
18
+ //# sourceMappingURL=fetch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/utils/fetch.ts"],"names":[],"mappings":"AAaA;;GAEG;AACH,wBAAsB,KAAK,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,MAAM,CAAC,KAAK,CAAC,qBAMnE;AAED;;;;GAIG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,MAAM,CAAC,KAAK,CAAC,cAI1E;AAED;;GAEG;AACH,qBAAa,UAAW,SAAQ,KAAK;IACvB,QAAQ,CAAC,QAAQ,EAAE,QAAQ;gBAAlB,QAAQ,EAAE,QAAQ;CAIxC"}
@@ -0,0 +1,42 @@
1
+ // Copyright 2021 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
+ */
16
+ export async function fetch(...args) {
17
+ const response = await global.fetch(...args);
18
+ if (response.ok === false) {
19
+ throw new FetchError(response);
20
+ }
21
+ return response;
22
+ }
23
+ /**
24
+ * Calls `global.fetch` and throws a `FetchError` on non-200 responses, but also
25
+ * decodes the response body as JSON, casting it to type `T`. Returns the
26
+ * decoded body.
27
+ */
28
+ export async function fetchJson(...args) {
29
+ const response = await fetch(...args);
30
+ const json = await response.json();
31
+ return json;
32
+ }
33
+ /**
34
+ * Error thrown when fetch returns a non-200 response.
35
+ */
36
+ export class FetchError extends Error {
37
+ constructor(response) {
38
+ super(`${response.status} ${response.statusText}`);
39
+ this.response = response;
40
+ Object.setPrototypeOf(this, FetchError.prototype);
41
+ }
42
+ }
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@perses-dev/core",
3
+ "version": "0.1.0",
4
+ "description": "Core functionality consumed by both the Perses UI and plugins",
5
+ "module": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "clean": "rimraf dist/",
9
+ "build": "tsc",
10
+ "test": "echo 'no test to run' && exit 0",
11
+ "lint": "eslint src --ext .ts,.tsx",
12
+ "lint:fix": "eslint --fix src --ext .ts,.tsx"
13
+ },
14
+ "dependencies": {
15
+ "date-fns": "^2.28.0",
16
+ "lodash-es": "^4.17.21"
17
+ },
18
+ "peerDependencies": {
19
+ "react": "^17.0.2"
20
+ },
21
+ "devDependencies": {
22
+ "@types/lodash-es": "^4.17.5"
23
+ },
24
+ "license": "Apache-2.0",
25
+ "files": [
26
+ "dist"
27
+ ]
28
+ }