Add typing for serialized collector type

Setup TypeScript tyings and JSON schema for serializeResult and
deserializeResult and use these in the metrics related requests.
This commit is contained in:
Hornwitser committed 2023-11-19 04:50:07 +01:00
1 parent b66138587b
commit b78ca31b09
7 files changed
+46 -26

No files matched your search

+3 -2
View File
@@ -1,5 +1,6 @@
import { Type, Static } from "@sinclair/typebox";
import { jsonArray, StringEnum } from "./composites";
import { CollectorResultSerialized } from "../prometheus";
export class HostDetails {
constructor(
@@ -75,11 +76,11 @@ export class HostMetricsRequest {
static dst = "host" as const;
static Response = class Response { // TODO: Use JSON class pattern in Prometheus
constructor(
public results: object[],
public results: CollectorResultSerialized[],
) { }
static jsonSchema = Type.Object({
"results": Type.Array(Type.Object({})),
"results": Type.Array(CollectorResultSerialized),
});
static fromJSON(json: Static<typeof this.jsonSchema>) {
+3 -3
View File
@@ -4,7 +4,7 @@ import { JsonString, StringEnum, jsonArray } from "./composites";
import { RawConfig } from "../config";
import type { User } from "../users";
import type { MessageRequest } from "./messages_core";
import type { SerializedConfig } from "../config";
import { CollectorResultSerialized } from "../prometheus";
export type InstanceStatus =
@@ -216,11 +216,11 @@ export class InstanceMetricsRequest {
static Response = class Response { // TODO: Use JSON class pattern in Prometheus
constructor(
public results: object[],
public results: CollectorResultSerialized[],
) { }
static jsonSchema = Type.Object({
"results": Type.Array(Type.Object({})),
"results": Type.Array(CollectorResultSerialized),
});
static fromJSON(json: Static<typeof this.jsonSchema>) {