54 lines
1.1 KiB
TypeScript
Raw Normal View History

2024-08-15 12:08:51 +02:00
import { Api } from "../api/config";
import { CodexValibotIssuesMap } from "../errors/errors";
import { Fetch } from "../fetch-safe/fetch-safe";
2024-08-30 12:24:00 +02:00
import type { SafeValue } from "../values/values";
2024-08-15 12:08:51 +02:00
import { CodexLogLevel, type CodexDebugInfo } from "./types";
import * as v from "valibot";
export class Debug {
readonly url: string;
constructor(url: string) {
this.url = url;
}
/**
* Set log level at run time
*/
2024-08-30 12:24:00 +02:00
setLogLevel(level: CodexLogLevel): Promise<SafeValue<Response>> {
2024-08-15 12:08:51 +02:00
const result = v.safeParse(CodexLogLevel, level);
if (!result.success) {
2024-08-30 12:24:00 +02:00
return Promise.resolve({
2024-08-15 12:08:51 +02:00
error: true,
data: {
message: "Cannot validate the input",
errors: CodexValibotIssuesMap(result.issues),
},
2024-08-30 12:24:00 +02:00
});
2024-08-15 12:08:51 +02:00
}
const url =
this.url +
Api.config.prefix +
"/debug/chronicles/loglevel?level=" +
level;
return Fetch.safe(url, {
method: "POST",
body: "",
});
}
/**
* Gets node information
*/
info() {
const url = this.url + Api.config.prefix + `/debug/info`;
return Fetch.safeJson<CodexDebugInfo>(url, {
method: "GET",
});
}
}