Skip to content

Commit

Permalink
fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
icebob committed Nov 26, 2023
1 parent 696e451 commit f6d97ff
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/loggers/base.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ declare abstract class BaseLogger {
loggerFactory: LoggerFactory;
broker: ServiceBroker;

opts: BaseLogger.LoggerOptions
// opts: BaseLogger.LoggerOptions

init(loggerFactory: LoggerFactory): void;

stop(): void;

getLogLevels(mod: string): BaseLogger.LogLevels | null;
getLogLevel(mod: string): BaseLogger.LogLevels | null;

getLogHandler(bindings: LoggerFactory.LoggerBindings): BaseLogger.LogHandler | null;

Expand Down
7 changes: 3 additions & 4 deletions src/loggers/bunyan.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import LoggerFactory = require("../logger-factory");
import BaseLogger = require("./base");
import type { LoggerOptions } from "./base";

import type { LoggerOptions as BunyanNativeLoggerOptions } from "bunyan";

declare namespace BunyanLogger {

export interface BunyanLoggerOptions extends LoggerOptions {
bunyan?: {
name?: string,
[key: string]: any
}
bunyan?: BunyanNativeLoggerOptions
}
}

Expand Down
12 changes: 3 additions & 9 deletions src/loggers/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@
const FormattedLogger = require("./formatted");
const _ = require("lodash");

const fs = require("fs");
const fs = require("fs").promises;
const path = require("path");
const os = require("os");
const util = require("util");
const { makeDirs } = require("../utils");

const appendFile = util.promisify(fs.appendFile);

/**
* Import types
*
Expand All @@ -41,10 +38,7 @@ class FileLogger extends FormattedLogger {
constructor(opts) {
super(opts);

/**
* @type {FileLoggerOptions}
* @override
*/
/** @type {FileLoggerOptions} */
this.opts = _.defaultsDeep(this.opts, {
folder: "./logs",
filename: "moleculer-{date}.log",
Expand Down Expand Up @@ -157,7 +151,7 @@ class FileLogger extends FormattedLogger {

const buf = rows.join(this.opts.eol) + this.opts.eol;

return appendFile(filename, buf).catch(err => {
return fs.appendFile(filename, buf).catch(err => {
/* istanbul ignore next */
console.debug("Unable to write log file:", filename, err); // eslint-disable-line no-console
});
Expand Down
6 changes: 4 additions & 2 deletions src/loggers/formatted.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { LoggerOptions } from "./base";

declare namespace FormattedLogger {

export type FormatterFunction = (obj: any) => string;
export type FormatterFunction = (type: string, args: any[]) => string[];

export interface FormattedLoggerOptions extends LoggerOptions {
colors?: boolean,
Expand All @@ -19,10 +19,12 @@ declare namespace FormattedLogger {
declare class FormattedLogger extends BaseLogger {
constructor(opts?: FormattedLogger.FormattedLoggerOptions);

opts: FormattedLogger.FormattedLoggerOptions;
// opts: FormattedLogger.FormattedLoggerOptions;

init(loggerFactory: LoggerFactory): void;
getLogHandler(bindings: LoggerFactory.LoggerBindings): BaseLogger.LogHandler | null;
getFormatter(bindings: LoggerFactory.LoggerBindings) : FormattedLogger.FormatterFunction;
render(str: string, obj: Record<string, any>): string;
}

export = FormattedLogger;
3 changes: 2 additions & 1 deletion src/loggers/log4js.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import LoggerFactory = require("../logger-factory");

import BaseLogger = require("./base");
import type { LoggerOptions } from "./base";
import type { Configuration } from "log4js";

declare namespace Log4jsLogger {

export interface Log4jsLoggerOptions extends LoggerOptions {
log4js?: Record<string, any>
log4js?: Configuration
}
}

Expand Down
1 change: 1 addition & 0 deletions src/middlewares/transmit/compression.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const { promisify } = require("util");
* This is a transmission compression middleware. It supports
* the `deflate`, `deflateRaw` & `gzip` compression methods.
*
* @param {object} opts
* @param {String?} opts.method
* @param {String|Number} opts.threshold
*/
Expand Down
2 changes: 1 addition & 1 deletion src/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export declare function dotSet<T extends object>(obj: T, path: string, value: un

export declare function makeDirs(path: string): void;

export declare function parseByteString(value: string): number;
export declare function parseByteString(value: string|number): number;

export declare function uniq(arr: Array<String|Number>): Array<String|Number>;

Expand Down
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ const utils = {
* Parse a byte string to number of bytes. E.g "1kb" -> 1024
* Credits: https://github.com/visionmedia/bytes.js
*
* @param {String} v
* @param {String|number} v
* @returns {Number|null}
*/
parseByteString(v) {
Expand Down

0 comments on commit f6d97ff

Please sign in to comment.