From 3590ba048de86fbf3ffe1215f1e68130202a1682 Mon Sep 17 00:00:00 2001 From: baldo Date: Fri, 17 Jun 2022 15:30:29 +0200 Subject: [PATCH] More types refactoring. --- server/types/shared.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/server/types/shared.ts b/server/types/shared.ts index 4b61d15..b1676bb 100644 --- a/server/types/shared.ts +++ b/server/types/shared.ts @@ -19,6 +19,10 @@ export function isArray(arg: unknown, isT: TypeGuard): arg is Array { return true; } +export function isMap(arg: unknown): arg is Map { + return arg instanceof Map; +} + export function isString(arg: unknown): arg is string { return typeof arg === "string" } @@ -333,8 +337,20 @@ export interface NodesFilter { hasKey?: boolean; hasCoords?: boolean; monitoringState?: MonitoringState; + site?: Site; + domain?: Domain; + onlineState?: OnlineState; } +export const NODES_FILTER_FIELDS = { + hasKey: Boolean, + hasCoords: Boolean, + monitoringState: MonitoringState, + site: String, + domain: String, + onlineState: OnlineState, +}; + export function isNodesFilter(arg: unknown): arg is NodesFilter { if (!isObject(arg)) { return false; @@ -343,6 +359,9 @@ export function isNodesFilter(arg: unknown): arg is NodesFilter { return ( isOptional(filter.hasKey, isBoolean) && isOptional(filter.hasCoords, isBoolean) && - isOptional(filter.monitoringState, isMonitoringState) + isOptional(filter.monitoringState, isMonitoringState) && + isOptional(filter.site, isSite) && + isOptional(filter.domain, isDomain) && + isOptional(filter.onlineState, isOnlineState) ); }