Skip to content

Commit

Permalink
renames + jsdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
mmkal committed May 26, 2024
1 parent 827827e commit d555355
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
6 changes: 2 additions & 4 deletions src/logging.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {LogMethod as LogFn, Logger} from './types'
import {Log, Logger} from './types'

export const lineByLineLogger = getLoggerTransformer(log => {
/**
Expand All @@ -25,10 +25,8 @@ const isPrimitive = (value: unknown): value is string | number | boolean => {
return type === 'string' || type === 'number' || type === 'boolean'
}

type TransformLogMethod = (log: LogFn) => LogFn

/** Takes a function that wraps an individual log function, and returns a function that wraps the `info` and `error` functions for a logger */
function getLoggerTransformer(transform: TransformLogMethod) {
function getLoggerTransformer(transform: (log: Log) => Log) {
return (logger: Logger): Logger => {
const info = logger.info && transform(logger.info)
const error = logger.error && transform(logger.error)
Expand Down
13 changes: 9 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,19 @@ export interface ParsedProcedure {
* Function for taking cleye parsed argv output and transforming it so it can be passed into the procedure
* Needed because this function is where inspect the input schema(s) and determine how to map the argv to the input
*/
getInput: (argv: {_: string[]; flags: {}}) => unknown
getInput: (argv: {_: string[]; flags: Record<string, unknown>}) => unknown
}

export type Result<T> = {success: true; value: T} | {success: false; error: string}

export type LogMethod = (...args: unknown[]) => void
/** A function that logs any inputs. e.g. `console.info` */
export type Log = (...args: unknown[]) => void

/**
* A struct which has `info` and `error` functions for logging. Easiest example: `console`
* But most loggers like pino, winston etc. have a similar interface.
*/
export interface Logger {
info?: LogMethod
error?: LogMethod
info?: Log
error?: Log
}

0 comments on commit d555355

Please sign in to comment.