@modelform/react-native 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +103 -2
- package/dist/chunk-L4SQVIJV.js +10630 -0
- package/dist/chunk-PIHXMZ4G.mjs +10630 -0
- package/dist/core/configSchema.d.ts +29 -0
- package/dist/core/dashboardSettings.d.ts +34 -0
- package/dist/core/datasource.d.ts +61 -0
- package/dist/core/documents.d.ts +35 -0
- package/dist/core/editing.d.ts +129 -0
- package/dist/core/fieldconfig.d.ts +12 -0
- package/dist/core/format.d.ts +29 -0
- package/dist/core/frame.d.ts +51 -0
- package/dist/core/gazetteer.d.ts +25 -0
- package/dist/core/grafana.d.ts +85 -0
- package/dist/core/index.d.ts +27 -0
- package/dist/core/index.js +380 -0
- package/dist/core/index.mjs +380 -0
- package/dist/core/inputs.d.ts +99 -0
- package/dist/core/jsonEdit.d.ts +30 -0
- package/dist/core/layout.d.ts +49 -0
- package/dist/core/layoutEdit.d.ts +87 -0
- package/dist/core/links.d.ts +56 -0
- package/dist/core/local.d.ts +95 -0
- package/dist/core/manifest.d.ts +201 -0
- package/dist/core/mappings.d.ts +46 -0
- package/dist/core/navigation.d.ts +19 -0
- package/dist/core/panelOptions.d.ts +109 -0
- package/dist/core/reduce.d.ts +6 -0
- package/dist/core/resolveVariables.d.ts +38 -0
- package/dist/core/sample.d.ts +13 -0
- package/dist/core/schema.d.ts +202 -0
- package/dist/core/time.d.ts +66 -0
- package/dist/core/transform.d.ts +12 -0
- package/dist/core/variables.d.ts +76 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +4156 -0
- package/dist/index.mjs +4156 -0
- package/dist/ui/Chip.d.ts +5 -0
- package/dist/ui/DashboardView.d.ts +22 -0
- package/dist/ui/RenderBoundary.d.ts +25 -0
- package/dist/ui/TimeRangeSheet.d.ts +24 -0
- package/dist/ui/Toolbar.d.ts +6 -0
- package/dist/ui/chart.d.ts +69 -0
- package/dist/ui/context.d.ts +68 -0
- package/dist/ui/geomap.d.ts +157 -0
- package/dist/ui/inputs/InputForm.d.ts +36 -0
- package/dist/ui/inputs/InputPanels.d.ts +4 -0
- package/dist/ui/inputs/formContext.d.ts +14 -0
- package/dist/ui/links.d.ts +28 -0
- package/dist/ui/panels/GaugePanels.d.ts +5 -0
- package/dist/ui/panels/GeomapPanel.d.ts +6 -0
- package/dist/ui/panels/OtherPanels.d.ts +18 -0
- package/dist/ui/panels/StatPanel.d.ts +14 -0
- package/dist/ui/panels/TimeSeriesPanel.d.ts +8 -0
- package/dist/ui/panels/XYChartPanel.d.ts +6 -0
- package/dist/ui/panels/common.d.ts +78 -0
- package/dist/ui/panels/registry.d.ts +5 -0
- package/dist/ui/table.d.ts +62 -0
- package/dist/ui/theme.d.ts +21 -0
- package/dist/ui/xychart.d.ts +27 -0
- package/package.json +89 -3
- package/schema/app.schema.json +184 -0
- package/schema/dashboard.schema.json +940 -0
- package/tools/dashboards.js +90 -0
- package/tools/metro.js +21 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export declare const appSchema: object;
|
|
2
|
+
export declare const dashboardSchema: object;
|
|
3
|
+
export interface SchemaIssue {
|
|
4
|
+
/** Like `tabs[0].screen.forms`, or `(root)`. */
|
|
5
|
+
path: string;
|
|
6
|
+
message: string;
|
|
7
|
+
}
|
|
8
|
+
/** `/tabs/0/screen` → `tabs[0].screen` */
|
|
9
|
+
export declare function pointerToPath(pointer: string): string;
|
|
10
|
+
/** Problems with an app manifest, per schema/app.schema.json. */
|
|
11
|
+
export declare const manifestSchemaIssues: (json: unknown) => SchemaIssue[];
|
|
12
|
+
/** Problems with a dashboard or form, per schema/dashboard.schema.json. */
|
|
13
|
+
export declare const dashboardSchemaIssues: (json: unknown) => SchemaIssue[];
|
|
14
|
+
export interface RemovedValue {
|
|
15
|
+
/** Like `panels[0].title`. */
|
|
16
|
+
path: string;
|
|
17
|
+
/** Why, e.g. "must be string". */
|
|
18
|
+
message: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A copy of a dashboard without the values that don't fit the schema: anything of the wrong
|
|
22
|
+
* type or out of range is removed, so the renderer only ever sees what it was written for, and
|
|
23
|
+
* an object left without something it requires goes too. Unknown keys stay (they're ignored),
|
|
24
|
+
* and so do objects that were missing a required key to begin with, as Grafana exports often are.
|
|
25
|
+
*/
|
|
26
|
+
export declare function cleanDashboard<T>(json: T): {
|
|
27
|
+
value: T;
|
|
28
|
+
removed: RemovedValue[];
|
|
29
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Editing a dashboard's settings: its time options and its template variables, written the
|
|
3
|
+
* way Grafana writes them so the JSON stays importable there.
|
|
4
|
+
*/
|
|
5
|
+
import type { Dashboard, Panel, TemplateVariable } from './schema';
|
|
6
|
+
/** Auto-refresh intervals to offer; "" is off. */
|
|
7
|
+
export declare const REFRESH_CHOICES: string[];
|
|
8
|
+
/** Variable types an editor can set up without a datasource to query. */
|
|
9
|
+
export declare const EDITABLE_VARIABLE_TYPES: readonly ["custom", "interval", "textbox", "constant"];
|
|
10
|
+
export type EditableVariableType = (typeof EDITABLE_VARIABLE_TYPES)[number];
|
|
11
|
+
export declare const isEditableVariableType: (type: string) => type is EditableVariableType;
|
|
12
|
+
/** Why `name` can't be a variable's name, or null if it can. `others` are the other variables' names. */
|
|
13
|
+
export declare function variableNameError(name: string, others: string[]): string | null;
|
|
14
|
+
/** A new variable of `type`, named so it doesn't clash with `taken`. */
|
|
15
|
+
export declare function newVariable(type: EditableVariableType, taken: string[]): TemplateVariable;
|
|
16
|
+
/** The variable as `type`, keeping its name, label and visibility and starting the rest afresh. */
|
|
17
|
+
export declare function variableWithType(v: TemplateVariable, type: EditableVariableType): TemplateVariable;
|
|
18
|
+
/**
|
|
19
|
+
* The variable with a new query: custom and interval options, a textbox's default or a
|
|
20
|
+
* constant's value. The selection is kept where it's still an option, as Grafana does; saved
|
|
21
|
+
* `options` are dropped, since they'd override the query.
|
|
22
|
+
*/
|
|
23
|
+
export declare function variableWithQuery(v: TemplateVariable, query: string): TemplateVariable;
|
|
24
|
+
/** The variable with `value` selected by default. */
|
|
25
|
+
export declare function variableWithCurrent(v: TemplateVariable, value: string | string[]): TemplateVariable;
|
|
26
|
+
/** The variable with multi-value or All turned on or off, its selection adjusted to suit. */
|
|
27
|
+
export declare function variableWithFlags(v: TemplateVariable, flags: {
|
|
28
|
+
multi?: boolean;
|
|
29
|
+
includeAll?: boolean;
|
|
30
|
+
}): TemplateVariable;
|
|
31
|
+
/** Titles of the panels that use variable `name`: in a query, a title, options, or repeating by it. */
|
|
32
|
+
export declare function variableUses(dashboard: Dashboard, name: string): string[];
|
|
33
|
+
/** Panels with every use of variable `from` (references and repeats) changed to `to`. */
|
|
34
|
+
export declare function renameVariableInPanels(panels: Panel[], from: string, to: string): Panel[];
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { DataFrame } from './frame';
|
|
2
|
+
import type { Dashboard, DataSourceRef, Panel, Target } from './schema';
|
|
3
|
+
import type { TimeRange } from './time';
|
|
4
|
+
import { type VariableInfo, type VariableValues, type VarOption } from './variables';
|
|
5
|
+
export interface QueryRequest {
|
|
6
|
+
/** Already interpolated; `datasource` is filled in on every target. */
|
|
7
|
+
targets: (Target & {
|
|
8
|
+
datasource?: DataSourceRef;
|
|
9
|
+
})[];
|
|
10
|
+
range: TimeRange;
|
|
11
|
+
intervalMs: number;
|
|
12
|
+
maxDataPoints: number;
|
|
13
|
+
}
|
|
14
|
+
export interface VariableQueryRequest {
|
|
15
|
+
/** The variable's `query`, already interpolated. */
|
|
16
|
+
query: unknown;
|
|
17
|
+
datasource?: DataSourceRef;
|
|
18
|
+
range: TimeRange;
|
|
19
|
+
}
|
|
20
|
+
export interface DataSource {
|
|
21
|
+
query(request: QueryRequest, signal?: AbortSignal): Promise<DataFrame[]>;
|
|
22
|
+
/**
|
|
23
|
+
* Options for a `query` variable, or null when this datasource can't run that kind of variable
|
|
24
|
+
* query (the variable then keeps the options saved in the dashboard JSON).
|
|
25
|
+
*/
|
|
26
|
+
variableOptions?(request: VariableQueryRequest, signal?: AbortSignal): Promise<VarOption[] | null>;
|
|
27
|
+
/**
|
|
28
|
+
* A JSON file the Grafana behind this datasource serves, by path such as `public/gazetteer/countries.json`.
|
|
29
|
+
* Geomap lookup layers load gazetteers with it.
|
|
30
|
+
*/
|
|
31
|
+
publicFile?(path: string, signal?: AbortSignal): Promise<unknown>;
|
|
32
|
+
}
|
|
33
|
+
/** Maps a panel/target datasource reference to the implementation that serves it. */
|
|
34
|
+
export type DataSourceResolver = (ref: DataSourceRef | undefined) => DataSource;
|
|
35
|
+
export interface PanelQueryContext {
|
|
36
|
+
resolve: DataSourceResolver;
|
|
37
|
+
range: TimeRange;
|
|
38
|
+
variables: VariableValues;
|
|
39
|
+
/** Options and multi/All settings per variable; needed to expand All. See variableInfo(). */
|
|
40
|
+
variableInfo?: Record<string, VariableInfo>;
|
|
41
|
+
/** Rendered width in px; Grafana uses this as the default maxDataPoints. */
|
|
42
|
+
widthPx: number;
|
|
43
|
+
/** Where `-- Dashboard --` queries find the panel they reuse. Its `timezone` also sets `$__timezone`. */
|
|
44
|
+
dashboard?: Dashboard;
|
|
45
|
+
/** Overrides the dashboard's `timezone` for `$__timezone`. */
|
|
46
|
+
timezone?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Results shared between a panel and the `-- Dashboard --` panels that reuse it, by panelKey, so
|
|
49
|
+
* the query runs once. Replace the map whenever the range or variables change.
|
|
50
|
+
*/
|
|
51
|
+
shared?: Map<string, Promise<DataFrame[]>>;
|
|
52
|
+
}
|
|
53
|
+
/** Grafana's datasource that reuses another panel's results instead of querying. */
|
|
54
|
+
export declare const DASHBOARD_DS = "-- Dashboard --";
|
|
55
|
+
/** Ids of the panels whose results a `-- Dashboard --` query reuses. */
|
|
56
|
+
export declare function dashboardSourceIds(dashboard: Dashboard): Set<number>;
|
|
57
|
+
export declare const panelHasQueries: (panel: Panel) => boolean;
|
|
58
|
+
/** Runs a panel's queries and applies its transformations. */
|
|
59
|
+
export declare function queryPanel(panel: Panel, ctx: PanelQueryContext, signal?: AbortSignal): Promise<DataFrame[]>;
|
|
60
|
+
/** Older dashboards reference datasources by name string; newer ones by {type, uid}. */
|
|
61
|
+
export declare function normalizeRef(ref: DataSourceRef | string | null | undefined): DataSourceRef | undefined;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** A document id from a title: lower case, with dashes for anything else. Empty if there's nothing to use. */
|
|
2
|
+
export declare function documentIdFor(title: string): string;
|
|
3
|
+
export interface RemovedDocument {
|
|
4
|
+
text: string;
|
|
5
|
+
/** Titles of tabs removed because they showed only this document. */
|
|
6
|
+
removedTabs: string[];
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The manifest without document `id`: out of `documents`, every tab's forms and menu items,
|
|
10
|
+
* and with any tab that showed nothing else removed. Throws if that would leave no tabs.
|
|
11
|
+
*/
|
|
12
|
+
export declare function removeDocumentFromManifest(text: string, id: string): RemovedDocument;
|
|
13
|
+
/**
|
|
14
|
+
* The manifest with document `from` listed as `to` instead, at `path` (a file) or unchanged
|
|
15
|
+
* (an inline document), and every tab and menu item that showed it updated. `documents` keeps
|
|
16
|
+
* its order.
|
|
17
|
+
*/
|
|
18
|
+
export declare function renameDocumentInManifest(text: string, from: string, to: string, path?: string): string;
|
|
19
|
+
export interface MetricChange {
|
|
20
|
+
/** A metric some form recorded before and none does after. */
|
|
21
|
+
metric: string;
|
|
22
|
+
/** Where the same input now records something else: probably a rename. */
|
|
23
|
+
renamedTo?: string;
|
|
24
|
+
/** The form (file) and input title, when it was renamed. */
|
|
25
|
+
file?: string;
|
|
26
|
+
input?: string;
|
|
27
|
+
/** Files whose charts still read the metric after the change, so they stop getting new data. */
|
|
28
|
+
readBy: string[];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Metrics that forms stop recording when `before` (files as saved) becomes `after` (null for a
|
|
32
|
+
* deleted file; files not in `after` are unchanged). Entries already saved under them stay, but
|
|
33
|
+
* no form adds to them and a renamed input starts a new history.
|
|
34
|
+
*/
|
|
35
|
+
export declare function metricChanges(before: Record<string, string>, after: Record<string, string | null>): MetricChange[];
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Editing an app config as text: parse with positions, check a set of draft files together
|
|
3
|
+
* exactly as the app would load them, point each issue at a spot in its file, and read and
|
|
4
|
+
* write the files where the config is served.
|
|
5
|
+
*/
|
|
6
|
+
import { type Node } from 'jsonc-parser';
|
|
7
|
+
import type { Panel } from './schema';
|
|
8
|
+
import { type FetchJson, type LoadResult } from './manifest';
|
|
9
|
+
export interface Located {
|
|
10
|
+
/** Character offset and length of the text the issue is about. */
|
|
11
|
+
offset: number;
|
|
12
|
+
length: number;
|
|
13
|
+
/** 1-based. */
|
|
14
|
+
line: number;
|
|
15
|
+
column: number;
|
|
16
|
+
}
|
|
17
|
+
/** An issue within one file, positioned in that file's text when it can be. */
|
|
18
|
+
export interface FileIssue extends Partial<Located> {
|
|
19
|
+
severity: 'error' | 'warning';
|
|
20
|
+
/** Path inside the file, like `tabs[0].screen`, or `(root)`. */
|
|
21
|
+
at: string;
|
|
22
|
+
message: string;
|
|
23
|
+
}
|
|
24
|
+
export declare function lineColumn(text: string, offset: number): {
|
|
25
|
+
line: number;
|
|
26
|
+
column: number;
|
|
27
|
+
};
|
|
28
|
+
export interface ParsedText {
|
|
29
|
+
value?: unknown;
|
|
30
|
+
tree?: Node;
|
|
31
|
+
/** Syntax errors; `value` is only set when there are none. */
|
|
32
|
+
errors: FileIssue[];
|
|
33
|
+
}
|
|
34
|
+
/** Strict JSON (no comments or trailing commas), with positions for syntax errors on every JS engine. */
|
|
35
|
+
export declare function parseJsonText(text: string): ParsedText;
|
|
36
|
+
/** `tabs[0].screen` → ['tabs', 0, 'screen'] */
|
|
37
|
+
export declare function splitPath(path: string): (string | number)[];
|
|
38
|
+
/**
|
|
39
|
+
* Where a path is in the text. Objects and arrays point at their key rather than their whole
|
|
40
|
+
* body; a path that doesn't exist (a missing key) points at its nearest ancestor.
|
|
41
|
+
*/
|
|
42
|
+
export declare function locate(text: string, tree: Node | undefined, path: string): Located | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Checks draft files (path → text) the way the app checks a fetched config, and files each
|
|
45
|
+
* issue under the file it's about, positioned in its text. `manifestPath` is the manifest's
|
|
46
|
+
* own key in `files`; documents are keyed by the path the manifest gives them.
|
|
47
|
+
*/
|
|
48
|
+
export declare function checkFiles(files: Record<string, string>, manifestPath: string): Promise<Record<string, FileIssue[]>>;
|
|
49
|
+
/**
|
|
50
|
+
* The bundle the app would make of draft files (path → text), to preview them as it would show
|
|
51
|
+
* them; no bundle when the app would refuse them.
|
|
52
|
+
*/
|
|
53
|
+
export declare function bundleFromFiles(files: Record<string, string>, manifestPath: string): Promise<LoadResult>;
|
|
54
|
+
/** Pretty-prints JSON text with 2-space indents, keeping key order. Text that doesn't parse comes back unchanged. */
|
|
55
|
+
export declare function formatJsonText(text: string): string;
|
|
56
|
+
/** Sets a value at a path in JSON text, touching only that spot so the rest keeps its formatting. */
|
|
57
|
+
export declare function setJsonValue(text: string, path: (string | number)[], value: unknown): string;
|
|
58
|
+
/** Panel types an editor offers to add, by what they're for. */
|
|
59
|
+
export declare const PANEL_TYPES: {
|
|
60
|
+
form: string[];
|
|
61
|
+
dashboard: string[];
|
|
62
|
+
};
|
|
63
|
+
/** A panel of `type` to start from. Inputs record to `metric`; charts read it from the local datasource. */
|
|
64
|
+
export declare function newPanel(type: string, metric?: string): Panel;
|
|
65
|
+
/** Starting points for a new document. */
|
|
66
|
+
export declare function newDocument(kind: 'form' | 'dashboard', title: string): string;
|
|
67
|
+
/** Where a config's files are read from and saved to, by path relative to the manifest. */
|
|
68
|
+
export interface ConfigFiles {
|
|
69
|
+
/** The manifest's own path, e.g. "app.json". */
|
|
70
|
+
readonly manifestPath: string;
|
|
71
|
+
read(path: string): Promise<string>;
|
|
72
|
+
/** `force` saves even if the file changed elsewhere since it was read. */
|
|
73
|
+
write(path: string, text: string, options?: {
|
|
74
|
+
force?: boolean;
|
|
75
|
+
}): Promise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* Reads every file in one go, all from the same moment, where the server can; resolves
|
|
78
|
+
* null where it can't (then use `read`). Paths are relative to the manifest, like `read`'s.
|
|
79
|
+
*/
|
|
80
|
+
readAll?(): Promise<Record<string, string> | null>;
|
|
81
|
+
/** True once `commit` can be used: the server saves several files at once. */
|
|
82
|
+
readonly atomic?: boolean;
|
|
83
|
+
/** Saves several files as one change, all or none (null deletes). Throws SaveConflictError listing every conflict. */
|
|
84
|
+
commit?(changes: Record<string, string | null>, options?: {
|
|
85
|
+
force?: boolean;
|
|
86
|
+
}): Promise<void>;
|
|
87
|
+
}
|
|
88
|
+
/** Supplies the bearer token for a request, or nothing to send none. Called per request, so it can refresh. */
|
|
89
|
+
export type TokenSource = () => Promise<string | null | undefined> | string | null | undefined;
|
|
90
|
+
/** A save refused because files were saved elsewhere after they were read. */
|
|
91
|
+
export declare class SaveConflictError extends Error {
|
|
92
|
+
readonly paths: string[];
|
|
93
|
+
constructor(paths: string[]);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Files served over HTTP next to the manifest: GET to read, PUT to save. The API and the dev
|
|
97
|
+
* config server both speak this. Where the server gives revisions (ETags), a save only goes
|
|
98
|
+
* through if the file hasn't been saved elsewhere since it was read here; otherwise it throws
|
|
99
|
+
* SaveConflictError, unless `force` is set. Where the server bundles, `readAll` reads the whole
|
|
100
|
+
* config in one request and `commit` saves several files at once.
|
|
101
|
+
*/
|
|
102
|
+
export declare class HttpConfigFiles implements ConfigFiles {
|
|
103
|
+
private manifestUrl;
|
|
104
|
+
private token?;
|
|
105
|
+
readonly manifestPath: string;
|
|
106
|
+
/** The revision of each file as last read or saved here, by path relative to the manifest. */
|
|
107
|
+
private revisions;
|
|
108
|
+
private commitUrl?;
|
|
109
|
+
/** The bundle's root URL, which its file paths are relative to. */
|
|
110
|
+
private root?;
|
|
111
|
+
constructor(manifestUrl: string, token?: TokenSource | undefined);
|
|
112
|
+
get atomic(): boolean;
|
|
113
|
+
read(path: string): Promise<string>;
|
|
114
|
+
readAll(): Promise<Record<string, string> | null>;
|
|
115
|
+
/** A bundle path as a path relative to the manifest, or null if it's not under the manifest's folder. */
|
|
116
|
+
private relative;
|
|
117
|
+
/** A path relative to the manifest as a bundle path. */
|
|
118
|
+
private key;
|
|
119
|
+
write(path: string, text: string, { force }?: {
|
|
120
|
+
force?: boolean;
|
|
121
|
+
}): Promise<void>;
|
|
122
|
+
commit(changes: Record<string, string | null>, { force }?: {
|
|
123
|
+
force?: boolean;
|
|
124
|
+
}): Promise<void>;
|
|
125
|
+
}
|
|
126
|
+
/** A FetchJson that sends a bearer token, for loading configs from the API. */
|
|
127
|
+
export declare function fetchJsonWithToken(token: TokenSource): FetchJson;
|
|
128
|
+
/** Reads the manifest and every document it gives a path for. Files that can't be read are left out (checkFiles then reports them). */
|
|
129
|
+
export declare function readConfigFiles(source: ConfigFiles): Promise<Record<string, string>>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { DataFrame, Field } from './frame';
|
|
2
|
+
import type { FieldConfig, Panel } from './schema';
|
|
3
|
+
/**
|
|
4
|
+
* Effective config for a field: panel defaults, then config the datasource attached
|
|
5
|
+
* to the field, then any matching panel overrides (byName, byRegexp, byFrameRefID, byType).
|
|
6
|
+
*/
|
|
7
|
+
export declare function resolveFieldConfig(panel: Panel, field: Field, frame: DataFrame, displayName: string): FieldConfig;
|
|
8
|
+
/** Whether a Grafana field matcher (byName, byRegexp, byFrameRefID, byType) selects this field. */
|
|
9
|
+
export declare function fieldMatches(matcher: {
|
|
10
|
+
id: string;
|
|
11
|
+
options?: unknown;
|
|
12
|
+
}, field: Field, frame: DataFrame, displayName: string): boolean;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { FieldConfig, MappingResult, ThresholdStep } from './schema';
|
|
2
|
+
/** Value formatting for the Grafana units people actually use. Unknown units fall back to "short". */
|
|
3
|
+
export declare function formatValue(value: number | null | undefined, config?: FieldConfig): string;
|
|
4
|
+
/** The step with the highest value at or below the value, in any order; the first step (the base, value null) below them all. */
|
|
5
|
+
export declare function thresholdStep(value: number | null, config?: FieldConfig): ThresholdStep | undefined;
|
|
6
|
+
/**
|
|
7
|
+
* Grafana's named colors. Panels created in Grafana reference these by name
|
|
8
|
+
* (thresholds default to "green"/"red"), so they must resolve to the same hues.
|
|
9
|
+
*/
|
|
10
|
+
export declare const NAMED_COLORS: Record<string, string>;
|
|
11
|
+
export declare function resolveColor(name: string | undefined, fallback: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Default categorical series palette (validated for colorblind separation, assigned in fixed
|
|
14
|
+
* order). Light and dark steps are tuned for each surface.
|
|
15
|
+
*/
|
|
16
|
+
export declare const SERIES_PALETTE: {
|
|
17
|
+
light: string[];
|
|
18
|
+
dark: string[];
|
|
19
|
+
};
|
|
20
|
+
export declare function seriesColor(index: number, scheme: 'light' | 'dark', config?: FieldConfig): string;
|
|
21
|
+
/** The text a value mapping gives a value, if any. Supports value, range and special mappings. */
|
|
22
|
+
export declare function mappedResult(value: unknown, config?: FieldConfig): MappingResult | undefined;
|
|
23
|
+
/** formatValue, with the field's value mappings applied first. */
|
|
24
|
+
export declare function formatDisplay(value: number | null | undefined, config?: FieldConfig): string;
|
|
25
|
+
/**
|
|
26
|
+
* The color a field's config gives one value: a mapping's color, the fixed color, the matching threshold, or a
|
|
27
|
+
* continuous scheme between min and max (from config, else `extent`). Other modes use `fallback`.
|
|
28
|
+
*/
|
|
29
|
+
export declare function valueColor(value: number | null, config: FieldConfig, fallback: string, extent?: [number, number]): string;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { FieldConfig } from './schema';
|
|
2
|
+
/** Column-oriented data, matching Grafana's data frame model so Grafana query results map 1:1. */
|
|
3
|
+
export type FieldType = 'time' | 'number' | 'string' | 'boolean' | 'other';
|
|
4
|
+
export interface Field {
|
|
5
|
+
name: string;
|
|
6
|
+
type: FieldType;
|
|
7
|
+
values: unknown[];
|
|
8
|
+
labels?: Record<string, string>;
|
|
9
|
+
config?: FieldConfig;
|
|
10
|
+
}
|
|
11
|
+
export interface DataFrame {
|
|
12
|
+
name?: string;
|
|
13
|
+
refId?: string;
|
|
14
|
+
fields: Field[];
|
|
15
|
+
}
|
|
16
|
+
export declare const frameLength: (frame: DataFrame) => number;
|
|
17
|
+
export declare const timeField: (frame: DataFrame) => Field | undefined;
|
|
18
|
+
export declare const numberFields: (frame: DataFrame) => Field[];
|
|
19
|
+
/** One plottable line: a numeric field paired with its frame's time field (or, for toXYSeries, its x field). */
|
|
20
|
+
export interface Series {
|
|
21
|
+
key: string;
|
|
22
|
+
name: string;
|
|
23
|
+
/** x positions: epoch ms for time series, the x field's values for toXYSeries. */
|
|
24
|
+
times: number[];
|
|
25
|
+
values: (number | null)[];
|
|
26
|
+
field: Field;
|
|
27
|
+
}
|
|
28
|
+
/** Display name the way Grafana derives it: config.displayName, then labels, then frame/field names. */
|
|
29
|
+
export declare function fieldDisplayName(field: Field, frame: DataFrame, multipleFrames: boolean): string;
|
|
30
|
+
/** Flatten frames into time series (one per numeric field). Frames without a time field are skipped. */
|
|
31
|
+
export declare function toSeries(frames: DataFrame[]): Series[];
|
|
32
|
+
/**
|
|
33
|
+
* Series against a numeric x field, as Grafana's "trend" panel plots them: x is the field named
|
|
34
|
+
* `xField` (in frames that have it), else each frame's first number field; every other number
|
|
35
|
+
* field is a series. Points are put in x order, since the line is drawn left to right.
|
|
36
|
+
*/
|
|
37
|
+
export declare function toXYSeries(frames: DataFrame[], xField?: string): {
|
|
38
|
+
series: Series[];
|
|
39
|
+
x?: {
|
|
40
|
+
field: Field;
|
|
41
|
+
frame: DataFrame;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* When display names collide (e.g. two frames with the same single label), qualify them with
|
|
46
|
+
* the frame name, then fall back to numbering, so the legend never shows the same name twice.
|
|
47
|
+
*/
|
|
48
|
+
export declare function uniqueNames<T extends {
|
|
49
|
+
name: string;
|
|
50
|
+
}>(items: T[], fieldOf: (item: T) => Field, frames: DataFrame[]): T[];
|
|
51
|
+
export declare function toMillis(v: unknown): number;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { DataSource } from './datasource';
|
|
2
|
+
/**
|
|
3
|
+
* Grafana gazetteers: named places with coordinates, for geomap layers that locate rows by a lookup field
|
|
4
|
+
* (a country code, a state, an airport). Grafana serves its own under public/gazetteer/.
|
|
5
|
+
*/
|
|
6
|
+
export interface Gazetteer {
|
|
7
|
+
find(key: string): {
|
|
8
|
+
lon: number;
|
|
9
|
+
lat: number;
|
|
10
|
+
} | undefined;
|
|
11
|
+
}
|
|
12
|
+
/** The gazetteer Grafana uses when a lookup layer names none. */
|
|
13
|
+
export declare const DEFAULT_GAZETTEER = "public/gazetteer/countries.json";
|
|
14
|
+
/**
|
|
15
|
+
* Reads the formats Grafana ships: a list of places with `key`/`keys`, `name`, `latitude`/`longitude`
|
|
16
|
+
* (countries.json, usa-states.json), or a GeoJSON FeatureCollection (airports.geojson), whose features are found
|
|
17
|
+
* by id or any text property. Keys match exactly first, then ignoring case.
|
|
18
|
+
*/
|
|
19
|
+
export declare function parseGazetteer(json: unknown): Gazetteer;
|
|
20
|
+
/**
|
|
21
|
+
* Loads a gazetteer once per datasource. An http(s) URL is fetched directly; a path such as
|
|
22
|
+
* public/gazetteer/usa-states.json comes from the datasource's Grafana (see DataSource.publicFile).
|
|
23
|
+
* A failed load isn't cached, so the next panel to ask tries again.
|
|
24
|
+
*/
|
|
25
|
+
export declare function loadGazetteer(path: string, ds?: DataSource): Promise<Gazetteer>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { DataSource, QueryRequest, VariableQueryRequest } from './datasource';
|
|
2
|
+
import type { DataFrame } from './frame';
|
|
3
|
+
import type { Dashboard, DataSourceRef } from './schema';
|
|
4
|
+
import { type VarOption } from './variables';
|
|
5
|
+
/**
|
|
6
|
+
* Talks to a Grafana instance's HTTP API with a service-account token.
|
|
7
|
+
* Works with self-hosted Grafana, Grafana Cloud and Amazon Managed Grafana
|
|
8
|
+
* (service accounts are available on AMG workspaces running Grafana 9+).
|
|
9
|
+
*
|
|
10
|
+
* Panel queries go through /api/ds/query, so Grafana runs the PromQL/SQL/CloudWatch
|
|
11
|
+
* query server-side and the app never needs to understand query languages.
|
|
12
|
+
*/
|
|
13
|
+
export interface GrafanaConfig {
|
|
14
|
+
/** e.g. https://g-abc123.grafana-workspace.us-east-1.amazonaws.com */
|
|
15
|
+
url: string;
|
|
16
|
+
token: string;
|
|
17
|
+
fetch?: typeof fetch;
|
|
18
|
+
}
|
|
19
|
+
export interface GrafanaSearchHit {
|
|
20
|
+
uid: string;
|
|
21
|
+
title: string;
|
|
22
|
+
type: 'dash-db' | 'dash-folder';
|
|
23
|
+
/** The containing folder; absent at the root. For folders, the parent when Grafana has nested folders. */
|
|
24
|
+
folderUid?: string;
|
|
25
|
+
folderTitle?: string;
|
|
26
|
+
tags: string[];
|
|
27
|
+
url: string;
|
|
28
|
+
}
|
|
29
|
+
interface WireFrame {
|
|
30
|
+
schema?: {
|
|
31
|
+
name?: string;
|
|
32
|
+
refId?: string;
|
|
33
|
+
fields: {
|
|
34
|
+
name: string;
|
|
35
|
+
type?: string;
|
|
36
|
+
labels?: Record<string, string>;
|
|
37
|
+
config?: any;
|
|
38
|
+
}[];
|
|
39
|
+
};
|
|
40
|
+
data?: {
|
|
41
|
+
values: unknown[][];
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export declare class GrafanaError extends Error {
|
|
45
|
+
readonly status?: number | undefined;
|
|
46
|
+
constructor(message: string, status?: number | undefined);
|
|
47
|
+
}
|
|
48
|
+
export declare class GrafanaClient {
|
|
49
|
+
private readonly config;
|
|
50
|
+
private settings?;
|
|
51
|
+
private readonly base;
|
|
52
|
+
private readonly doFetch;
|
|
53
|
+
constructor(config: GrafanaConfig);
|
|
54
|
+
request<T>(path: string, init?: RequestInit): Promise<T>;
|
|
55
|
+
/** Returns the signed-in identity; handy as a connection test. */
|
|
56
|
+
user(): Promise<{
|
|
57
|
+
login: string;
|
|
58
|
+
name?: string;
|
|
59
|
+
orgId: number;
|
|
60
|
+
}>;
|
|
61
|
+
search(query?: string, options?: {
|
|
62
|
+
type?: GrafanaSearchHit['type'];
|
|
63
|
+
tag?: string[];
|
|
64
|
+
limit?: number;
|
|
65
|
+
}): Promise<GrafanaSearchHit[]>;
|
|
66
|
+
dashboard(uid: string): Promise<Dashboard>;
|
|
67
|
+
/** Resolve name / "${DS_X}" placeholder / missing refs to a concrete {type, uid}. */
|
|
68
|
+
resolveRef(ref: DataSourceRef | undefined): Promise<DataSourceRef>;
|
|
69
|
+
query(request: QueryRequest, signal?: AbortSignal): Promise<DataFrame[]>;
|
|
70
|
+
}
|
|
71
|
+
/** A DataSource that sends every query to Grafana. One instance serves all of a dashboard's datasources. */
|
|
72
|
+
export declare class GrafanaDataSource implements DataSource {
|
|
73
|
+
readonly client: GrafanaClient;
|
|
74
|
+
constructor(client: GrafanaClient);
|
|
75
|
+
query(request: QueryRequest, signal?: AbortSignal): Promise<DataFrame[]>;
|
|
76
|
+
publicFile(path: string, signal?: AbortSignal): Promise<unknown>;
|
|
77
|
+
/**
|
|
78
|
+
* SQL variable queries run through /api/ds/query like any panel query. Other datasources
|
|
79
|
+
* (Prometheus label_values() and the like) evaluate variable queries in Grafana's frontend,
|
|
80
|
+
* which this can't reproduce, so those return null.
|
|
81
|
+
*/
|
|
82
|
+
variableOptions({ query, datasource, range }: VariableQueryRequest, signal?: AbortSignal): Promise<VarOption[] | null>;
|
|
83
|
+
}
|
|
84
|
+
export declare function fromWire(frame: WireFrame): DataFrame;
|
|
85
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export * from './schema';
|
|
2
|
+
export * from './frame';
|
|
3
|
+
export * from './time';
|
|
4
|
+
export * from './layout';
|
|
5
|
+
export * from './variables';
|
|
6
|
+
export * from './resolveVariables';
|
|
7
|
+
export * from './reduce';
|
|
8
|
+
export * from './format';
|
|
9
|
+
export * from './fieldconfig';
|
|
10
|
+
export * from './datasource';
|
|
11
|
+
export * from './transform';
|
|
12
|
+
export * from './grafana';
|
|
13
|
+
export * from './inputs';
|
|
14
|
+
export * from './local';
|
|
15
|
+
export * from './gazetteer';
|
|
16
|
+
export * from './links';
|
|
17
|
+
export * from './manifest';
|
|
18
|
+
export * from './navigation';
|
|
19
|
+
export * from './documents';
|
|
20
|
+
export * from './dashboardSettings';
|
|
21
|
+
export * from './configSchema';
|
|
22
|
+
export * from './editing';
|
|
23
|
+
export * from './jsonEdit';
|
|
24
|
+
export * from './layoutEdit';
|
|
25
|
+
export * from './mappings';
|
|
26
|
+
export * from './panelOptions';
|
|
27
|
+
export * from './sample';
|