@reliverse/relinka 1.2.3 → 1.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +2 -2
- package/README.md +2 -8
- package/dist-npm/components/levels/levels.d.ts +21 -0
- package/dist-npm/components/levels/levels.js +8 -8
- package/dist-npm/components/messages/mapping.d.ts +3 -0
- package/dist-npm/components/messages/mapping.js +49 -0
- package/dist-npm/components/messages/messages.d.ts +89 -0
- package/dist-npm/components/messages/messages.js +329 -0
- package/dist-npm/components/messages/mod.d.ts +6 -0
- package/dist-npm/components/messages/mod.js +6 -0
- package/dist-npm/components/messages/platforms.d.ts +10 -0
- package/dist-npm/components/messages/platforms.js +67 -0
- package/dist-npm/components/messages/terminal.d.ts +15 -0
- package/dist-npm/components/messages/terminal.js +57 -0
- package/dist-npm/components/messages/types.d.ts +12 -0
- package/dist-npm/components/messages/types.js +0 -0
- package/dist-npm/components/messages/variants.d.ts +12 -0
- package/dist-npm/components/messages/variants.js +52 -0
- package/dist-npm/components/modes/basic.d.ts +14 -2
- package/dist-npm/components/modes/basic.js +6 -6
- package/dist-npm/components/modes/browser.d.ts +16 -2
- package/dist-npm/components/modes/browser.js +5 -5
- package/dist-npm/components/modes/shared.d.ts +1 -1
- package/dist-npm/components/modes/shared.js +1 -1
- package/dist-npm/components/relinka/logger.d.ts +12 -0
- package/dist-npm/components/relinka/logger.js +52 -0
- package/dist-npm/components/relinka/mod.d.ts +21 -0
- package/dist-npm/components/relinka/mod.js +34 -0
- package/dist-npm/components/relinka/relinka.d.ts +118 -20
- package/dist-npm/components/relinka/relinka.js +133 -36
- package/dist-npm/components/reporters/basic.d.ts +1 -1
- package/dist-npm/components/reporters/basic.js +5 -5
- package/dist-npm/components/reporters/browser.js +5 -5
- package/dist-npm/components/reporters/fancy.d.ts +1 -1
- package/dist-npm/components/reporters/fancy.js +9 -9
- package/dist-npm/main.d.ts +3 -8
- package/dist-npm/main.js +3 -34
- package/dist-npm/types/mod.d.ts +136 -29
- package/dist-npm/utils/box.d.ts +104 -14
- package/dist-npm/utils/box.js +1 -1
- package/dist-npm/utils/color.d.ts +20 -0
- package/dist-npm/utils/color.js +3 -3
- package/dist-npm/utils/error.d.ts +5 -0
- package/dist-npm/utils/format.d.ts +12 -0
- package/dist-npm/utils/log.d.ts +11 -0
- package/dist-npm/utils/stream.d.ts +13 -0
- package/dist-npm/utils/string.d.ts +45 -0
- package/dist-npm/utils/tree.d.ts +34 -5
- package/package.json +35 -32
- package/LICENSE.md +0 -21
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import ansiEscapes from "ansi-escapes";
|
|
2
|
+
import { cursor } from "sisteransi";
|
|
3
|
+
import terminalSize from "terminal-size";
|
|
4
|
+
import wrapAnsi from "wrap-ansi";
|
|
5
|
+
export function getTerminalHeight() {
|
|
6
|
+
return terminalSize().rows ?? 24;
|
|
7
|
+
}
|
|
8
|
+
export function getExactTerminalWidth() {
|
|
9
|
+
return terminalSize().columns ?? 80;
|
|
10
|
+
}
|
|
11
|
+
export function getTerminalWidth(terminalWidth = 0) {
|
|
12
|
+
if (terminalWidth === 0) {
|
|
13
|
+
terminalWidth = getExactTerminalWidth();
|
|
14
|
+
}
|
|
15
|
+
if (terminalWidth > 150) {
|
|
16
|
+
return terminalWidth - 40;
|
|
17
|
+
} else if (terminalWidth > 120) {
|
|
18
|
+
return terminalWidth - 30;
|
|
19
|
+
} else if (terminalWidth > 100) {
|
|
20
|
+
return terminalWidth - 20;
|
|
21
|
+
}
|
|
22
|
+
return terminalWidth;
|
|
23
|
+
}
|
|
24
|
+
export function breakLines(content, terminalWidth = 0) {
|
|
25
|
+
if (terminalWidth === 0) {
|
|
26
|
+
terminalWidth = getTerminalWidth();
|
|
27
|
+
}
|
|
28
|
+
return content.split("\n").flatMap(
|
|
29
|
+
(line) => wrapAnsi(line, terminalWidth, { trim: false, hard: true }).split("\n").map((str) => str.trimEnd())
|
|
30
|
+
).join("\n");
|
|
31
|
+
}
|
|
32
|
+
export function removeCursor() {
|
|
33
|
+
process.stdout.write(cursor.hide);
|
|
34
|
+
}
|
|
35
|
+
export function restoreCursor() {
|
|
36
|
+
process.stdout.write(cursor.show);
|
|
37
|
+
}
|
|
38
|
+
export function deleteLastLine() {
|
|
39
|
+
process.stdout.write(ansiEscapes.cursorUp(1) + ansiEscapes.eraseLine);
|
|
40
|
+
}
|
|
41
|
+
export function deleteLastLines(count) {
|
|
42
|
+
if (count <= 0) {
|
|
43
|
+
console.error("Count is less than or equal to 0. Nothing to delete.");
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
process.stdout.write(ansiEscapes.eraseLines(count));
|
|
47
|
+
}
|
|
48
|
+
export function countLines(text) {
|
|
49
|
+
const adjustedWidth = getTerminalWidth();
|
|
50
|
+
const lines = text.split("\n");
|
|
51
|
+
let lineCount = 0;
|
|
52
|
+
for (const line of lines) {
|
|
53
|
+
const wrapped = wrapAnsi(line, adjustedWidth, { hard: true });
|
|
54
|
+
lineCount += wrapped.split("\n").length;
|
|
55
|
+
}
|
|
56
|
+
return lineCount;
|
|
57
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type MsgType = "M_NULL" | "M_INFO_NULL" | "M_START" | "M_MIDDLE" | "M_GENERAL" | "M_GENERAL_NULL" | "M_INFO" | "M_ERROR" | "M_ERROR_NULL" | "M_END" | "M_NEWLINE" | "M_BAR";
|
|
2
|
+
export type TypographyName = "bold" | "strikethrough" | "underline" | "italic" | "none";
|
|
3
|
+
export type BorderColorName = "reset" | "inverse" | "dim" | "black" | "red" | "redBright" | "green" | "greenBright" | "yellow" | "yellowBright" | "blue" | "blueBright" | "magenta" | "magentaBright" | "cyan" | "cyanBright" | "bgCyan" | "bgCyanBright" | "white" | "gray";
|
|
4
|
+
export type ColorName = BorderColorName | "gradientGradient" | "rainbowGradient" | "cristalGradient" | "mindGradient" | "passionGradient" | "viceGradient" | "retroGradient" | "none";
|
|
5
|
+
export type MsgConfig = {
|
|
6
|
+
symbol: string;
|
|
7
|
+
prefix?: string;
|
|
8
|
+
color?: (text: string) => string;
|
|
9
|
+
newLineBefore?: boolean;
|
|
10
|
+
newLineAfter?: boolean;
|
|
11
|
+
suffix?: string;
|
|
12
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ColorName } from "./types.js";
|
|
2
|
+
export declare const variantMap: {
|
|
3
|
+
doubleBox: typeof createDoubleBox;
|
|
4
|
+
};
|
|
5
|
+
type ValidVariant = keyof typeof variantMap;
|
|
6
|
+
export type VariantName = ValidVariant | "none";
|
|
7
|
+
export declare function isValidVariant(variant: string | undefined): variant is ValidVariant;
|
|
8
|
+
export declare function applyVariant(lines: string[] | string, variant?: VariantName, options?: {
|
|
9
|
+
limit?: number;
|
|
10
|
+
}, borderColor?: ColorName): Promise<string>;
|
|
11
|
+
declare function createDoubleBox(lines: string[], limit?: number, borderColor?: ColorName): string;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { colorMap } from "./mapping.js";
|
|
2
|
+
export const variantMap = {
|
|
3
|
+
// box: createBox,
|
|
4
|
+
doubleBox: createDoubleBox
|
|
5
|
+
// banner: createBanner,
|
|
6
|
+
// underline: createUnderline,
|
|
7
|
+
};
|
|
8
|
+
export function isValidVariant(variant) {
|
|
9
|
+
return variant !== void 0 && variant !== "none" && variant in variantMap;
|
|
10
|
+
}
|
|
11
|
+
export async function applyVariant(lines, variant, options, borderColor) {
|
|
12
|
+
const linesArray = Array.isArray(lines) ? lines : [lines];
|
|
13
|
+
switch (variant) {
|
|
14
|
+
// case "box":
|
|
15
|
+
// return createBox(linesArray, options?.limit);
|
|
16
|
+
case "doubleBox":
|
|
17
|
+
return createDoubleBox(linesArray, options?.limit, borderColor);
|
|
18
|
+
// case "banner":
|
|
19
|
+
// return createBanner(linesArray);
|
|
20
|
+
// case "underline":
|
|
21
|
+
// return createUnderline(linesArray);
|
|
22
|
+
default:
|
|
23
|
+
return linesArray.join("\n");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function createDoubleBox(lines, limit, borderColor) {
|
|
27
|
+
const processedLines = processLines(lines, limit);
|
|
28
|
+
const maxLength = Math.max(...processedLines.map((line) => line.length));
|
|
29
|
+
const indentation = "";
|
|
30
|
+
if (borderColor === void 0) {
|
|
31
|
+
borderColor = "dim";
|
|
32
|
+
}
|
|
33
|
+
const topBorder = borderColor ? colorMap[borderColor](`${"\u2550".repeat(maxLength)}\u2557`) : `${"\u2550".repeat(maxLength)}\u2557`;
|
|
34
|
+
const bottomBorder = borderColor ? colorMap[borderColor](`${indentation}\u255A${"\u2550".repeat(maxLength + 2)}\u255D`) : `${indentation}\u255A${"\u2550".repeat(maxLength + 2)}\u255D`;
|
|
35
|
+
const middle = processedLines.map((line, index) => {
|
|
36
|
+
const lineIndentation = index === 0 ? indentation : indentation + " ";
|
|
37
|
+
return `${lineIndentation}${borderColor ? colorMap[borderColor]("\u2551") : "\u2551"} ${colorMap[borderColor](line.padEnd(maxLength))} ${borderColor ? colorMap[borderColor]("\u2551") : "\u2551"}`;
|
|
38
|
+
}).join("\n");
|
|
39
|
+
return `${topBorder}
|
|
40
|
+
${middle}
|
|
41
|
+
${bottomBorder}`;
|
|
42
|
+
}
|
|
43
|
+
function processLines(lines, limit) {
|
|
44
|
+
const linesArray = Array.isArray(lines) ? lines : [lines];
|
|
45
|
+
return linesArray.map((line) => {
|
|
46
|
+
let truncatedLine = line;
|
|
47
|
+
if (limit && line.length > limit) {
|
|
48
|
+
truncatedLine = `${line.slice(0, limit - 3)}...`;
|
|
49
|
+
}
|
|
50
|
+
return truncatedLine.padEnd(limit || truncatedLine.length);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
import type { RelinkaInstance } from "../../components/relinka/relinka.js";
|
|
2
2
|
import type { RelinkaOptions } from "../../types/mod.js";
|
|
3
3
|
export * from "./shared.js";
|
|
4
|
+
/**
|
|
5
|
+
* Factory function to create a new Relinka instance
|
|
6
|
+
*
|
|
7
|
+
* @param {Partial<RelinkaOptions & { fancy: boolean }>} [options={}] - Optional configuration options. See {@link RelinkaOptions}.
|
|
8
|
+
* @returns {RelinkaInstance} A new Relinka instance configured with the given options.
|
|
9
|
+
*/
|
|
4
10
|
export declare function createRelinka(options?: Partial<RelinkaOptions & {
|
|
5
11
|
fancy: boolean;
|
|
6
12
|
}>): RelinkaInstance;
|
|
7
|
-
|
|
8
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Creates and exports a standard instance of Relinka with the default configuration.
|
|
15
|
+
* This instance can be used directly for logging throughout the application.
|
|
16
|
+
*
|
|
17
|
+
* @type {RelinkaInstance} relinka - The default instance of Relinka.
|
|
18
|
+
*/
|
|
19
|
+
export declare const relinkaBasic: RelinkaInstance;
|
|
20
|
+
export default relinkaBasic;
|
|
@@ -4,10 +4,10 @@ import { BasicReporter } from "../../components/reporters/basic.js";
|
|
|
4
4
|
export * from "./shared.js";
|
|
5
5
|
export function createRelinka(options = {}) {
|
|
6
6
|
let level = LogLevels.info;
|
|
7
|
-
if (process.env
|
|
8
|
-
level = Number.parseInt(process.env
|
|
7
|
+
if (process.env["RELINKA_LEVEL"]) {
|
|
8
|
+
level = Number.parseInt(process.env["RELINKA_LEVEL"]) ?? level;
|
|
9
9
|
}
|
|
10
|
-
const
|
|
10
|
+
const relinka = _createRelinka({
|
|
11
11
|
level,
|
|
12
12
|
defaults: { level },
|
|
13
13
|
stdout: process.stdout,
|
|
@@ -15,7 +15,7 @@ export function createRelinka(options = {}) {
|
|
|
15
15
|
reporters: options.reporters || [new BasicReporter()],
|
|
16
16
|
...options
|
|
17
17
|
});
|
|
18
|
-
return
|
|
18
|
+
return relinka;
|
|
19
19
|
}
|
|
20
|
-
export const
|
|
21
|
-
export default
|
|
20
|
+
export const relinkaBasic = createRelinka();
|
|
21
|
+
export default relinkaBasic;
|
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
import type { RelinkaOptions } from "../../types/mod.js";
|
|
2
2
|
export * from "./shared.js";
|
|
3
|
+
/**
|
|
4
|
+
* Creates a new Relinka instance configured specifically for browser environments.
|
|
5
|
+
* This function sets up default reporters and a prompt method tailored to the browser's dialogue APIs.
|
|
6
|
+
*
|
|
7
|
+
* @param {Partial<RelinkaOptions>} [options={}] - Optional configuration options.
|
|
8
|
+
* The options can override the default reporter and prompt behavior. See {@link RelinkaOptions}.
|
|
9
|
+
* @returns {RelinkaInstance} A new Relinka instance optimized for use in browser environments.
|
|
10
|
+
*/
|
|
3
11
|
export declare function createRelinka(options?: Partial<RelinkaOptions>): any;
|
|
4
|
-
|
|
5
|
-
|
|
12
|
+
/**
|
|
13
|
+
* A standard Relinka instance created with browser-specific configurations.
|
|
14
|
+
* This instance can be used throughout a browser-based project.
|
|
15
|
+
*
|
|
16
|
+
* @type {RelinkaInstance} relinka - The default browser-configured Relinka instance.
|
|
17
|
+
*/
|
|
18
|
+
export declare const relinkaBrowser: any;
|
|
19
|
+
export default relinkaBrowser;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { BrowserReporter } from "../../components/reporters/browser.js";
|
|
2
1
|
import { createRelinka as _createRelinka } from "../../components/relinka/relinka.js";
|
|
2
|
+
import { BrowserReporter } from "../../components/reporters/browser.js";
|
|
3
3
|
export * from "./shared.js";
|
|
4
4
|
export function createRelinka(options = {}) {
|
|
5
|
-
const
|
|
5
|
+
const relinka = _createRelinka({
|
|
6
6
|
reporters: options.reporters || [new BrowserReporter({})],
|
|
7
7
|
...options
|
|
8
8
|
});
|
|
9
|
-
return
|
|
9
|
+
return relinka;
|
|
10
10
|
}
|
|
11
|
-
export const
|
|
12
|
-
export default
|
|
11
|
+
export const relinkaBrowser = createRelinka();
|
|
12
|
+
export default relinkaBrowser;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { LogLevels, LogTypes } from "../../components/levels/levels.js";
|
|
2
|
-
export {
|
|
2
|
+
export { RelinkaInterface } from "../../components/relinka/relinka.js";
|
|
3
3
|
export type * from "../../types/mod.js";
|
|
4
4
|
export type { RelinkaInstance } from "../../components/relinka/relinka.js";
|
|
5
5
|
export type { LogLevel, LogType } from "../../components/levels/levels.js";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { LogLevels, LogTypes } from "../../components/levels/levels.js";
|
|
2
|
-
export {
|
|
2
|
+
export { RelinkaInterface } from "../../components/relinka/relinka.js";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type MessageKind = "log" | "info" | "warn" | "error" | "success";
|
|
2
|
+
export type VerboseKind = `${MessageKind}-verbose`;
|
|
3
|
+
export type AllKinds = MessageKind | VerboseKind;
|
|
4
|
+
export type MessageConfig = {
|
|
5
|
+
type: "M_INFO" | "M_ERROR";
|
|
6
|
+
titleColor?: "retroGradient" | "viceGradient" | "yellowBright";
|
|
7
|
+
titleTypography?: "bold";
|
|
8
|
+
contentColor?: "dim";
|
|
9
|
+
contentTypography?: "italic";
|
|
10
|
+
};
|
|
11
|
+
export declare const relinka: (kind: AllKinds, title: string, content?: string, hint?: string) => void;
|
|
12
|
+
export declare const throwError: (error: unknown) => never;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { msg } from "../../main.js";
|
|
2
|
+
const verboseLogging = false;
|
|
3
|
+
const MESSAGE_CONFIGS = {
|
|
4
|
+
log: {
|
|
5
|
+
type: "M_INFO",
|
|
6
|
+
titleColor: "retroGradient",
|
|
7
|
+
titleTypography: "bold"
|
|
8
|
+
},
|
|
9
|
+
info: {
|
|
10
|
+
type: "M_INFO",
|
|
11
|
+
titleColor: "retroGradient",
|
|
12
|
+
titleTypography: "bold"
|
|
13
|
+
},
|
|
14
|
+
success: {
|
|
15
|
+
type: "M_INFO",
|
|
16
|
+
titleColor: "viceGradient",
|
|
17
|
+
titleTypography: "bold"
|
|
18
|
+
},
|
|
19
|
+
warn: {
|
|
20
|
+
type: "M_ERROR",
|
|
21
|
+
titleColor: "yellowBright",
|
|
22
|
+
titleTypography: "bold"
|
|
23
|
+
},
|
|
24
|
+
error: {
|
|
25
|
+
type: "M_ERROR",
|
|
26
|
+
titleColor: "yellowBright",
|
|
27
|
+
titleTypography: "bold"
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
export const relinka = (kind, title, content, hint) => {
|
|
31
|
+
const isVerbose = kind.endsWith("-verbose");
|
|
32
|
+
const baseKind = isVerbose ? kind.replace("-verbose", "") : kind;
|
|
33
|
+
if (isVerbose && !verboseLogging) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const config = MESSAGE_CONFIGS[baseKind];
|
|
37
|
+
msg({
|
|
38
|
+
...config,
|
|
39
|
+
title: isVerbose ? `[debug] ${title}` : title,
|
|
40
|
+
content: content ?? "",
|
|
41
|
+
contentColor: "dim",
|
|
42
|
+
contentTypography: "italic",
|
|
43
|
+
hint: hint ?? ""
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
export const throwError = (error) => {
|
|
47
|
+
msg({
|
|
48
|
+
type: "M_ERROR",
|
|
49
|
+
title: error instanceof Error ? `\u{1F914} Failed to set up the project: ${error.message}` : "\u{1F914} An unknown error occurred."
|
|
50
|
+
});
|
|
51
|
+
process.exit(1);
|
|
52
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { RelinkaOptions } from "../../types/mod.js";
|
|
2
|
+
import type { RelinkaInstance } from "./relinka.js";
|
|
3
|
+
export * from "../../components/modes/shared.js";
|
|
4
|
+
/**
|
|
5
|
+
* Factory function to create a new Relinka instance tailored for use in different environments.
|
|
6
|
+
* It automatically adjusts logging levels based on environment variables and execution context.
|
|
7
|
+
*
|
|
8
|
+
* @param {Partial<RelinkaOptions & { fancy: boolean }>} [options={}] - Optional configuration options. See {@link RelinkaOptions}.
|
|
9
|
+
* @returns {RelinkaInstance} A new Relinka instance with configurations based on the given options and the execution environment.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createRelinka(options?: Partial<RelinkaOptions & {
|
|
12
|
+
fancy: boolean;
|
|
13
|
+
}>): RelinkaInstance;
|
|
14
|
+
/**
|
|
15
|
+
* A default instance of Relinka, created and configured for immediate use.
|
|
16
|
+
* This instance is configured based on the execution environment and the options provided.
|
|
17
|
+
*
|
|
18
|
+
* @type {RelinkaInstance} relinka - The default Relinka instance, ready to use.
|
|
19
|
+
*/
|
|
20
|
+
export declare const relinkaInstance: RelinkaInstance;
|
|
21
|
+
export default relinkaInstance;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { isDebug, isTest, isCI } from "std-env";
|
|
2
|
+
import { LogLevels } from "../levels/levels.js";
|
|
3
|
+
import { BasicReporter } from "../reporters/basic.js";
|
|
4
|
+
import { FancyReporter } from "../reporters/fancy.js";
|
|
5
|
+
import { createRelinka as _createRelinka } from "./relinka.js";
|
|
6
|
+
export * from "../../components/modes/shared.js";
|
|
7
|
+
export function createRelinka(options = {}) {
|
|
8
|
+
let level = _getDefaultLogLevel();
|
|
9
|
+
if (process.env["RELINKA_LEVEL"]) {
|
|
10
|
+
level = Number.parseInt(process.env["RELINKA_LEVEL"]) ?? level;
|
|
11
|
+
}
|
|
12
|
+
const relinka = _createRelinka({
|
|
13
|
+
level,
|
|
14
|
+
defaults: { level },
|
|
15
|
+
stdout: process.stdout,
|
|
16
|
+
stderr: process.stderr,
|
|
17
|
+
reporters: options.reporters || [
|
|
18
|
+
options.fancy ?? !(isCI || isTest) ? new FancyReporter() : new BasicReporter()
|
|
19
|
+
],
|
|
20
|
+
...options
|
|
21
|
+
});
|
|
22
|
+
return relinka;
|
|
23
|
+
}
|
|
24
|
+
function _getDefaultLogLevel() {
|
|
25
|
+
if (isDebug) {
|
|
26
|
+
return LogLevels.debug;
|
|
27
|
+
}
|
|
28
|
+
if (isTest) {
|
|
29
|
+
return LogLevels.warn;
|
|
30
|
+
}
|
|
31
|
+
return LogLevels.info;
|
|
32
|
+
}
|
|
33
|
+
export const relinkaInstance = createRelinka();
|
|
34
|
+
export default relinkaInstance;
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import type { LogType } from "../../components/levels/levels.js";
|
|
2
2
|
import type { RelinkaReporter, InputLogObject, LogObject, RelinkaOptions } from "../../types/mod.js";
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Relinka class for logging management with support for pause/resume, mocking and customizable reporting.
|
|
5
|
+
* Provides flexible logging capabilities including level-based logging, custom reporters and integration options.
|
|
6
|
+
*
|
|
7
|
+
* @class Relinka
|
|
8
|
+
*/
|
|
9
|
+
export declare class RelinkaInterface {
|
|
4
10
|
options: RelinkaOptions;
|
|
5
11
|
_lastLog: {
|
|
6
12
|
serialized?: string;
|
|
@@ -9,34 +15,126 @@ export declare class Relinka {
|
|
|
9
15
|
time?: Date;
|
|
10
16
|
timeout?: ReturnType<typeof setTimeout>;
|
|
11
17
|
};
|
|
18
|
+
_paused: boolean;
|
|
19
|
+
_queue: any[];
|
|
12
20
|
_mockFn?: RelinkaOptions["mockFn"];
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Creates an instance of Relinka with specified options or defaults.
|
|
23
|
+
*
|
|
24
|
+
* @param {Partial<RelinkaOptions>} [options={}] - Configuration options for the Relinka instance.
|
|
25
|
+
*/
|
|
26
|
+
constructor(options?: Partial<RelinkaOptions>);
|
|
27
|
+
/**
|
|
28
|
+
* Gets the current log level of the Relinka instance.
|
|
29
|
+
*
|
|
30
|
+
* @returns {number} The current log level.
|
|
31
|
+
*/
|
|
32
|
+
get level(): any;
|
|
33
|
+
/**
|
|
34
|
+
* Sets the minimum log level that will be output by the instance.
|
|
35
|
+
*
|
|
36
|
+
* @param {number} level - The new log level to set.
|
|
37
|
+
*/
|
|
38
|
+
set level(level: any);
|
|
39
|
+
/**
|
|
40
|
+
* Creates a new instance of Relinka, inheriting options from the current instance, with possible overrides.
|
|
41
|
+
*
|
|
42
|
+
* @param {Partial<RelinkaOptions>} options - Optional overrides for the new instance. See {@link RelinkaOptions}.
|
|
43
|
+
* @returns {RelinkaInstance} A new Relinka instance. See {@link RelinkaInstance}.
|
|
44
|
+
*/
|
|
45
|
+
create(options: Partial<RelinkaOptions>): RelinkaInstance;
|
|
46
|
+
/**
|
|
47
|
+
* Creates a new Relinka instance with the specified default log object properties.
|
|
48
|
+
*
|
|
49
|
+
* @param {InputLogObject} defaults - Default properties to include in any log from the new instance. See {@link InputLogObject}.
|
|
50
|
+
* @returns {RelinkaInstance} A new Relinka instance. See {@link RelinkaInstance}.
|
|
51
|
+
*/
|
|
52
|
+
withDefaults(defaults: InputLogObject): RelinkaInstance;
|
|
53
|
+
/**
|
|
54
|
+
* Creates a new Relinka instance with a specified tag, which will be included in every log.
|
|
55
|
+
*
|
|
56
|
+
* @param {string} tag - The tag to include in each log of the new instance.
|
|
57
|
+
* @returns {RelinkaInstance} A new Relinka instance. See {@link RelinkaInstance}.
|
|
58
|
+
*/
|
|
59
|
+
withTag(tag: string): RelinkaInstance;
|
|
60
|
+
/**
|
|
61
|
+
* Adds a custom reporter to the Relinka instance.
|
|
62
|
+
* Reporters will be called for each log message, depending on their implementation and log level.
|
|
63
|
+
*
|
|
64
|
+
* @param {RelinkaReporter} reporter - The reporter to add. See {@link RelinkaReporter}.
|
|
65
|
+
* @returns {Relinka} The current Relinka instance.
|
|
66
|
+
*/
|
|
67
|
+
addReporter(reporter: RelinkaReporter): this;
|
|
68
|
+
/**
|
|
69
|
+
* Removes a custom reporter from the Relinka instance.
|
|
70
|
+
* If no reporter is specified, all reporters will be removed.
|
|
71
|
+
*
|
|
72
|
+
* @param {RelinkaReporter} reporter - The reporter to remove. See {@link RelinkaReporter}.
|
|
73
|
+
* @returns {Relinka} The current Relinka instance.
|
|
74
|
+
*/
|
|
75
|
+
removeReporter(reporter: RelinkaReporter): any;
|
|
76
|
+
/**
|
|
77
|
+
* Replaces all reporters of the Relinka instance with the specified array of reporters.
|
|
78
|
+
*
|
|
79
|
+
* @param {RelinkaReporter[]} reporters - The new reporters to set. See {@link RelinkaReporter}.
|
|
80
|
+
* @returns {Relinka} The current Relinka instance.
|
|
81
|
+
*/
|
|
82
|
+
setReporters(reporters: RelinkaReporter[]): this;
|
|
22
83
|
wrapAll(): void;
|
|
23
84
|
restoreAll(): void;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
85
|
+
/**
|
|
86
|
+
* Overrides console methods with Relinka logging methods for consistent logging.
|
|
87
|
+
*/
|
|
88
|
+
wrapConsole(): void;
|
|
89
|
+
/**
|
|
90
|
+
* Restores the original console methods, removing Relinka overrides.
|
|
91
|
+
*/
|
|
92
|
+
restoreConsole(): void;
|
|
93
|
+
/**
|
|
94
|
+
* Overrides standard output and error streams to redirect them through RelinkaInterface.
|
|
95
|
+
*/
|
|
96
|
+
wrapStd(): void;
|
|
27
97
|
_wrapStream(stream: NodeJS.WriteStream | undefined, type: LogType): void;
|
|
28
|
-
|
|
98
|
+
/**
|
|
99
|
+
* Restores the original standard output and error streams, removing the Relinka redirection.
|
|
100
|
+
*/
|
|
101
|
+
restoreStd(): void;
|
|
29
102
|
_restoreStream(stream?: NodeJS.WriteStream): void;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
103
|
+
/**
|
|
104
|
+
* Clears the internal state of the Relinka instance.
|
|
105
|
+
* This will reset any throttling, last log data, clear any queued logs,
|
|
106
|
+
* and optionally clear the actual console.
|
|
107
|
+
*
|
|
108
|
+
* @param {boolean} clearConsole - Whether to clear the actual console. Defaults to false.
|
|
109
|
+
*/
|
|
110
|
+
clear(clearConsole?: boolean): void;
|
|
111
|
+
/**
|
|
112
|
+
* Pauses logging, queues incoming logs until resumed.
|
|
113
|
+
*/
|
|
114
|
+
pauseLogs(): void;
|
|
115
|
+
/**
|
|
116
|
+
* Resumes logging, processing any queued logs.
|
|
117
|
+
*/
|
|
118
|
+
resumeLogs(): void;
|
|
119
|
+
/**
|
|
120
|
+
* Replaces logging methods with mocks if a mock function is provided.
|
|
121
|
+
*
|
|
122
|
+
* @param {RelinkaOptions["mockFn"]} mockFn - The function to use for mocking logging methods. See {@link RelinkaOptions["mockFn"]}.
|
|
123
|
+
*/
|
|
124
|
+
mockTypes(mockFn?: RelinkaOptions["mockFn"]): void;
|
|
125
|
+
_wrapLogFn(defaults: InputLogObject, isRaw?: boolean): (...args: any[]) => boolean;
|
|
126
|
+
_logFn(defaults: InputLogObject, args: any[], isRaw?: boolean): boolean;
|
|
35
127
|
_log(logObj: LogObject): void;
|
|
36
128
|
}
|
|
37
129
|
export type LogFn = {
|
|
38
130
|
(message: InputLogObject | any, ...args: any[]): void;
|
|
39
131
|
raw: (...args: any[]) => void;
|
|
40
132
|
};
|
|
41
|
-
export type RelinkaInstance =
|
|
133
|
+
export type RelinkaInstance = RelinkaInterface & Record<LogType, LogFn>;
|
|
134
|
+
/**
|
|
135
|
+
* Utility for creating a new Relinka instance with optional configuration.
|
|
136
|
+
*
|
|
137
|
+
* @param {Partial<RelinkaOptions>} [options={}] - Optional configuration options for the new Relinka instance. See {@link RelinkaOptions}.
|
|
138
|
+
* @returns {RelinkaInstance} A new instance of RelinkaInterface. See {@link RelinkaInstance}.
|
|
139
|
+
*/
|
|
42
140
|
export declare function createRelinka(options?: Partial<RelinkaOptions>): RelinkaInstance;
|