-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: split API in multiple sub-class (#84)
* refactor: split API in multiple sub-class * docs: use CAUTION blockquote
- Loading branch information
Showing
15 changed files
with
908 additions
and
579 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,8 @@ | |
"parserOptions": { | ||
"sourceType": "module", | ||
"requireConfigFile": false | ||
}, | ||
"rules": { | ||
"func-style": "off" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# Grafana Datasources API | ||
|
||
https://grafana.com/docs/grafana/latest/developers/http_api/data_source/ | ||
|
||
API are accessible from the `Datasources` property. | ||
|
||
```ts | ||
import { GrafanaApi } from "@myunisoft/loki"; | ||
|
||
const api = new GrafanaApi({ | ||
remoteApiURL: "https://name.loki.com" | ||
}); | ||
|
||
await api.Datasources.all(); | ||
``` | ||
|
||
Datasource is described by the following TypeScript interface | ||
```ts | ||
interface Datasource { | ||
id: number; | ||
uid: string; | ||
orgId: number; | ||
name: string; | ||
type: string; | ||
typeName?: string; | ||
typeLogoUrl: string; | ||
access: string; | ||
url: string; | ||
password?: string; | ||
user: string; | ||
database: string; | ||
basicAuth: boolean; | ||
basicAuthUser?: string; | ||
basicAuthPassword?: string; | ||
withCredentials?: boolean; | ||
isDefault: boolean; | ||
jsonData?: { | ||
authType?: string; | ||
defaultRegion?: string; | ||
logLevelField?: string; | ||
logMessageField?: string; | ||
timeField?: string; | ||
maxConcurrentShardRequests?: number; | ||
maxLines?: number; | ||
graphiteVersion?: string; | ||
graphiteType?: string; | ||
}; | ||
secureJsonFields?: { | ||
basicAuthPassword?: boolean; | ||
}; | ||
version?: number; | ||
readOnly: boolean; | ||
} | ||
``` | ||
|
||
## API | ||
|
||
### all(): Promise< Datasource[] > | ||
retrieves all datasources. | ||
|
||
```ts | ||
const datasources = await api.Datasources.all(); | ||
``` | ||
|
||
### byId(id: number | string): Promise< Datasource > | ||
retrieves a single datasource given it's id. | ||
|
||
```ts | ||
const datasource = await api.Datasources.byId(1); | ||
// or | ||
const datasource = await api.Datasources.byId("1"); | ||
``` | ||
|
||
### byName(name: string): Promise< Datasource > | ||
retrieves a single datasource given it's name. | ||
|
||
```ts | ||
const datasource = await api.Datasources.byName("Loki"); | ||
``` | ||
|
||
### byUID(name: string): Promise< Datasource > | ||
retrieves a single datasources given it's uid. | ||
|
||
```ts | ||
const datasource = await api.Datasources.byUID("303030xGz"); | ||
``` | ||
|
||
### idByName(name: string): Promise< Datasource > | ||
retrieves datasource id given it's name. | ||
|
||
```ts | ||
const id = await api.Datasources.idByName("Loki"); | ||
``` |
Oops, something went wrong.