@wide-events/client 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.
- package/LICENSE +6 -0
- package/README.md +18 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +51 -0
- package/dist/index.js.map +1 -0
- package/package.json +31 -0
package/LICENSE
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# @wide-events/client
|
|
2
|
+
|
|
3
|
+
Typed HTTP client for the Wide Events collector query APIs.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @wide-events/client
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { WideEventsClient } from "@wide-events/client";
|
|
15
|
+
|
|
16
|
+
const client = new WideEventsClient({ url: "http://localhost:4318" });
|
|
17
|
+
const columns = await client.getColumns();
|
|
18
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ColumnInfo, QueryResult, StructuredQuery, TraceResult } from "@wide-events/internal";
|
|
2
|
+
export interface WideEventsClientOptions {
|
|
3
|
+
url: string;
|
|
4
|
+
fetchImpl?: typeof fetch;
|
|
5
|
+
}
|
|
6
|
+
export declare class WideEventsClient {
|
|
7
|
+
private readonly baseUrl;
|
|
8
|
+
private readonly fetchImpl;
|
|
9
|
+
constructor(options: WideEventsClientOptions);
|
|
10
|
+
query(request: StructuredQuery): Promise<QueryResult>;
|
|
11
|
+
sql(sql: string): Promise<QueryResult>;
|
|
12
|
+
getColumns(): Promise<ColumnInfo[]>;
|
|
13
|
+
getTrace(traceId: string): Promise<TraceResult>;
|
|
14
|
+
private getJson;
|
|
15
|
+
private postJson;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,WAAW,EACX,eAAe,EACf,WAAW,EACZ,MAAM,uBAAuB,CAAC;AAE/B,MAAM,WAAW,uBAAuB;IACtC,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;CAC1B;AAMD,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAe;gBAE7B,OAAO,EAAE,uBAAuB;IAKtC,KAAK,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;IAIrD,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAItC,UAAU,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;IAKnC,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;YAIvC,OAAO;YAKP,QAAQ;CAavB"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export class WideEventsClient {
|
|
2
|
+
baseUrl;
|
|
3
|
+
fetchImpl;
|
|
4
|
+
constructor(options) {
|
|
5
|
+
this.baseUrl = options.url.replace(/\/$/u, "");
|
|
6
|
+
this.fetchImpl = options.fetchImpl ?? fetch;
|
|
7
|
+
}
|
|
8
|
+
async query(request) {
|
|
9
|
+
return await this.postJson("/query", request);
|
|
10
|
+
}
|
|
11
|
+
async sql(sql) {
|
|
12
|
+
return await this.postJson("/sql", { sql });
|
|
13
|
+
}
|
|
14
|
+
async getColumns() {
|
|
15
|
+
const response = await this.getJson("/columns");
|
|
16
|
+
return response.columns;
|
|
17
|
+
}
|
|
18
|
+
async getTrace(traceId) {
|
|
19
|
+
return await this.getJson(`/trace/${encodeURIComponent(traceId)}`);
|
|
20
|
+
}
|
|
21
|
+
async getJson(path) {
|
|
22
|
+
const response = await this.fetchImpl(`${this.baseUrl}${path}`);
|
|
23
|
+
return await readJsonResponse(response);
|
|
24
|
+
}
|
|
25
|
+
async postJson(path, body) {
|
|
26
|
+
const response = await this.fetchImpl(`${this.baseUrl}${path}`, {
|
|
27
|
+
method: "POST",
|
|
28
|
+
headers: {
|
|
29
|
+
"content-type": "application/json"
|
|
30
|
+
},
|
|
31
|
+
body: JSON.stringify(body)
|
|
32
|
+
});
|
|
33
|
+
return await readJsonResponse(response);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async function readJsonResponse(response) {
|
|
37
|
+
if (!response.ok) {
|
|
38
|
+
const payload = await response
|
|
39
|
+
.json()
|
|
40
|
+
.catch(async () => ({ error: await response.text() }));
|
|
41
|
+
const message = payload &&
|
|
42
|
+
typeof payload === "object" &&
|
|
43
|
+
"error" in payload &&
|
|
44
|
+
typeof payload.error === "string"
|
|
45
|
+
? payload.error
|
|
46
|
+
: `HTTP ${response.status}`;
|
|
47
|
+
throw new Error(message);
|
|
48
|
+
}
|
|
49
|
+
return (await response.json());
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAgBA,MAAM,OAAO,gBAAgB;IACV,OAAO,CAAS;IAChB,SAAS,CAAe;IAEzC,YAAY,OAAgC;QAC1C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAC/C,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,KAAK,CAAC;IAC9C,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,OAAwB;QAClC,OAAO,MAAM,IAAI,CAAC,QAAQ,CAAc,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC7D,CAAC;IAED,KAA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,EAAE,CAAC,CAAC,CAAC;QACzD,MAAM,OAAO,GACX,OAAO;YACP,OAAO,OAAO,KAAK,QAAQ;YAC3B,OAAO,IAAI,OAAO;YAClB,OAAO,OAAO,CAAC,KAAK,KAAK,QAAQ;YAC/B,CAAC,CAAC,OAAO,CAAC,KAAK;YACf,CAAC,CAAC,QAAQ,QAAQ,CAAC,MAAM,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;IAED,OAAO,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAc,CAAC;AAC9C,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wide-events/client",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "AGPL-3.0-only",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"README.md",
|
|
21
|
+
"LICENSE"
|
|
22
|
+
],
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@wide-events/internal": "0.1.0"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsc -p tsconfig.json",
|
|
28
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
29
|
+
"clean": "rm -rf dist tsconfig.tsbuildinfo"
|
|
30
|
+
}
|
|
31
|
+
}
|