@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,95 @@
|
|
|
1
|
+
import type { DataSource, QueryRequest } from './datasource';
|
|
2
|
+
import type { DataFrame } from './frame';
|
|
3
|
+
import type { Entry, NewEntry } from './inputs';
|
|
4
|
+
import type { DataSourceRef, Target } from './schema';
|
|
5
|
+
/**
|
|
6
|
+
* A datasource over entries recorded by input forms. Reference it from a panel with
|
|
7
|
+
* `"datasource": {"type": "modelform-local"}` and targets like:
|
|
8
|
+
*
|
|
9
|
+
* { "refId": "A", "metric": "weight" } raw points
|
|
10
|
+
* { "refId": "A", "metric": "water", "aggregate": "sum", "bucket": "1d" } daily totals
|
|
11
|
+
* { "refId": "A", "metric": "mood", "aggregate": "count", "groupBy": "text" } one series per choice
|
|
12
|
+
*/
|
|
13
|
+
export declare const LOCAL_DATASOURCE_TYPE = "modelform-local";
|
|
14
|
+
/** Whether a panel or target's datasource is the local one, under its current name or its old one. */
|
|
15
|
+
export declare function isLocalDatasource(ref: DataSourceRef | string | null | undefined): boolean;
|
|
16
|
+
export interface EntryStore {
|
|
17
|
+
add(entries: NewEntry[]): Promise<Entry[]>;
|
|
18
|
+
list(query: {
|
|
19
|
+
metrics: string[];
|
|
20
|
+
from?: number;
|
|
21
|
+
to?: number;
|
|
22
|
+
}): Promise<Entry[]>;
|
|
23
|
+
latest(metric: string): Promise<Entry | undefined>;
|
|
24
|
+
remove(id: string): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Remove `ids` and add `entries` as one change, so an edited record is never left half
|
|
27
|
+
* saved. Stores without it get a remove of each id followed by an add.
|
|
28
|
+
*/
|
|
29
|
+
replace?(ids: string[], entries: NewEntry[]): Promise<Entry[]>;
|
|
30
|
+
/** Subscribe to changes so panels can refresh after a save. Returns an unsubscribe function. */
|
|
31
|
+
subscribe(listener: () => void): () => void;
|
|
32
|
+
}
|
|
33
|
+
export type Aggregate = 'none' | 'sum' | 'avg' | 'min' | 'max' | 'count' | 'last';
|
|
34
|
+
export interface LocalTarget extends Target {
|
|
35
|
+
metric: string;
|
|
36
|
+
aggregate?: Aggregate;
|
|
37
|
+
/** Bucket size such as "1h", "1d", "1w", "1M", or "auto" to follow the panel's interval. */
|
|
38
|
+
bucket?: string;
|
|
39
|
+
/** "text" splits into one series per distinct text value (e.g. select choices). */
|
|
40
|
+
groupBy?: 'text';
|
|
41
|
+
/** Fill empty buckets with 0. Defaults to true for sum/count. */
|
|
42
|
+
fillZero?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Raw points only: "previous" treats each value as holding until the next one, for settings
|
|
45
|
+
* recorded only when they change. The series starts at the range start with the value in
|
|
46
|
+
* effect then and ends at the range end (or now) with the latest value.
|
|
47
|
+
*/
|
|
48
|
+
fill?: 'previous';
|
|
49
|
+
/** Display name for the series. */
|
|
50
|
+
alias?: string;
|
|
51
|
+
}
|
|
52
|
+
export interface LocalDataSourceOptions {
|
|
53
|
+
/**
|
|
54
|
+
* Display name for a `groupBy: "text"` series, for text that's an id into app data
|
|
55
|
+
* (e.g. a tire set id → its name). Return undefined to keep the text.
|
|
56
|
+
*/
|
|
57
|
+
label?(metric: string, text: string): string | undefined;
|
|
58
|
+
}
|
|
59
|
+
export declare class LocalDataSource implements DataSource {
|
|
60
|
+
private readonly store;
|
|
61
|
+
private readonly options;
|
|
62
|
+
constructor(store: EntryStore, options?: LocalDataSourceOptions);
|
|
63
|
+
query(request: QueryRequest): Promise<DataFrame[]>;
|
|
64
|
+
}
|
|
65
|
+
export declare function buildFrames(target: LocalTarget, entries: Entry[], request: Pick<QueryRequest, 'range' | 'intervalMs'>, label?: LocalDataSourceOptions['label']): DataFrame[];
|
|
66
|
+
/** In-memory EntryStore for tests, previews and web. */
|
|
67
|
+
export declare class MemoryEntryStore implements EntryStore {
|
|
68
|
+
private entries;
|
|
69
|
+
private listeners;
|
|
70
|
+
private nextId;
|
|
71
|
+
constructor(seed?: NewEntry[]);
|
|
72
|
+
add(entries: NewEntry[]): Promise<{
|
|
73
|
+
id: string;
|
|
74
|
+
metric: string;
|
|
75
|
+
value: number | null;
|
|
76
|
+
text: string | null;
|
|
77
|
+
ts: number;
|
|
78
|
+
}[]>;
|
|
79
|
+
list({ metrics, from, to }: {
|
|
80
|
+
metrics: string[];
|
|
81
|
+
from?: number;
|
|
82
|
+
to?: number;
|
|
83
|
+
}): Promise<Entry[]>;
|
|
84
|
+
latest(metric: string): Promise<Entry>;
|
|
85
|
+
remove(id: string): Promise<void>;
|
|
86
|
+
replace(ids: string[], entries: NewEntry[]): Promise<{
|
|
87
|
+
id: string;
|
|
88
|
+
metric: string;
|
|
89
|
+
value: number | null;
|
|
90
|
+
text: string | null;
|
|
91
|
+
ts: number;
|
|
92
|
+
}[]>;
|
|
93
|
+
subscribe(listener: () => void): () => boolean;
|
|
94
|
+
private emit;
|
|
95
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import type { Dashboard } from './schema';
|
|
2
|
+
export declare const MANIFEST_VERSION = 1;
|
|
3
|
+
/** The root of an app config: navigation, plus the documents it shows. Annotations here feed schema/app.schema.json. */
|
|
4
|
+
export interface AppManifest {
|
|
5
|
+
/** Format version. Always 1 for now. */
|
|
6
|
+
version: number;
|
|
7
|
+
/**
|
|
8
|
+
* The app's name.
|
|
9
|
+
* @minLength 1
|
|
10
|
+
*/
|
|
11
|
+
title: string;
|
|
12
|
+
/**
|
|
13
|
+
* The bottom tabs, in order.
|
|
14
|
+
* @minItems 1
|
|
15
|
+
*/
|
|
16
|
+
tabs: Tab[];
|
|
17
|
+
/** Dashboards and forms by id: a path relative to this file, or the dashboard JSON inline. */
|
|
18
|
+
documents: Record<string, string | Dashboard>;
|
|
19
|
+
}
|
|
20
|
+
export interface Tab {
|
|
21
|
+
/**
|
|
22
|
+
* Also the tab's route, so keep it URL-safe and stable.
|
|
23
|
+
* @pattern ^[A-Za-z0-9_-]+$
|
|
24
|
+
*/
|
|
25
|
+
id: string;
|
|
26
|
+
/** @minLength 1 */
|
|
27
|
+
title: string;
|
|
28
|
+
/** A name from the app's icon set (e.g. "edit", "chart"), or per-platform symbol names. */
|
|
29
|
+
icon?: string | {
|
|
30
|
+
ios?: string;
|
|
31
|
+
android?: string;
|
|
32
|
+
web?: string;
|
|
33
|
+
};
|
|
34
|
+
screen: Screen;
|
|
35
|
+
}
|
|
36
|
+
export type Screen =
|
|
37
|
+
/** One dashboard. */
|
|
38
|
+
{
|
|
39
|
+
type: 'dashboard';
|
|
40
|
+
dashboard: string;
|
|
41
|
+
}
|
|
42
|
+
/** Input forms, picked with chips when there's more than one. */
|
|
43
|
+
| {
|
|
44
|
+
type: 'forms';
|
|
45
|
+
/** @minItems 1 */
|
|
46
|
+
forms: string[];
|
|
47
|
+
}
|
|
48
|
+
/** A list that opens dashboards and forms. */
|
|
49
|
+
| {
|
|
50
|
+
type: 'menu';
|
|
51
|
+
items: MenuItem[];
|
|
52
|
+
};
|
|
53
|
+
export interface MenuItem {
|
|
54
|
+
/** Defaults to the document's title. */
|
|
55
|
+
title?: string;
|
|
56
|
+
description?: string;
|
|
57
|
+
/** A dashboard to open. Give this or `form`, not both. */
|
|
58
|
+
dashboard?: string;
|
|
59
|
+
/** A form to open. Give this or `dashboard`, not both. */
|
|
60
|
+
form?: string;
|
|
61
|
+
}
|
|
62
|
+
/** A manifest with every document fetched and parsed. */
|
|
63
|
+
export interface ConfigBundle {
|
|
64
|
+
manifest: AppManifest;
|
|
65
|
+
documents: Record<string, Dashboard>;
|
|
66
|
+
}
|
|
67
|
+
export interface ConfigIssue {
|
|
68
|
+
severity: 'error' | 'warning';
|
|
69
|
+
/** Where in the config, e.g. `app.json: tabs[1].screen.dashboard` or `forms/daily.json: panels[3]`. */
|
|
70
|
+
path: string;
|
|
71
|
+
message: string;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Checks the manifest's own shape against schema/app.schema.json, plus what the schema can't
|
|
75
|
+
* say. Inline documents are left to validateDashboard, and document references to
|
|
76
|
+
* validateBundle once documents are loaded.
|
|
77
|
+
*/
|
|
78
|
+
export declare function validateManifest(json: unknown, file?: string): ConfigIssue[];
|
|
79
|
+
/**
|
|
80
|
+
* Checks a dashboard or form and readies it for rendering. Errors are what would stop it
|
|
81
|
+
* rendering, and leave no dashboard. Otherwise values that don't fit the schema (a title
|
|
82
|
+
* that's a number, say) are removed, each with a warning, so the renderer never sees them;
|
|
83
|
+
* anything else the schema flags (unknown keys, mostly) is a warning, since Grafana exports
|
|
84
|
+
* often carry values modelform just ignores.
|
|
85
|
+
*/
|
|
86
|
+
export declare function prepareDashboard(json: unknown, file: string): {
|
|
87
|
+
dashboard?: Dashboard;
|
|
88
|
+
issues: ConfigIssue[];
|
|
89
|
+
};
|
|
90
|
+
/** The issues `prepareDashboard` would find. */
|
|
91
|
+
export declare function validateDashboard(json: unknown, file: string): ConfigIssue[];
|
|
92
|
+
/** Cross-checks a loaded bundle: screens must point at documents that exist, and forms must have inputs. */
|
|
93
|
+
export declare function validateBundle(bundle: ConfigBundle, file?: string): ConfigIssue[];
|
|
94
|
+
/**
|
|
95
|
+
* Resolves `rel` against the URL of the file that referenced it. Hand-rolled because
|
|
96
|
+
* React Native's URL polyfill doesn't support relative resolution.
|
|
97
|
+
*/
|
|
98
|
+
export declare function resolveUrl(base: string, rel: string): string;
|
|
99
|
+
/** `accept` replaces the default Accept header, e.g. to ask for a bundle. */
|
|
100
|
+
export type FetchJson = (url: string, options?: {
|
|
101
|
+
accept?: string;
|
|
102
|
+
}) => Promise<unknown>;
|
|
103
|
+
export declare const defaultFetchJson: FetchJson;
|
|
104
|
+
export interface LoadResult {
|
|
105
|
+
/** Present when there are no errors. */
|
|
106
|
+
bundle?: ConfigBundle;
|
|
107
|
+
issues: ConfigIssue[];
|
|
108
|
+
/** The config's revision, when the server sent it as one bundle. */
|
|
109
|
+
revision?: string;
|
|
110
|
+
}
|
|
111
|
+
/** Asked for on the manifest's URL, a server that can returns the whole config in one response. */
|
|
112
|
+
export declare const BUNDLE_TYPE = "application/vnd.modelform.bundle+json";
|
|
113
|
+
export declare const BUNDLE_ACCEPT = "application/vnd.modelform.bundle+json, application/json;q=0.9";
|
|
114
|
+
/**
|
|
115
|
+
* A whole config as of one moment: what the API and the dev config server send for the
|
|
116
|
+
* manifest's URL when asked for BUNDLE_TYPE. File paths are relative to the config's root,
|
|
117
|
+
* of which `manifest` is one; `commit` (relative to the manifest's URL) saves several at once.
|
|
118
|
+
*/
|
|
119
|
+
export interface BundleResponse {
|
|
120
|
+
$bundle: 1;
|
|
121
|
+
revision: string | number;
|
|
122
|
+
manifest: string;
|
|
123
|
+
commit?: string;
|
|
124
|
+
files: Record<string, {
|
|
125
|
+
revision: string | number;
|
|
126
|
+
text: string;
|
|
127
|
+
}>;
|
|
128
|
+
}
|
|
129
|
+
export declare function isBundleResponse(json: unknown): json is BundleResponse;
|
|
130
|
+
/** The URL of a bundle's root folder, from the manifest's URL. */
|
|
131
|
+
export declare function bundleRoot(manifestUrl: string, manifestPath: string): string;
|
|
132
|
+
/**
|
|
133
|
+
* Builds a bundle from a server's bundle response. Documents inside the config come from the
|
|
134
|
+
* response; one elsewhere (an absolute URL) is still fetched.
|
|
135
|
+
*/
|
|
136
|
+
export declare function assembleFromResponse(url: string, response: BundleResponse, fetchJson?: FetchJson): Promise<LoadResult>;
|
|
137
|
+
/**
|
|
138
|
+
* Builds a bundle from a parsed manifest, getting each path document with `load`.
|
|
139
|
+
* Never throws: failures to fetch or parse come back as issues.
|
|
140
|
+
*/
|
|
141
|
+
export declare function assembleBundle(manifest: unknown, load: (path: string) => Promise<unknown>, file?: string): Promise<LoadResult>;
|
|
142
|
+
/**
|
|
143
|
+
* Fetches a config: in one response from a server that bundles (all of it from the same
|
|
144
|
+
* moment), or else the manifest and then each document it points to, resolved against its URL.
|
|
145
|
+
*/
|
|
146
|
+
export declare function fetchBundle(url: string, fetchJson?: FetchJson): Promise<LoadResult>;
|
|
147
|
+
/** Where the last good config is kept between launches. */
|
|
148
|
+
export interface ConfigCache {
|
|
149
|
+
read(): Promise<CachedConfig | null>;
|
|
150
|
+
write(config: CachedConfig): Promise<void>;
|
|
151
|
+
}
|
|
152
|
+
export interface CachedConfig {
|
|
153
|
+
url: string;
|
|
154
|
+
fetchedAt: number;
|
|
155
|
+
bundle: ConfigBundle;
|
|
156
|
+
revision?: string;
|
|
157
|
+
}
|
|
158
|
+
export interface ConfigState {
|
|
159
|
+
bundle?: ConfigBundle;
|
|
160
|
+
source: 'none' | 'bundled' | 'cache' | 'remote';
|
|
161
|
+
url?: string;
|
|
162
|
+
/** When the bundle shown was fetched (cache or remote). */
|
|
163
|
+
fetchedAt?: number;
|
|
164
|
+
/** The shown config's revision, when the server gives one. */
|
|
165
|
+
revision?: string;
|
|
166
|
+
loading: boolean;
|
|
167
|
+
/** A summary ("2 errors") when the last fetch failed; the bundle shown is then the last good one. See `issues`. */
|
|
168
|
+
error?: string;
|
|
169
|
+
/** From the last fetch, good or bad. */
|
|
170
|
+
issues: ConfigIssue[];
|
|
171
|
+
}
|
|
172
|
+
export interface ConfigLoaderOptions {
|
|
173
|
+
/** Where the manifest is served. Without one, only `fallback` is used. */
|
|
174
|
+
url?: string;
|
|
175
|
+
cache?: ConfigCache;
|
|
176
|
+
/** Shown until something better loads, e.g. a config bundled with the app. */
|
|
177
|
+
fallback?: ConfigBundle;
|
|
178
|
+
fetchJson?: FetchJson;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Keeps the app's config current. Shows the bundled fallback, then the cached copy,
|
|
182
|
+
* then each newer fetch that validates. A bad fetch never replaces a good config: it's
|
|
183
|
+
* reported in `error`/`issues` and the last good bundle stays.
|
|
184
|
+
*/
|
|
185
|
+
export declare class ConfigLoader {
|
|
186
|
+
private options;
|
|
187
|
+
private listeners;
|
|
188
|
+
private snapshot;
|
|
189
|
+
private lastJson?;
|
|
190
|
+
private inflight?;
|
|
191
|
+
constructor(options: ConfigLoaderOptions);
|
|
192
|
+
get state(): ConfigState;
|
|
193
|
+
subscribe: (listener: () => void) => () => void;
|
|
194
|
+
getSnapshot: () => ConfigState;
|
|
195
|
+
/** Loads the cached copy (if it was fetched from the same URL), then fetches. */
|
|
196
|
+
start(): Promise<void>;
|
|
197
|
+
/** Fetches now. Concurrent calls share one fetch. Only notifies listeners when something changed. */
|
|
198
|
+
refresh(): Promise<void>;
|
|
199
|
+
/** `notify: false` drops the patch, so the snapshot only changes when listeners hear about it. */
|
|
200
|
+
private set;
|
|
201
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Value mappings as an editor shows them: one row per condition, in the order they're tried.
|
|
3
|
+
* Grafana keeps every value condition in one mapping keyed by value; rows keep each in its own,
|
|
4
|
+
* so editing a value never reorders or merges rows. Both shapes render the same here.
|
|
5
|
+
*/
|
|
6
|
+
import type { MappingResult, ValueMapping } from './schema';
|
|
7
|
+
export type SpecialMatch = 'null' | 'nan' | 'null+nan' | 'true' | 'false' | 'empty';
|
|
8
|
+
export type MappingRow = {
|
|
9
|
+
type: 'value';
|
|
10
|
+
value: string;
|
|
11
|
+
result: MappingResult;
|
|
12
|
+
} | {
|
|
13
|
+
type: 'range';
|
|
14
|
+
from: number | null;
|
|
15
|
+
to: number | null;
|
|
16
|
+
result: MappingResult;
|
|
17
|
+
} | {
|
|
18
|
+
type: 'regex';
|
|
19
|
+
pattern: string;
|
|
20
|
+
result: MappingResult;
|
|
21
|
+
} | {
|
|
22
|
+
type: 'special';
|
|
23
|
+
match: SpecialMatch;
|
|
24
|
+
result: MappingResult;
|
|
25
|
+
}
|
|
26
|
+
/** A mapping type modelform doesn't render, kept as it is. */
|
|
27
|
+
| {
|
|
28
|
+
type: 'other';
|
|
29
|
+
mapping: ValueMapping;
|
|
30
|
+
};
|
|
31
|
+
export declare const MAPPING_TYPES: {
|
|
32
|
+
label: string;
|
|
33
|
+
value: Exclude<MappingRow['type'], 'other'>;
|
|
34
|
+
}[];
|
|
35
|
+
export declare const SPECIAL_MATCHES: {
|
|
36
|
+
label: string;
|
|
37
|
+
value: SpecialMatch;
|
|
38
|
+
}[];
|
|
39
|
+
/** The rows of a list of mappings. A value mapping with several values becomes a row each, in Grafana's `index` order. */
|
|
40
|
+
export declare function mappingRows(mappings: ValueMapping[] | undefined): MappingRow[];
|
|
41
|
+
/** Mappings for rows, one each. */
|
|
42
|
+
export declare function rowsToMappings(rows: MappingRow[]): ValueMapping[];
|
|
43
|
+
/** A new row of a type, keeping what it shows from the row it replaces. */
|
|
44
|
+
export declare function mappingRow(type: Exclude<MappingRow['type'], 'other'>, result?: MappingResult): MappingRow;
|
|
45
|
+
/** Why the renderer can't use a mapping, if it can't. Types it doesn't know are fine: it skips them. */
|
|
46
|
+
export declare function mappingProblem(m: unknown): string | undefined;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Editing a manifest's navigation: ids for new tabs, what a tab shows when its screen type
|
|
3
|
+
* changes, and where each document is shown.
|
|
4
|
+
*/
|
|
5
|
+
import type { AppManifest, Screen } from './manifest';
|
|
6
|
+
/** A URL-safe tab id from a title, unlike any of `taken`. */
|
|
7
|
+
export declare function tabIdFor(title: string, taken: string[]): string;
|
|
8
|
+
/** A screen of another type, showing what the old one did where it can (a dashboard, or a form, becomes a menu item). */
|
|
9
|
+
export declare function screenOfType(type: Screen['type'], from: Screen | undefined, docs: {
|
|
10
|
+
forms: string[];
|
|
11
|
+
dashboards: string[];
|
|
12
|
+
}): Screen;
|
|
13
|
+
/** The documents a screen shows, in order. */
|
|
14
|
+
export declare function screenDocuments(screen: Screen): {
|
|
15
|
+
id: string;
|
|
16
|
+
kind: 'form' | 'dashboard';
|
|
17
|
+
}[];
|
|
18
|
+
/** For each document, the titles of the tabs that show it, directly or from their menu. */
|
|
19
|
+
export declare function documentUses(manifest: Pick<AppManifest, 'tabs'>): Record<string, string[]>;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type { FieldType } from './frame';
|
|
2
|
+
import type { FieldOverride, Panel } from './schema';
|
|
3
|
+
export type OptionControl = {
|
|
4
|
+
kind: 'boolean';
|
|
5
|
+
} | {
|
|
6
|
+
kind: 'number';
|
|
7
|
+
min?: number;
|
|
8
|
+
max?: number;
|
|
9
|
+
integer?: boolean;
|
|
10
|
+
} | {
|
|
11
|
+
kind: 'select';
|
|
12
|
+
choices: {
|
|
13
|
+
label: string;
|
|
14
|
+
value: string;
|
|
15
|
+
}[];
|
|
16
|
+
} | {
|
|
17
|
+
kind: 'text';
|
|
18
|
+
multiline?: boolean;
|
|
19
|
+
placeholder?: string;
|
|
20
|
+
}
|
|
21
|
+
/** A Grafana unit id; offered from UNIT_CHOICES. */
|
|
22
|
+
| {
|
|
23
|
+
kind: 'unit';
|
|
24
|
+
}
|
|
25
|
+
/** A Grafana color name or a CSS color. */
|
|
26
|
+
| {
|
|
27
|
+
kind: 'color';
|
|
28
|
+
}
|
|
29
|
+
/** fieldConfig.defaults.thresholds: a base color and steps. */
|
|
30
|
+
| {
|
|
31
|
+
kind: 'thresholds';
|
|
32
|
+
}
|
|
33
|
+
/** fieldConfig.defaults.mappings: display text and colors for values. */
|
|
34
|
+
| {
|
|
35
|
+
kind: 'mappings';
|
|
36
|
+
}
|
|
37
|
+
/** The name of a field the panel's queries return, of one of these types. */
|
|
38
|
+
| {
|
|
39
|
+
kind: 'field';
|
|
40
|
+
types: FieldType[];
|
|
41
|
+
};
|
|
42
|
+
export interface PanelOption {
|
|
43
|
+
/** Dotted path in the panel, e.g. "options.legend.showLegend" or "fieldConfig.defaults.custom.lineWidth". */
|
|
44
|
+
path: string;
|
|
45
|
+
label: string;
|
|
46
|
+
category: string;
|
|
47
|
+
help?: string;
|
|
48
|
+
/** What the panel does while it's unset, in the control's terms. */
|
|
49
|
+
default?: unknown;
|
|
50
|
+
control: OptionControl;
|
|
51
|
+
/** Shown only when this holds, e.g. a fixed color only in the fixed color mode. */
|
|
52
|
+
showIf?(panel: Panel): boolean;
|
|
53
|
+
/** For values not stored as the control shows them (e.g. one reducer kept as a one-item array). */
|
|
54
|
+
get?(panel: Panel): unknown;
|
|
55
|
+
set?(panel: Panel, value: unknown): Panel;
|
|
56
|
+
/** The JSON type the stored value must have; defaults from the control. */
|
|
57
|
+
stored?: 'boolean' | 'number' | 'string' | 'string[]' | 'object' | 'list';
|
|
58
|
+
}
|
|
59
|
+
/** Categories in the order the options pane lists them. */
|
|
60
|
+
export declare const OPTION_CATEGORIES: readonly ["Panel", "Value", "Legend", "Graph styles", "Axis", "Table", "Text", "Standard options", "Value mappings", "Thresholds", "Map"];
|
|
61
|
+
/** Units modelform formats specially; anything else formats as "short". `suffix:` and `prefix:` units take any text. */
|
|
62
|
+
export declare const UNIT_CHOICES: {
|
|
63
|
+
label: string;
|
|
64
|
+
value: string;
|
|
65
|
+
}[];
|
|
66
|
+
/** The options a panel type reads, beyond its title, queries and size. Empty for types without any (inputs have their own). */
|
|
67
|
+
export declare function panelOptions(type: string): PanelOption[];
|
|
68
|
+
/** The value at a dotted path, or undefined. */
|
|
69
|
+
export declare function getPath(value: unknown, path: string): unknown;
|
|
70
|
+
/** An option's value as its control shows it. */
|
|
71
|
+
export declare function optionValue(panel: Panel, option: PanelOption): unknown;
|
|
72
|
+
/** Sets an option as its control gives it. Undefined (or '') unsets it. */
|
|
73
|
+
export declare function setOption(panel: Panel, option: PanelOption, value: unknown): Panel;
|
|
74
|
+
/**
|
|
75
|
+
* A copy of the panel with the value at a dotted path set, making objects on the way as
|
|
76
|
+
* needed. Undefined or '' removes it, along with any objects that leaves empty, so clearing a
|
|
77
|
+
* field leaves no trace in the JSON.
|
|
78
|
+
*/
|
|
79
|
+
export declare function setOptionValue(panel: Panel, path: string, value: unknown): Panel;
|
|
80
|
+
/**
|
|
81
|
+
* Removes, in place, option values of the wrong type for what the panel's type reads, and
|
|
82
|
+
* anything on the way to one that isn't an object. Returns where each was, relative to the
|
|
83
|
+
* panel (like `.options.legend.showLegend`), and why.
|
|
84
|
+
*/
|
|
85
|
+
export declare function cleanPanelOptions(panel: Panel): {
|
|
86
|
+
path: string;
|
|
87
|
+
message: string;
|
|
88
|
+
}[];
|
|
89
|
+
/** Grafana's field matchers that modelform applies. Overrides with other matchers are kept but match nothing. */
|
|
90
|
+
export declare const OVERRIDE_MATCHERS: {
|
|
91
|
+
label: string;
|
|
92
|
+
value: string;
|
|
93
|
+
help: string;
|
|
94
|
+
}[];
|
|
95
|
+
export interface OverrideProperty {
|
|
96
|
+
/** The property id, a path into the field's config, e.g. "unit" or "custom.lineWidth". */
|
|
97
|
+
id: string;
|
|
98
|
+
/** How it's edited; its default is the panel's. */
|
|
99
|
+
option: PanelOption;
|
|
100
|
+
/** For values not stored as the control shows them (a fixed color is stored as a color object). */
|
|
101
|
+
get?(value: unknown): unknown;
|
|
102
|
+
set?(value: unknown): unknown;
|
|
103
|
+
}
|
|
104
|
+
/** What an override can set on the fields it matches, for a panel type: its field options, with one Color in place of the color scheme pair. */
|
|
105
|
+
export declare function overrideProperties(type: string): OverrideProperty[];
|
|
106
|
+
/** The panel's overrides, or none. */
|
|
107
|
+
export declare function panelOverrides(panel: Panel): FieldOverride[];
|
|
108
|
+
/** A copy of the panel with its overrides replaced; none removes the key. */
|
|
109
|
+
export declare function setOverrides(panel: Panel, overrides: FieldOverride[]): Panel;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Grafana "calcs" reducers used by stat, gauge, bar gauge and pie panels. */
|
|
2
|
+
export type Reducer = 'last' | 'lastNotNull' | 'first' | 'firstNotNull' | 'mean' | 'sum' | 'min' | 'max' | 'count' | 'delta' | 'range' | 'diff' | 'median' | 'variance' | 'stdDev' | 'distinctCount' | 'changeCount';
|
|
3
|
+
/** Grafana's names for the reducers, as its legends and table footers label them. */
|
|
4
|
+
export declare const REDUCER_LABELS: Record<Reducer, string>;
|
|
5
|
+
export declare const isReducer: (calc: string) => calc is Reducer;
|
|
6
|
+
export declare function reduce(values: (number | null | undefined)[], calc?: string): number | null;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type DataSourceResolver } from './datasource';
|
|
2
|
+
import type { Dashboard, TemplateVariable } from './schema';
|
|
3
|
+
import type { TimeRange } from './time';
|
|
4
|
+
import { type VariableValues, type VarOption } from './variables';
|
|
5
|
+
/**
|
|
6
|
+
* Re-runs query variables against their datasource, the way Grafana does when a dashboard loads,
|
|
7
|
+
* its time range changes, or a variable that others depend on changes.
|
|
8
|
+
*/
|
|
9
|
+
export interface ResolvedVariables {
|
|
10
|
+
values: VariableValues;
|
|
11
|
+
/** Resolved options for every query variable that has been run. */
|
|
12
|
+
options: Record<string, VarOption[]>;
|
|
13
|
+
/** Per-variable failures; those variables keep their previous options. */
|
|
14
|
+
errors: Record<string, string>;
|
|
15
|
+
}
|
|
16
|
+
export interface ResolveOptions {
|
|
17
|
+
/** Current values and previously resolved options; neither is mutated. */
|
|
18
|
+
values: VariableValues;
|
|
19
|
+
options?: Record<string, VarOption[]>;
|
|
20
|
+
/** The variables to re-run. Others are left as they are. */
|
|
21
|
+
names: Iterable<string>;
|
|
22
|
+
resolve: DataSourceResolver;
|
|
23
|
+
range: TimeRange;
|
|
24
|
+
signal?: AbortSignal;
|
|
25
|
+
}
|
|
26
|
+
/** Query variables that Grafana runs on load (`refresh` 1 or 2), or only those run on time range change (`refresh` 2). */
|
|
27
|
+
export declare function refreshedVariables(dashboard: Dashboard, on: 'load' | 'range'): string[];
|
|
28
|
+
/** Every variable whose query refers to one of `names`, directly or through another variable. */
|
|
29
|
+
export declare function variableDependents(dashboard: Dashboard, names: Iterable<string>): Set<string>;
|
|
30
|
+
/**
|
|
31
|
+
* Variables ordered so each comes after the ones its query refers to, keeping
|
|
32
|
+
* `templating.list` order otherwise. Variables in a reference cycle are returned separately.
|
|
33
|
+
*/
|
|
34
|
+
export declare function variableOrder(dashboard: Dashboard): {
|
|
35
|
+
order: TemplateVariable[];
|
|
36
|
+
cyclic: TemplateVariable[];
|
|
37
|
+
};
|
|
38
|
+
export declare function resolveVariables(dashboard: Dashboard, opts: ResolveOptions): Promise<ResolvedVariables>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Made-up entries for previewing a config before anything has been recorded. Each metric gets
|
|
3
|
+
* values shaped by the input that records it (choices for a select, whole stars for a rating,
|
|
4
|
+
* the slider's range, and so on), the same every time for the same metric.
|
|
5
|
+
*/
|
|
6
|
+
import { type NewEntry } from './inputs';
|
|
7
|
+
import type { Dashboard } from './schema';
|
|
8
|
+
/**
|
|
9
|
+
* Entries for each metric over the last `days`, most days having one (counters may have
|
|
10
|
+
* several). Metrics a form records take their shape from its input; any other is a number
|
|
11
|
+
* wandering around 60.
|
|
12
|
+
*/
|
|
13
|
+
export declare function sampleEntries(forms: Dashboard[], metrics: Iterable<string>, now?: number, days?: number): NewEntry[];
|