Initial setup for new frontend.

This commit is contained in:
baldo 2022-02-22 15:39:39 +01:00
parent 7671bfd4d3
commit 59f7897d8e
33 changed files with 2594 additions and 12 deletions
server/types

45
server/types/shared.ts Normal file
View file

@ -0,0 +1,45 @@
// Types shared with the client.
export function isObject(arg: unknown): arg is object {
return arg !== null && typeof arg === "object";
}
export type Version = string;
export function isVersion(arg: unknown): arg is Version {
// Should be good enough for now.
return typeof arg === "string";
}
export type NodeStatistics = {
registered: number;
withVPN: number;
withCoords: number;
monitoring: {
active: number;
pending: number;
};
};
export function isNodeStatistics(arg: unknown): arg is NodeStatistics {
if (!isObject(arg)) {
return false;
}
const stats = arg as NodeStatistics;
return (
typeof stats.registered === "number" &&
typeof stats.withVPN === "number" &&
typeof stats.withCoords === "number" &&
typeof stats.monitoring === "object" &&
typeof stats.monitoring.active === "number" &&
typeof stats.monitoring.pending === "number"
);
}
export interface Statistics {
nodes: NodeStatistics;
}
export function isStatistics(arg: unknown): arg is Statistics {
return isObject(arg) && isNodeStatistics((arg as Statistics).nodes);
}