Skip to content

Commit

Permalink
format d.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
icebob committed Dec 9, 2023
1 parent 3fbadeb commit 6e9a91b
Show file tree
Hide file tree
Showing 83 changed files with 427 additions and 365 deletions.
2 changes: 1 addition & 1 deletion src/cachers/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ export {
RedisCacher as Redis
};

export declare function resolve(opt: Record<string,any>|string|boolean): Cacher;
export declare function resolve(opt: Record<string, any> | string | boolean): Cacher;
export declare function register(name: string, value: Cacher): void;
1 change: 0 additions & 1 deletion src/cachers/redis.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ declare class RedisCacher<TClient = any> extends BaseCacher {
clean(match?: string | string[]): Promise<unknown>;
tryLock(key: string | string[], ttl?: number): Promise<() => Promise<void>>;
lock(key: string | string[], ttl?: number): Promise<() => Promise<void>>;

}

export = RedisCacher;
24 changes: 16 additions & 8 deletions src/context.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,31 @@ import { Stream } from "stream";
import util = require("util");

declare namespace Context {

export interface ContextParentSpan {
id: string;
traceID: string;
sampled: boolean;
}
}

declare class Context<TParams = unknown, TMeta extends object = {}, TLocals = Record<string, any>, THeaders = Record<string, any>> {
declare class Context<
TParams = unknown,
TMeta extends object = {},
TLocals = Record<string, any>,
THeaders = Record<string, any>
> {
static create(
broker: ServiceBroker,
endpoint: ActionEndpoint|EventEndpoint,
endpoint: ActionEndpoint | EventEndpoint,
params: Record<string, any>,
opts: Record<string, any>
): Context;
static create(broker: ServiceBroker, endpoint: ActionEndpoint|EventEndpoint, params: Record<string, any>): Context;
static create(broker: ServiceBroker, endpoint: ActionEndpoint|EventEndpoint): Context;
static create(
broker: ServiceBroker,
endpoint: ActionEndpoint | EventEndpoint,
params: Record<string, any>
): Context;
static create(broker: ServiceBroker, endpoint: ActionEndpoint | EventEndpoint): Context;
static create(broker: ServiceBroker): Context;

id: string;
Expand Down Expand Up @@ -80,9 +88,9 @@ declare class Context<TParams = unknown, TMeta extends object = {}, TLocals = Re

cachedResult: boolean;

constructor(broker: ServiceBroker, endpoint?: ActionEndpoint|EventEndpoint);
constructor(broker: ServiceBroker, endpoint?: ActionEndpoint | EventEndpoint);

setEndpoint(endpoint: ActionEndpoint|EventEndpoint): void;
setEndpoint(endpoint: ActionEndpoint | EventEndpoint): void;

setParams(newParams: TParams, cloning?: boolean): void;

Expand All @@ -105,7 +113,7 @@ declare class Context<TParams = unknown, TMeta extends object = {}, TLocals = Re
broadcast<D>(eventName: string, data: D, opts?: Record<string, any>): Promise<void>;
broadcast(eventName: string): Promise<void>;

copy(endpoint: ActionEndpoint|EventEndpoint): this;
copy(endpoint: ActionEndpoint | EventEndpoint): this;
copy(): this;

startSpan(name: string, opts?: Record<string, any>): Span;
Expand Down
13 changes: 7 additions & 6 deletions src/errors.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,15 @@ export declare class Regenerator {

extractPlainError(err: Record<string, any>, payload?: Record<string, any>): PlainMoleculerError;

restoreCustomError(
plainError: PlainMoleculerError,
payload: Record<string, any>
): Error;
restoreCustomError(plainError: PlainMoleculerError, payload: Record<string, any>): Error;

private _createDefaultError(plainError: PlainMoleculerError): Error;
private _restoreExternalFields(plainError: PlainMoleculerError, err: PlainMoleculerError, payload: Record<string, any>): void;
private _restoreExternalFields(
plainError: PlainMoleculerError,
err: PlainMoleculerError,
payload: Record<string, any>
): void;
private _restoreStack(plainError: PlainMoleculerError, err: Error): void;
}

export declare function resolveRegenerator(opts?: Regenerator): Regenerator
export declare function resolveRegenerator(opts?: Regenerator): Regenerator;
6 changes: 3 additions & 3 deletions src/loggers/base.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ declare namespace BaseLogger {

export interface LoggerOptions {
level?: LogLevels;
createLogger?: Function
createLogger?: Function;
}

// export const BaseLogger;
Expand All @@ -17,8 +17,8 @@ declare namespace BaseLogger {
declare abstract class BaseLogger<T extends BaseLogger.LoggerOptions> {
constructor(opts?: T);

loggerFactory: LoggerFactory;
broker: ServiceBroker;
loggerFactory: LoggerFactory;
broker: ServiceBroker;

opts: T;

Expand Down
3 changes: 1 addition & 2 deletions src/loggers/bunyan.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import type { LoggerOptions } from "./base";
import type { LoggerOptions as BunyanNativeLoggerOptions } from "bunyan";

declare namespace BunyanLogger {

export interface BunyanLoggerOptions extends LoggerOptions {
bunyan?: BunyanNativeLoggerOptions
bunyan?: BunyanNativeLoggerOptions;
}
}

Expand Down
1 change: 0 additions & 1 deletion src/loggers/console.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import FormattedLogger = require("./formatted");
import type { FormattedLoggerOptions } from "./formatted";

declare namespace ConsoleLogger {

export interface ConsoleLoggerOptions extends FormattedLoggerOptions {}
}

Expand Down
16 changes: 7 additions & 9 deletions src/loggers/datadog.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ import BaseLogger = require("./base");
import type { LoggerOptions } from "./base";

declare namespace DatadogLogger {

export interface DatadogLoggerOptions extends LoggerOptions {
url?: string,
apiKey?: string,
ddSource?: string,
env?: string,
hostname?: string,
objectPrinter?: (obj: any) => string,
interval?: number

url?: string;
apiKey?: string;
ddSource?: string;
env?: string;
hostname?: string;
objectPrinter?: (obj: any) => string;
interval?: number;
}
}

Expand Down
1 change: 0 additions & 1 deletion src/loggers/debug.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import BaseLogger = require("./base");
import type { LoggerOptions } from "./base";

declare namespace DebugLogger {

export interface DebugLoggerOptions extends LoggerOptions {}
}

Expand Down
9 changes: 4 additions & 5 deletions src/loggers/file.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import FormattedLogger = require("./formatted");
import type { FormattedLoggerOptions } from "./formatted";

declare namespace FileLogger {

export interface FileLoggerOptions extends FormattedLoggerOptions {
folder?: string,
filename?: string,
eol?: string,
interval?: number
folder?: string;
filename?: string;
eol?: string;
interval?: number;
}
}

Expand Down
17 changes: 9 additions & 8 deletions src/loggers/formatted.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@ import BaseLogger = require("./base");
import type { LoggerOptions } from "./base";

declare namespace FormattedLogger {

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

export interface FormattedLoggerOptions extends LoggerOptions {
colors?: boolean,
moduleColors?: boolean|string[],
formatter?: FormatterFunction|"json"|"jsonext"|"simple"|"short"|"full",
objectPrinter?: (obj: any) => string,
autoPadding?: boolean
colors?: boolean;
moduleColors?: boolean | string[];
formatter?: FormatterFunction | "json" | "jsonext" | "simple" | "short" | "full";
objectPrinter?: (obj: any) => string;
autoPadding?: boolean;
}
}

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

Expand Down
3 changes: 1 addition & 2 deletions src/loggers/log4js.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import type { LoggerOptions } from "./base";
import type { Configuration } from "log4js";

declare namespace Log4jsLogger {

export interface Log4jsLoggerOptions extends LoggerOptions {
log4js?: Configuration
log4js?: Configuration;
}
}

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

declare namespace PinoLogger {

export interface PinoLoggerOptions extends LoggerOptions {
pino?: {
options: Record<string, any>,
destination: Record<string, any>,
}
options: Record<string, any>;
destination: Record<string, any>;
};
}
}

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

declare namespace WinstonLogger {

export interface WinstonLoggerOptions extends LoggerOptions {
winston: {
level?: string,
[key: string]: any
}
level?: string;
[key: string]: any;
};
}
}

Expand Down
33 changes: 21 additions & 12 deletions src/metrics/constants.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export declare const TYPE_GAUGE = "gauge";
export declare const TYPE_HISTOGRAM = "histogram";
export declare const TYPE_INFO = "info";


export declare const PROCESS_ARGUMENTS: "process.arguments";

export declare const PROCESS_PID = "process.pid";
Expand All @@ -16,17 +15,27 @@ export declare const PROCESS_MEMORY_EXTERNAL = "process.memory.external";

export declare const PROCESS_MEMORY_HEAP_SPACE_SIZE_TOTAL = "process.memory.heap.space.size.total";
export declare const PROCESS_MEMORY_HEAP_SPACE_SIZE_USED = "process.memory.heap.space.size.used";
export declare const PROCESS_MEMORY_HEAP_SPACE_SIZE_AVAILABLE = "process.memory.heap.space.size.available";
export declare const PROCESS_MEMORY_HEAP_SPACE_SIZE_PHYSICAL = "process.memory.heap.space.size.physical";

export declare const PROCESS_MEMORY_HEAP_STAT_HEAP_SIZE_TOTAL = "process.memory.heap.stat.heap.size.total";
export declare const PROCESS_MEMORY_HEAP_STAT_EXECUTABLE_SIZE_TOTAL = "process.memory.heap.stat.executable.size.total";
export declare const PROCESS_MEMORY_HEAP_STAT_PHYSICAL_SIZE_TOTAL = "process.memory.heap.stat.physical.size.total";
export declare const PROCESS_MEMORY_HEAP_STAT_AVAILABLE_SIZE_TOTAL = "process.memory.heap.stat.available.size.total";
export declare const PROCESS_MEMORY_HEAP_STAT_USED_HEAP_SIZE = "process.memory.heap.stat.used.heap.size";
export declare const PROCESS_MEMORY_HEAP_STAT_HEAP_SIZE_LIMIT = "process.memory.heap.stat.heap.size.limit";
export declare const PROCESS_MEMORY_HEAP_STAT_MALLOCATED_MEMORY = "process.memory.heap.stat.mallocated.memory";
export declare const PROCESS_MEMORY_HEAP_STAT_PEAK_MALLOCATED_MEMORY = "process.memory.heap.stat.peak.mallocated.memory";
export declare const PROCESS_MEMORY_HEAP_SPACE_SIZE_AVAILABLE =
"process.memory.heap.space.size.available";
export declare const PROCESS_MEMORY_HEAP_SPACE_SIZE_PHYSICAL =
"process.memory.heap.space.size.physical";

export declare const PROCESS_MEMORY_HEAP_STAT_HEAP_SIZE_TOTAL =
"process.memory.heap.stat.heap.size.total";
export declare const PROCESS_MEMORY_HEAP_STAT_EXECUTABLE_SIZE_TOTAL =
"process.memory.heap.stat.executable.size.total";
export declare const PROCESS_MEMORY_HEAP_STAT_PHYSICAL_SIZE_TOTAL =
"process.memory.heap.stat.physical.size.total";
export declare const PROCESS_MEMORY_HEAP_STAT_AVAILABLE_SIZE_TOTAL =
"process.memory.heap.stat.available.size.total";
export declare const PROCESS_MEMORY_HEAP_STAT_USED_HEAP_SIZE =
"process.memory.heap.stat.used.heap.size";
export declare const PROCESS_MEMORY_HEAP_STAT_HEAP_SIZE_LIMIT =
"process.memory.heap.stat.heap.size.limit";
export declare const PROCESS_MEMORY_HEAP_STAT_MALLOCATED_MEMORY =
"process.memory.heap.stat.mallocated.memory";
export declare const PROCESS_MEMORY_HEAP_STAT_PEAK_MALLOCATED_MEMORY =
"process.memory.heap.stat.peak.mallocated.memory";
export declare const PROCESS_MEMORY_HEAP_STAT_ZAP_GARBAGE = "process.memory.heap.stat.zap.garbage";

export declare const PROCESS_UPTIME = "process.uptime";
Expand Down
54 changes: 32 additions & 22 deletions src/metrics/registry.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,43 @@ declare namespace MetricRegistry {
excludes?: string | string[];
}

export type MetricsReporter = {
type: "Console",
options?: ConsoleReporterOptions,
} | {
type: "CSV",
options?: ConsoleReporterOptions,
} | {
type: "Datadog",
options?: DatadogReporterOptions,
} | {
type: "Event",
options?: EventReporterOptions,
} | {
type: "Prometheus",
options?: PrometheusReporterOptions,
} | {
type: "StatsD",
options?: StatsDReporterOptions,
};
export type MetricsReporter =
| {
type: "Console";
options?: ConsoleReporterOptions;
}
| {
type: "CSV";
options?: ConsoleReporterOptions;
}
| {
type: "Datadog";
options?: DatadogReporterOptions;
}
| {
type: "Event";
options?: EventReporterOptions;
}
| {
type: "Prometheus";
options?: PrometheusReporterOptions;
}
| {
type: "StatsD";
options?: StatsDReporterOptions;
};

type MetricsReporterTypes = MetricsReporter["type"];

export interface MetricRegistryOptions {
enabled?: boolean;
collectProcessMetrics?: boolean;
collectInterval?: number;
reporter?: MetricsReporterTypes | MetricsReporter | (MetricsReporter | MetricsReporterTypes)[] | null;
reporter?:
| MetricsReporterTypes
| MetricsReporter
| (MetricsReporter | MetricsReporterTypes)[]
| null;
defaultBuckets?: number[];
defaultQuantiles?: number[];
defaultMaxAgeSeconds?: number;
Expand All @@ -66,8 +76,8 @@ declare namespace MetricRegistry {

type HistogramMetricOptions = BaseMetricOptions & {
type: "histogram";
quantiles?: boolean|number[];
buckets?: boolean|number[];
quantiles?: boolean | number[];
buckets?: boolean | number[];
};

type InfoMetricOptions = BaseMetricOptions & {
Expand Down
2 changes: 1 addition & 1 deletion src/metrics/reporters/base.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ServiceBroker = require("../../service-broker");
import type MetricRegistry = require("../registry");
import type BaseMetric = require("../types/base");
import type {Logger} from "../../logger-factory";
import type { Logger } from "../../logger-factory";

declare namespace MetricBaseReporter {
export interface MetricReporterOptions {
Expand Down
4 changes: 2 additions & 2 deletions src/metrics/reporters/console.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ declare class ConsoleReporter extends MetricBaseReporter {
constructor(opts?: ConsoleReporter.ConsoleReporterOptions);

labelsToStr(labels: Record<string, any>): string;
print(): void;
log(...args: any[]): any;
print(): void;
log(...args: any[]): any;

metricChanged(metric: BaseMetric<any>): void;
}
Expand Down
Loading

0 comments on commit 6e9a91b

Please sign in to comment.