-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
204 additions
and
11 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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
node_modules/ | ||
|
||
dist/ | ||
|
||
config.json |
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,11 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Datadata SDK Javascript</title> | ||
</head> | ||
<body> | ||
<script type="module" src="./src/main.ts"></script> | ||
</body> | ||
</html> |
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export * from "./api-key"; | ||
export * from "./api-key.interface"; | ||
export * from "./api-key.service"; | ||
export * from "./api-token-payload"; | ||
export * from "./api-token-payload.interface"; | ||
export * from "./crypto"; |
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,31 @@ | ||
export interface Chart { | ||
id: string; | ||
name: string; | ||
tags: string[]; | ||
createdAt: string; | ||
updatedAt: string; | ||
description?: string; | ||
datasetQuery: DatasetQuery; | ||
visualizationSettings: any; | ||
} | ||
|
||
export interface DatasetQuery { | ||
type: "native"; | ||
native: { | ||
query: string; | ||
}; | ||
dataSourceId: string; | ||
} | ||
|
||
export type GetChartsParams = { | ||
tag?: Array<string>; | ||
sort?: "name:asc" | "name:desc" | "create_at:asc" | "create_at:desc" | "updated_at:asc" | "updated_at:desc"; | ||
limit?: number; | ||
offset?: number; | ||
keyword?: string; | ||
archived?: boolean; | ||
}; | ||
|
||
export type CreateChartBody = Pick<Chart, "name" | "description" | "datasetQuery" | "visualizationSettings">; | ||
|
||
export type UpdateChartBody = Pick<Chart, "name" | "description" | "datasetQuery" | "visualizationSettings">; |
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,56 @@ | ||
import { BaseService, type PaginatedData } from "../common"; | ||
import type { Chart, CreateChartBody, GetChartsParams, UpdateChartBody } from "./chart.interface"; | ||
|
||
/** | ||
* Chart 相关 Rest API 接口 | ||
*/ | ||
export class ChartService extends BaseService { | ||
/** | ||
* 分页获取当前用户的 Chart 资源 | ||
*/ | ||
public getCharts(params?: GetChartsParams, signal?: AbortSignal) { | ||
return this.http.get<PaginatedData<Chart>>(`/api/v1/charts`, { params, signal }); | ||
} | ||
|
||
/** | ||
* 创建 Chart 资源 | ||
*/ | ||
public createChart(body: CreateChartBody) { | ||
return this.http.post<Chart>(`/api/v1/charts`, body); | ||
} | ||
|
||
/** | ||
* 获取指定 Chart 资源 | ||
*/ | ||
public getChart(id: string, signal?: AbortSignal) { | ||
return this.http.get<Chart>(`/api/v1/charts/${id}`, { signal }); | ||
} | ||
|
||
/** | ||
* 更新指定 Chart 资源 | ||
*/ | ||
public updateChart(id: string, body: UpdateChartBody) { | ||
return this.http.put<Chart>(`/api/v1/charts/${id}`, body); | ||
} | ||
|
||
/** | ||
* 归档指定 Chart 资源 | ||
*/ | ||
public deleteChart(id: string) { | ||
return this.http.delete<void>(`/api/v1/charts/${id}`); | ||
} | ||
|
||
/** | ||
* 分页获取子用户的 Chart 资源,通过 API-Token 中的 UID 区分子用户 | ||
*/ | ||
public getSubUserCharts(params?: GetChartsParams, signal?: AbortSignal) { | ||
return this.http.get<PaginatedData<Chart>>(`/api/v1/charts/by-uid`, { params, signal }); | ||
} | ||
|
||
/** | ||
* 分页获取指定子用户的 Chart 资源 | ||
*/ | ||
public getChartsByUID(uid: string, params?: GetChartsParams, signal?: AbortSignal) { | ||
return this.http.get<PaginatedData<Chart>>(`/api/v1/charts/uid/${uid}`, { params, signal }); | ||
} | ||
} |
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,2 @@ | ||
export * from "./chart.interface"; | ||
export * from "./chart.service"; |
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 |
---|---|---|
@@ -1,9 +1,19 @@ | ||
import axios, { type AxiosInstance } from "axios"; | ||
|
||
export type BaseServiceOptions = { | ||
token: string; | ||
baseURL: string; | ||
}; | ||
|
||
export class BaseService { | ||
public http: AxiosInstance; | ||
|
||
constructor() { | ||
this.http = axios.create(); | ||
constructor(public readonly options: BaseServiceOptions) { | ||
this.http = axios.create({ | ||
baseURL: options.baseURL, | ||
headers: { | ||
"x-datadata-api-token": options.token, | ||
}, | ||
}); | ||
} | ||
} |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./base-service"; | ||
export * from "./paginated-data.interface"; |
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,4 @@ | ||
export interface PaginatedData<T> { | ||
count: number; | ||
data: T[]; | ||
} |
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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
export * from "./common"; | ||
|
||
export * from "./api-key"; | ||
export * from "./chart"; | ||
export * from "./query"; | ||
|
||
export * from "./services"; |
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 @@ | ||
export * from "./query.service"; |
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,3 @@ | ||
import { BaseService } from "../common"; | ||
|
||
export class QueryService extends BaseService {} |
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 |
---|---|---|
@@ -1,11 +1,15 @@ | ||
import { APIKeyService } from "./api-key"; | ||
import { ChartService } from "./chart"; | ||
import type { BaseServiceOptions } from "./common"; | ||
import { QueryService } from "./query"; | ||
|
||
export type CreateServicesOptions = { | ||
token: string; | ||
}; | ||
export const BASE_URL_CN = "https://www.datadata.cn"; | ||
export const BASE_URL_GLOBAL = "https://www.datadata.com"; | ||
|
||
export function createServices(options: CreateServicesOptions) { | ||
export function createServices(options: BaseServiceOptions) { | ||
return { | ||
apiKey: new APIKeyService(), | ||
apiKey: new APIKeyService(options), | ||
chart: new ChartService(options), | ||
query: new QueryService(options), | ||
}; | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,13 @@ | ||
import { BASE_URL_CN, createServices } from "@lib"; | ||
import Config from "../config.json"; | ||
|
||
async function main() { | ||
const services = createServices({ | ||
token: Config.apiToken, | ||
baseURL: BASE_URL_CN, | ||
}); | ||
|
||
console.log(services); | ||
} | ||
|
||
main().catch((err) => console.error(err)); |
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