From e08ae944c48c0006811115e1595bf2b51f8bae13 Mon Sep 17 00:00:00 2001 From: baldo Date: Tue, 6 Sep 2022 17:43:00 +0200 Subject: [PATCH] Move node types into own module to keep index.ts clean. --- server/types/index.ts | 92 +------------------------------------------ server/types/node.ts | 90 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 91 deletions(-) create mode 100644 server/types/node.ts diff --git a/server/types/index.ts b/server/types/index.ts index cba4a55..9b4ba79 100644 --- a/server/types/index.ts +++ b/server/types/index.ts @@ -1,95 +1,5 @@ -import { - CreateOrUpdateNode, - Domain, - DomainSpecificNodeResponse, - MonitoringResponse, - MonitoringState, - MonitoringToken, - NodeResponse, - NodeTokenResponse, - OnlineState, - Site, - StoredNode, -} from "../shared/types"; - export * from "./config"; export * from "./database"; export * from "./logger"; +export * from "./node"; export * from "../shared/types"; - -export type NodeStateData = { - site?: Site; - domain?: Domain; - state: OnlineState; -}; - -export function toCreateOrUpdateNode(node: StoredNode): CreateOrUpdateNode { - return { - nickname: node.nickname, - email: node.email, - hostname: node.hostname, - coords: node.coords, - key: node.key, - mac: node.mac, - monitoring: node.monitoringState !== MonitoringState.DISABLED, - }; -} - -export function toNodeResponse(node: StoredNode): NodeResponse { - return { - token: node.token, - nickname: node.nickname, - email: node.email, - hostname: node.hostname, - coords: node.coords, - key: node.key, - mac: node.mac, - monitoring: node.monitoringState !== MonitoringState.DISABLED, - monitoringConfirmed: node.monitoringState === MonitoringState.ACTIVE, - monitoringState: node.monitoringState, - modifiedAt: node.modifiedAt, - }; -} - -export function toNodeTokenResponse(node: StoredNode): NodeTokenResponse { - return { - token: node.token, - node: toNodeResponse(node), - }; -} - -export function toDomainSpecificNodeResponse( - node: StoredNode, - nodeStateData: NodeStateData -): DomainSpecificNodeResponse { - return { - token: node.token, - nickname: node.nickname, - email: node.email, - hostname: node.hostname, - coords: node.coords, - key: node.key, - mac: node.mac, - monitoring: node.monitoringState !== MonitoringState.DISABLED, - monitoringConfirmed: node.monitoringState === MonitoringState.ACTIVE, - monitoringState: node.monitoringState, - modifiedAt: node.modifiedAt, - site: nodeStateData.site, - domain: nodeStateData.domain, - onlineState: nodeStateData.state, - }; -} - -export function toMonitoringResponse(node: StoredNode): MonitoringResponse { - return { - hostname: node.hostname, - mac: node.mac, - email: node.email, - monitoring: node.monitoringState !== MonitoringState.DISABLED, - monitoringConfirmed: node.monitoringState === MonitoringState.ACTIVE, - }; -} - -export type NodeSecrets = { - monitoringToken?: MonitoringToken; -}; diff --git a/server/types/node.ts b/server/types/node.ts new file mode 100644 index 0000000..d0dbdc8 --- /dev/null +++ b/server/types/node.ts @@ -0,0 +1,90 @@ +import { + CreateOrUpdateNode, + Domain, + DomainSpecificNodeResponse, + MonitoringResponse, + MonitoringState, + MonitoringToken, + NodeResponse, + NodeTokenResponse, + OnlineState, + Site, + StoredNode, +} from "../shared/types"; + +export type NodeStateData = { + site?: Site; + domain?: Domain; + state: OnlineState; +}; + +export function toCreateOrUpdateNode(node: StoredNode): CreateOrUpdateNode { + return { + nickname: node.nickname, + email: node.email, + hostname: node.hostname, + coords: node.coords, + key: node.key, + mac: node.mac, + monitoring: node.monitoringState !== MonitoringState.DISABLED, + }; +} + +export function toNodeResponse(node: StoredNode): NodeResponse { + return { + token: node.token, + nickname: node.nickname, + email: node.email, + hostname: node.hostname, + coords: node.coords, + key: node.key, + mac: node.mac, + monitoring: node.monitoringState !== MonitoringState.DISABLED, + monitoringConfirmed: node.monitoringState === MonitoringState.ACTIVE, + monitoringState: node.monitoringState, + modifiedAt: node.modifiedAt, + }; +} + +export function toNodeTokenResponse(node: StoredNode): NodeTokenResponse { + return { + token: node.token, + node: toNodeResponse(node), + }; +} + +export function toDomainSpecificNodeResponse( + node: StoredNode, + nodeStateData: NodeStateData +): DomainSpecificNodeResponse { + return { + token: node.token, + nickname: node.nickname, + email: node.email, + hostname: node.hostname, + coords: node.coords, + key: node.key, + mac: node.mac, + monitoring: node.monitoringState !== MonitoringState.DISABLED, + monitoringConfirmed: node.monitoringState === MonitoringState.ACTIVE, + monitoringState: node.monitoringState, + modifiedAt: node.modifiedAt, + site: nodeStateData.site, + domain: nodeStateData.domain, + onlineState: nodeStateData.state, + }; +} + +export function toMonitoringResponse(node: StoredNode): MonitoringResponse { + return { + hostname: node.hostname, + mac: node.mac, + email: node.email, + monitoring: node.monitoringState !== MonitoringState.DISABLED, + monitoringConfirmed: node.monitoringState === MonitoringState.ACTIVE, + }; +} + +export type NodeSecrets = { + monitoringToken?: MonitoringToken; +};