From 935c12aa69d46e68bfa126a49116e904c4e0f566 Mon Sep 17 00:00:00 2001 From: Gajus Kuizinas Date: Fri, 5 Nov 2021 18:51:33 -0600 Subject: [PATCH] feat: simplify LogWriter interface --- src/factories/createNodeWriter.ts | 6 ++---- src/factories/createRoarrInitialGlobalState.ts | 4 +++- src/types.ts | 7 +++---- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/factories/createNodeWriter.ts b/src/factories/createNodeWriter.ts index e92e824..1f93351 100644 --- a/src/factories/createNodeWriter.ts +++ b/src/factories/createNodeWriter.ts @@ -3,10 +3,8 @@ import type { } from '../types'; const createBlockingWriter = (stream: NodeJS.WritableStream): LogWriter => { - return { - write: (message: string) => { - stream.write(message + '\n'); - }, + return (message: string) => { + stream.write(message + '\n'); }; }; diff --git a/src/factories/createRoarrInitialGlobalState.ts b/src/factories/createRoarrInitialGlobalState.ts index 303d773..0f40edc 100644 --- a/src/factories/createRoarrInitialGlobalState.ts +++ b/src/factories/createRoarrInitialGlobalState.ts @@ -39,7 +39,9 @@ export const createRoarrInitialGlobalState = (currentState: any): RoarrGlobalSta newState = { ...newState, - ...createNodeWriter(), + ...{ + write: createNodeWriter(), + }, asyncLocalStorage, }; // eslint-disable-next-line no-empty diff --git a/src/types.ts b/src/types.ts index 238ea09..8443ecd 100644 --- a/src/types.ts +++ b/src/types.ts @@ -2,16 +2,15 @@ import type { AsyncLocalStorage, } from 'async_hooks'; -export type LogWriter = { - write: (message: string) => void, -}; +export type LogWriter = (message: string) => void; export type MessageContext = any; -export type RoarrGlobalState = LogWriter & { +export type RoarrGlobalState = { asyncLocalStorage?: AsyncLocalStorage, sequence: number, versions: readonly string[], + write: LogWriter, }; export type SprintfArgument = boolean | number | string | null;