@meadown/logger 1.8.10 → 1.8.11

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.
Files changed (61) hide show
  1. package/dist/cjs/core/writeLog/{formatLocation.d.ts → helpers/formatLocation.d.ts} +1 -1
  2. package/dist/cjs/core/writeLog/{formatLocation.js → helpers/formatLocation.js} +3 -2
  3. package/dist/cjs/core/writeLog/helpers/index.d.ts +3 -0
  4. package/dist/cjs/core/writeLog/helpers/index.js +17 -0
  5. package/dist/cjs/core/writeLog/{renderMessage.js → helpers/renderMessage.js} +2 -2
  6. package/dist/cjs/core/writeLog/{visibleLines.js → helpers/visibleLines.js} +1 -1
  7. package/dist/cjs/core/writeLog/index.d.ts +2 -15
  8. package/dist/cjs/core/writeLog/index.js +6 -40
  9. package/dist/cjs/core/writeLog/writeLog.d.ts +14 -0
  10. package/dist/cjs/core/writeLog/writeLog.js +43 -0
  11. package/dist/cjs/index.d.ts +46 -17
  12. package/dist/cjs/index.js +17 -7
  13. package/dist/cjs/tap/createTap.js +4 -4
  14. package/dist/cjs/tap/tapAsync/helpers/buildBlock.d.ts +19 -0
  15. package/dist/cjs/tap/tapAsync/helpers/buildBlock.js +56 -0
  16. package/dist/cjs/tap/tapAsync/helpers/format.d.ts +4 -0
  17. package/dist/cjs/tap/tapAsync/helpers/format.js +30 -0
  18. package/dist/cjs/tap/tapAsync/helpers/index.d.ts +4 -0
  19. package/dist/cjs/tap/tapAsync/helpers/index.js +20 -0
  20. package/dist/cjs/tap/tapAsync/helpers/isThenable.d.ts +2 -0
  21. package/dist/cjs/tap/tapAsync/helpers/isThenable.js +15 -0
  22. package/dist/cjs/tap/tapAsync/helpers/response.d.ts +21 -0
  23. package/dist/cjs/tap/tapAsync/helpers/response.js +62 -0
  24. package/dist/cjs/tap/tapAsync/index.d.ts +2 -0
  25. package/dist/cjs/tap/tapAsync/index.js +13 -0
  26. package/dist/{tap → cjs/tap/tapAsync}/tapAsync.d.ts +1 -3
  27. package/dist/cjs/tap/tapAsync/tapAsync.js +92 -0
  28. package/dist/core/writeLog/{formatLocation.d.ts → helpers/formatLocation.d.ts} +1 -1
  29. package/dist/core/writeLog/{formatLocation.js → helpers/formatLocation.js} +3 -2
  30. package/dist/core/writeLog/helpers/index.d.ts +3 -0
  31. package/dist/core/writeLog/helpers/index.js +9 -0
  32. package/dist/core/writeLog/{renderMessage.js → helpers/renderMessage.js} +2 -2
  33. package/dist/core/writeLog/{visibleLines.js → helpers/visibleLines.js} +1 -1
  34. package/dist/core/writeLog/index.d.ts +2 -15
  35. package/dist/core/writeLog/index.js +2 -33
  36. package/dist/core/writeLog/writeLog.d.ts +14 -0
  37. package/dist/core/writeLog/writeLog.js +37 -0
  38. package/dist/index.d.ts +46 -17
  39. package/dist/index.js +17 -7
  40. package/dist/tap/createTap.js +2 -2
  41. package/dist/tap/tapAsync/helpers/buildBlock.d.ts +19 -0
  42. package/dist/tap/tapAsync/helpers/buildBlock.js +53 -0
  43. package/dist/tap/tapAsync/helpers/format.d.ts +4 -0
  44. package/dist/tap/tapAsync/helpers/format.js +26 -0
  45. package/dist/tap/tapAsync/helpers/index.d.ts +4 -0
  46. package/dist/tap/tapAsync/helpers/index.js +10 -0
  47. package/dist/tap/tapAsync/helpers/isThenable.d.ts +2 -0
  48. package/dist/tap/tapAsync/helpers/isThenable.js +12 -0
  49. package/dist/tap/tapAsync/helpers/response.d.ts +21 -0
  50. package/dist/tap/tapAsync/helpers/response.js +57 -0
  51. package/dist/tap/tapAsync/index.d.ts +2 -0
  52. package/dist/tap/tapAsync/index.js +8 -0
  53. package/dist/{cjs/tap → tap/tapAsync}/tapAsync.d.ts +1 -3
  54. package/dist/tap/tapAsync/tapAsync.js +89 -0
  55. package/package.json +7 -4
  56. package/dist/cjs/tap/tapAsync.js +0 -192
  57. package/dist/tap/tapAsync.js +0 -188
  58. /package/dist/cjs/core/writeLog/{renderMessage.d.ts → helpers/renderMessage.d.ts} +0 -0
  59. /package/dist/cjs/core/writeLog/{visibleLines.d.ts → helpers/visibleLines.d.ts} +0 -0
  60. /package/dist/core/writeLog/{renderMessage.d.ts → helpers/renderMessage.d.ts} +0 -0
  61. /package/dist/core/writeLog/{visibleLines.d.ts → helpers/visibleLines.d.ts} +0 -0
@@ -1,4 +1,4 @@
1
- import { type Caller } from "../../caller/getCaller.js";
1
+ import { type Caller } from "../../../caller/getCaller.js";
2
2
  /**
3
3
  * Renders a caller as a `(file:line)` location — a clickable OSC-8 link on a
4
4
  * supporting terminal, plain text otherwise. Pure (no stack access).
@@ -7,13 +7,14 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.formatLocation = formatLocation;
10
- const link_js_1 = require("../../decorations/link.js");
10
+ const link_js_1 = require("../../../decorations/link.js");
11
11
  /**
12
12
  * Renders a caller as a `(file:line)` location — a clickable OSC-8 link on a
13
13
  * supporting terminal, plain text otherwise. Pure (no stack access).
14
14
  */
15
15
  function formatLocation(caller, interactive) {
16
- if (caller.file !== null && caller.line !== null && interactive)
16
+ if (caller.file !== null && caller.line !== null && interactive) {
17
17
  return (0, link_js_1.hyperlink)(caller.label, (0, link_js_1.fileUrl)(caller.file));
18
+ }
18
19
  return caller.label;
19
20
  }
@@ -0,0 +1,3 @@
1
+ export { visibleLines, getVisibleLines, setVisibleLines, } from "./visibleLines.js";
2
+ export { renderMessage } from "./renderMessage.js";
3
+ export { formatLocation } from "./formatLocation.js";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ /*
3
+ * index.ts
4
+ * Created by Dewan Mobashirul
5
+ * Copyright (c) 2026 dewan-meadown
6
+ * All rights reserved
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.formatLocation = exports.renderMessage = exports.setVisibleLines = exports.getVisibleLines = exports.visibleLines = void 0;
10
+ var visibleLines_js_1 = require("./visibleLines.js");
11
+ Object.defineProperty(exports, "visibleLines", { enumerable: true, get: function () { return visibleLines_js_1.visibleLines; } });
12
+ Object.defineProperty(exports, "getVisibleLines", { enumerable: true, get: function () { return visibleLines_js_1.getVisibleLines; } });
13
+ Object.defineProperty(exports, "setVisibleLines", { enumerable: true, get: function () { return visibleLines_js_1.setVisibleLines; } });
14
+ var renderMessage_js_1 = require("./renderMessage.js");
15
+ Object.defineProperty(exports, "renderMessage", { enumerable: true, get: function () { return renderMessage_js_1.renderMessage; } });
16
+ var formatLocation_js_1 = require("./formatLocation.js");
17
+ Object.defineProperty(exports, "formatLocation", { enumerable: true, get: function () { return formatLocation_js_1.formatLocation; } });
@@ -8,9 +8,9 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.renderMessage = renderMessage;
10
10
  const node_util_1 = require("node:util");
11
- const constants_js_1 = require("../../constants.js");
12
- const color_js_1 = require("../../colors/color.js");
13
11
  const visibleLines_js_1 = require("./visibleLines.js");
12
+ const color_js_1 = require("../../../colors/color.js");
13
+ const constants_js_1 = require("../../../constants.js");
14
14
  /**
15
15
  * Collapses a long multi-line message to {@link visibleLines} lines, replacing
16
16
  * the rest with a dimmed `… N more lines` summary. When `visibleLines` is 0
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.visibleLines = void 0;
10
10
  exports.getVisibleLines = getVisibleLines;
11
11
  exports.setVisibleLines = setVisibleLines;
12
- const constants_js_1 = require("../../constants.js");
12
+ const constants_js_1 = require("../../../constants.js");
13
13
  /** Max message lines to show before collapsing the rest; 0 (default) shows all. */
14
14
  exports.visibleLines = constants_js_1.DEFAULT_MAX_LINES;
15
15
  /** How many lines a long message shows before collapsing (0 = all). */
@@ -1,15 +1,2 @@
1
- import { type LogChannel } from "../../constants.js";
2
- import { type Caller } from "../../caller/getCaller.js";
3
- export { getVisibleLines, setVisibleLines } from "./visibleLines.js";
4
- /**
5
- * Renders and writes one log entry. The `caller` is resolved by the *caller* of
6
- * this function (the log closure or `tap`) and passed in, so this helper never
7
- * touches the stack — keeping {@link getCaller}'s frame depth correct no matter
8
- * which user-facing function delegates here.
9
- */
10
- export declare function writeLog(opts: {
11
- channel: LogChannel;
12
- tag: string;
13
- args: unknown[];
14
- caller: Caller;
15
- }): void;
1
+ export { writeLog } from "./writeLog.js";
2
+ export { getVisibleLines, setVisibleLines } from "./helpers/index.js";
@@ -5,44 +5,10 @@
5
5
  * Copyright (c) 2026 dewan-meadown
6
6
  * All rights reserved
7
7
  */
8
- var __importDefault = (this && this.__importDefault) || function (mod) {
9
- return (mod && mod.__esModule) ? mod : { "default": mod };
10
- };
11
8
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.setVisibleLines = exports.getVisibleLines = void 0;
13
- exports.writeLog = writeLog;
14
- const constants_js_1 = require("../../constants.js");
15
- const getTimeStamp_js_1 = __importDefault(require("../../time/getTimeStamp.js"));
16
- const color_js_1 = require("../../colors/color.js");
17
- const isTTY_js_1 = require("../../terminal/isTTY.js");
18
- const renderMessage_js_1 = require("./renderMessage.js");
19
- const formatLocation_js_1 = require("./formatLocation.js");
20
- var visibleLines_js_1 = require("./visibleLines.js");
21
- Object.defineProperty(exports, "getVisibleLines", { enumerable: true, get: function () { return visibleLines_js_1.getVisibleLines; } });
22
- Object.defineProperty(exports, "setVisibleLines", { enumerable: true, get: function () { return visibleLines_js_1.setVisibleLines; } });
23
- /**
24
- * Renders and writes one log entry. The `caller` is resolved by the *caller* of
25
- * this function (the log closure or `tap`) and passed in, so this helper never
26
- * touches the stack — keeping {@link getCaller}'s frame depth correct no matter
27
- * which user-facing function delegates here.
28
- */
29
- function writeLog(opts) {
30
- const { channel, tag, args, caller } = opts;
31
- const streamName = channel === "log" ? "stdout" : "stderr";
32
- // One terminal check drives both color and clickable links — `isTTY` is the
33
- // single source of truth (DRY). Off when output is piped/redirected.
34
- const useColor = (0, isTTY_js_1.isTTY)(streamName);
35
- const paint = (s, c) => useColor ? (0, color_js_1.colorize)(s, c) : s;
36
- const location = (0, formatLocation_js_1.formatLocation)(caller, useColor);
37
- const tagOut = paint(tag, constants_js_1.TAG_COLOR[channel]);
38
- const timeStamp = paint((0, getTimeStamp_js_1.default)(), "teal");
39
- const locOut = paint(`(${location})`, "dimTeal");
40
- const connector = paint(constants_js_1.BRANCH, "gray");
41
- const connectorBottom = paint(constants_js_1.BRANCH_END, "gray");
42
- const separator = paint(constants_js_1.SEPARATOR, "gray");
43
- // Layout: the tag, the message hanging off a `├──` branch, then the timestamp
44
- // and location on a `└──` branch below. Leading `\n` spaces entries apart.
45
- const message = (0, renderMessage_js_1.renderMessage)(args, useColor);
46
- const meta = `\n${connectorBottom} ${timeStamp} ${separator} ${locOut}`;
47
- console[channel](`\n${tagOut}`, `\n${connector}`, message, meta);
48
- }
9
+ exports.setVisibleLines = exports.getVisibleLines = exports.writeLog = void 0;
10
+ var writeLog_js_1 = require("./writeLog.js");
11
+ Object.defineProperty(exports, "writeLog", { enumerable: true, get: function () { return writeLog_js_1.writeLog; } });
12
+ var index_js_1 = require("./helpers/index.js");
13
+ Object.defineProperty(exports, "getVisibleLines", { enumerable: true, get: function () { return index_js_1.getVisibleLines; } });
14
+ Object.defineProperty(exports, "setVisibleLines", { enumerable: true, get: function () { return index_js_1.setVisibleLines; } });
@@ -0,0 +1,14 @@
1
+ import { type LogChannel } from "../../constants.js";
2
+ import { type Caller } from "../../caller/getCaller.js";
3
+ /**
4
+ * Renders and writes one log entry. The `caller` is resolved by the *caller* of
5
+ * this function (the log closure or `tap`) and passed in, so this helper never
6
+ * touches the stack — keeping {@link getCaller}'s frame depth correct no matter
7
+ * which user-facing function delegates here.
8
+ */
9
+ export declare function writeLog(opts: {
10
+ channel: LogChannel;
11
+ tag: string;
12
+ args: unknown[];
13
+ caller: Caller;
14
+ }): void;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ /*
3
+ * writeLog.ts
4
+ * Created by Dewan Mobashirul
5
+ * Copyright (c) 2026 dewan-meadown
6
+ * All rights reserved
7
+ */
8
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.writeLog = writeLog;
13
+ const constants_js_1 = require("../../constants.js");
14
+ const isTTY_js_1 = require("../../terminal/isTTY.js");
15
+ const getTimeStamp_js_1 = __importDefault(require("../../time/getTimeStamp.js"));
16
+ const color_js_1 = require("../../colors/color.js");
17
+ const index_js_1 = require("./helpers/index.js");
18
+ /**
19
+ * Renders and writes one log entry. The `caller` is resolved by the *caller* of
20
+ * this function (the log closure or `tap`) and passed in, so this helper never
21
+ * touches the stack — keeping {@link getCaller}'s frame depth correct no matter
22
+ * which user-facing function delegates here.
23
+ */
24
+ function writeLog(opts) {
25
+ const { channel, tag, args, caller } = opts;
26
+ const streamName = channel === "log" ? "stdout" : "stderr";
27
+ // One terminal check drives both color and clickable links — `isTTY` is the
28
+ // single source of truth (DRY). Off when output is piped/redirected.
29
+ const useColor = (0, isTTY_js_1.isTTY)(streamName);
30
+ const paint = (s, c) => (useColor ? (0, color_js_1.colorize)(s, c) : s);
31
+ const location = (0, index_js_1.formatLocation)(caller, useColor);
32
+ const tagOut = paint(tag, constants_js_1.TAG_COLOR[channel]);
33
+ const timeStamp = paint((0, getTimeStamp_js_1.default)(), "teal");
34
+ const locOut = paint(`(${location})`, "dimTeal");
35
+ const connector = paint(constants_js_1.BRANCH, "gray");
36
+ const connectorBottom = paint(constants_js_1.BRANCH_END, "gray");
37
+ const separator = paint(constants_js_1.SEPARATOR, "gray");
38
+ // Layout: the tag, the message hanging off a `├──` branch, then the timestamp
39
+ // and location on a `└──` branch below. Leading `\n` spaces entries apart.
40
+ const message = (0, index_js_1.renderMessage)(args, useColor);
41
+ const meta = `\n${connectorBottom} ${timeStamp} ${separator} ${locOut}`;
42
+ console[channel](`\n${tagOut}`, `\n${connector}`, message, meta);
43
+ }
@@ -1,32 +1,61 @@
1
- /** The logger: a callable for info logs, plus `.error`, `.warn`, and `.tap`. */
2
- export interface LogFN {
1
+ /** Type of the logger use this to annotate variables or parameters that accept it. */
2
+ export interface Logger {
3
+ /** Log at info level — `stdout`, cyan `[INFO]` tag. */
3
4
  (...args: unknown[]): void;
5
+ /** Log at error level — `stderr`, red `[ERROR]` tag. */
4
6
  error(...args: unknown[]): void;
7
+ /** Log at warn level — `stderr`, yellow `[WARN]` tag. */
5
8
  warn(...args: unknown[]): void;
6
9
  /**
7
- * Logs `value` (optionally tagged with `label`) and returns it **unchanged**,
8
- * so it drops into any expression: `const u = logger.tap(getUser(), "user")`.
9
- * Pass a **promise** (e.g. a `fetch`) and you get the same promise back while
10
- * its elapsed time and the HTTP status if it's a `Response` — is logged in
11
- * the background. Silent in production; the value always flows through.
10
+ * Logs `value` with an optional `label` and gives it straight back unchanged
11
+ * so you can drop it into any expression without adding an extra line.
12
+ *
13
+ * **Sync value**logged immediately, returned as-is:
14
+ * ```ts
15
+ * const port = logger.tap(3000, "port") // logs it, port is still 3000
16
+ * const user = logger.tap(getUser(), "user") // logs the user object, returns it
17
+ * ```
18
+ *
19
+ * **Promise** — the same promise comes back; timing and HTTP status are logged
20
+ * in the background once it settles, without blocking your code:
21
+ * ```ts
22
+ * const res = await logger.tap(fetch(url), "GET /users") // logs status + ms
23
+ * const data = await logger.tap(loadConfig(), "config") // logs value + ms
24
+ * ```
25
+ *
26
+ * @param value Any value or promise — always returned as-is.
27
+ * @param label Optional label shown next to the value in the log line.
12
28
  */
13
29
  tap<T>(value: T, label?: string): T;
14
30
  /**
15
- * How many lines of a multi-line message to show before collapsing the rest
16
- * into a `… N more lines` summary. `0` (the default) shows everything.
31
+ * How many lines to show before the rest collapses into a
32
+ * `… N more lines` summary. `0` (default) shows everything.
33
+ *
34
+ * @example
35
+ * logger.maxLines = 5
17
36
  */
18
37
  maxLines: number;
19
38
  }
20
39
  /**
21
- * Logs to the console, but only outside production. Each line is prefixed with
22
- * a level tag, a short local timestamp, and a clickable link to the file it was
23
- * called from; all arguments are then printed as-is.
40
+ * A logger built for development colored tags, a local timestamp, and a
41
+ * clickable `(file:line)` link on every line so you always know where a
42
+ * message came from. Works like `console.log`: pass anything and it prints.
43
+ *
44
+ * Logs only when `NODE_ENV !== "production"`.
45
+ *
24
46
  * @example
25
- * logger("Auth", "user logged in")
26
- * // [INFO] 05-30 04:00:00 PM (server.ts:42) Auth user logged in
27
- * @example
28
- * logger.maxLines = 5 // long messages collapse to 5 lines; 0 = show all
47
+ * ```ts
48
+ * logger("server started", { port: 3000 })
49
+ * logger.error("db failed", new Error("ECONNREFUSED"))
50
+ * logger.warn("disk above 80%")
51
+ * ```
52
+ *
53
+ * @example Tap — keep the value flowing, log it on the side
54
+ * ```ts
55
+ * const user = logger.tap(await getUser(id), "user")
56
+ * const res = await logger.tap(fetch(url), "GET /users")
57
+ * ```
29
58
  */
30
- declare const logger: LogFN;
59
+ declare const logger: Logger;
31
60
  export { logger };
32
61
  export default logger;
package/dist/cjs/index.js CHANGED
@@ -14,14 +14,24 @@ const createLog_js_1 = __importDefault(require("./core/createLog.js"));
14
14
  const createTap_js_1 = __importDefault(require("./tap/createTap.js"));
15
15
  const index_js_1 = require("./core/writeLog/index.js");
16
16
  /**
17
- * Logs to the console, but only outside production. Each line is prefixed with
18
- * a level tag, a short local timestamp, and a clickable link to the file it was
19
- * called from; all arguments are then printed as-is.
17
+ * A logger built for development colored tags, a local timestamp, and a
18
+ * clickable `(file:line)` link on every line so you always know where a
19
+ * message came from. Works like `console.log`: pass anything and it prints.
20
+ *
21
+ * Logs only when `NODE_ENV !== "production"`.
22
+ *
20
23
  * @example
21
- * logger("Auth", "user logged in")
22
- * // [INFO] 05-30 04:00:00 PM (server.ts:42) Auth user logged in
23
- * @example
24
- * logger.maxLines = 5 // long messages collapse to 5 lines; 0 = show all
24
+ * ```ts
25
+ * logger("server started", { port: 3000 })
26
+ * logger.error("db failed", new Error("ECONNREFUSED"))
27
+ * logger.warn("disk above 80%")
28
+ * ```
29
+ *
30
+ * @example Tap — keep the value flowing, log it on the side
31
+ * ```ts
32
+ * const user = logger.tap(await getUser(id), "user")
33
+ * const res = await logger.tap(fetch(url), "GET /users")
34
+ * ```
25
35
  */
26
36
  const logger = Object.assign((0, createLog_js_1.default)("log", "[INFO]"), {
27
37
  error: (0, createLog_js_1.default)("error", "[ERROR]"),
@@ -10,10 +10,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.default = createTap;
13
+ const config_js_1 = require("../config.js");
13
14
  const getCaller_js_1 = __importDefault(require("../caller/getCaller.js"));
14
15
  const index_js_1 = require("../core/writeLog/index.js");
15
- const config_js_1 = require("../config.js");
16
- const tapAsync_js_1 = require("./tapAsync.js");
16
+ const index_js_2 = require("./tapAsync/index.js");
17
17
  /**
18
18
  * Builds `tap` — logs a value and returns it **unchanged**, so it drops into any
19
19
  * expression (`const u = logger.tap(getUser(), "user")`). The consumer always
@@ -32,10 +32,10 @@ function createTap() {
32
32
  if (!(0, config_js_1.isLogAllowed)())
33
33
  return value;
34
34
  const caller = (0, getCaller_js_1.default)();
35
- if ((0, tapAsync_js_1.isThenable)(value)) {
35
+ if ((0, index_js_2.isThenable)(value)) {
36
36
  // value is a promise → hand off to the async tap (caller passed in so the
37
37
  // location stays on the user's file, not on this helper).
38
- (0, tapAsync_js_1.tapAsync)(value, label, caller);
38
+ (0, index_js_2.tapAsync)(value, label, caller);
39
39
  }
40
40
  else {
41
41
  (0, index_js_1.writeLog)({
@@ -0,0 +1,19 @@
1
+ import { type ResponseLike } from "./response.js";
2
+ /**
3
+ * Renders the nested tree block:
4
+ *
5
+ * GET /users/1
6
+ * │
7
+ * │ response:
8
+ * │ ├── time: 65ms
9
+ * │ ├── status: 200 OK
10
+ * │ └── size: 848 B
11
+ * │
12
+ * │ body:
13
+ * │ ├── id: 1
14
+ * │ └── name: Leanne Graham
15
+ */
16
+ export declare function buildBlock(label: string | undefined, ms: number, res: ResponseLike, body: {
17
+ data: unknown;
18
+ size: string;
19
+ }, useColor: boolean): unknown[];
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ /*
3
+ * buildBlock.ts
4
+ * Created by Dewan Mobashirul
5
+ * Copyright (c) 2026 dewan-meadown
6
+ * All rights reserved
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.buildBlock = buildBlock;
10
+ const node_util_1 = require("node:util");
11
+ const format_js_1 = require("./format.js");
12
+ const color_js_1 = require("../../../colors/color.js");
13
+ const response_js_1 = require("./response.js");
14
+ /**
15
+ * Renders the nested tree block:
16
+ *
17
+ * GET /users/1
18
+ * │
19
+ * │ response:
20
+ * │ ├── time: 65ms
21
+ * │ ├── status: 200 OK
22
+ * │ └── size: 848 B
23
+ * │
24
+ * │ body:
25
+ * │ ├── id: 1
26
+ * │ └── name: Leanne Graham
27
+ */
28
+ function buildBlock(label, ms, res, body, useColor) {
29
+ const paint = (s, c) => useColor ? (0, color_js_1.colorize)(s, c) : s;
30
+ const pipe = paint("│", "gray");
31
+ const branch = paint("├──", "gray");
32
+ const last = paint("└──", "gray");
33
+ const indent = `${pipe} `;
34
+ const timeLine = `${indent}${branch} time: ${(0, format_js_1.formatDuration)(ms, useColor)}`;
35
+ const statusLine = `${indent}${branch} status: ${(0, response_js_1.formatStatus)(res, useColor)}`;
36
+ const sizeLine = `${indent}${last} size: ${body.size}`;
37
+ const responseLines = [
38
+ `${pipe}`,
39
+ `${indent}response:`,
40
+ timeLine,
41
+ statusLine,
42
+ sizeLine,
43
+ ];
44
+ const head = label === undefined ? "" : `${label}\n`;
45
+ if (body.data === undefined) {
46
+ return [`${head}${responseLines.join("\n")}`];
47
+ }
48
+ const bodyText = (0, node_util_1.formatWithOptions)({ colors: useColor }, body.data);
49
+ const bodyLines = bodyText.split("\n");
50
+ const lastIdx = bodyLines.length - 1;
51
+ const bodyBlock = bodyLines
52
+ .map((line, i) => `${indent}${i === lastIdx ? last : branch} ${line}`)
53
+ .join("\n");
54
+ const full = [...responseLines, `${pipe}`, `${indent}body:`, bodyBlock].join("\n");
55
+ return [`${head}${full}`];
56
+ }
@@ -0,0 +1,4 @@
1
+ /** `65ms` (green) · `1.2s` (yellow) · `5.8s` (red). */
2
+ export declare function formatDuration(ms: number, useColor: boolean): string;
3
+ /** `848 B` / `1.84 KB` / `2.10 MB`. */
4
+ export declare function formatBytes(bytes: number): string;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ /*
3
+ * format.ts
4
+ * Created by Dewan Mobashirul
5
+ * Copyright (c) 2026 dewan-meadown
6
+ * All rights reserved
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.formatDuration = formatDuration;
10
+ exports.formatBytes = formatBytes;
11
+ const color_js_1 = require("../../../colors/color.js");
12
+ /** `65ms` (green) · `1.2s` (yellow) · `5.8s` (red). */
13
+ function formatDuration(ms, useColor) {
14
+ const text = ms >= 1000 ? `${(ms / 1000).toFixed(2)}s` : `${ms}ms`;
15
+ if (!useColor)
16
+ return text;
17
+ if (ms >= 2000)
18
+ return (0, color_js_1.colorize)(text, "red");
19
+ if (ms >= 500)
20
+ return (0, color_js_1.colorize)(text, "yellow");
21
+ return (0, color_js_1.colorize)(text, "green");
22
+ }
23
+ /** `848 B` / `1.84 KB` / `2.10 MB`. */
24
+ function formatBytes(bytes) {
25
+ if (bytes < 1024)
26
+ return `${bytes} B`;
27
+ if (bytes < 1024 * 1024)
28
+ return `${(bytes / 1024).toFixed(2)} KB`;
29
+ return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;
30
+ }
@@ -0,0 +1,4 @@
1
+ export { readBody, isResponse, formatStatus, type ResponseLike, } from "./response.js";
2
+ export { buildBlock } from "./buildBlock.js";
3
+ export { isThenable } from "./isThenable.js";
4
+ export { formatDuration, formatBytes } from "./format.js";
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ /*
3
+ * index.ts
4
+ * Created by Dewan Mobashirul
5
+ * Copyright (c) 2026 dewan-meadown
6
+ * All rights reserved
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.formatBytes = exports.formatDuration = exports.isThenable = exports.buildBlock = exports.formatStatus = exports.isResponse = exports.readBody = void 0;
10
+ var response_js_1 = require("./response.js");
11
+ Object.defineProperty(exports, "readBody", { enumerable: true, get: function () { return response_js_1.readBody; } });
12
+ Object.defineProperty(exports, "isResponse", { enumerable: true, get: function () { return response_js_1.isResponse; } });
13
+ Object.defineProperty(exports, "formatStatus", { enumerable: true, get: function () { return response_js_1.formatStatus; } });
14
+ var buildBlock_js_1 = require("./buildBlock.js");
15
+ Object.defineProperty(exports, "buildBlock", { enumerable: true, get: function () { return buildBlock_js_1.buildBlock; } });
16
+ var isThenable_js_1 = require("./isThenable.js");
17
+ Object.defineProperty(exports, "isThenable", { enumerable: true, get: function () { return isThenable_js_1.isThenable; } });
18
+ var format_js_1 = require("./format.js");
19
+ Object.defineProperty(exports, "formatDuration", { enumerable: true, get: function () { return format_js_1.formatDuration; } });
20
+ Object.defineProperty(exports, "formatBytes", { enumerable: true, get: function () { return format_js_1.formatBytes; } });
@@ -0,0 +1,2 @@
1
+ /** Whether `value` is thenable (a promise we can await + time). */
2
+ export declare function isThenable(value: unknown): value is PromiseLike<unknown>;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ /*
3
+ * isThenable.ts
4
+ * Created by Dewan Mobashirul
5
+ * Copyright (c) 2026 dewan-meadown
6
+ * All rights reserved
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.isThenable = isThenable;
10
+ /** Whether `value` is thenable (a promise we can await + time). */
11
+ function isThenable(value) {
12
+ return (typeof value === "object" &&
13
+ value !== null &&
14
+ typeof value.then === "function");
15
+ }
@@ -0,0 +1,21 @@
1
+ export type ResponseLike = {
2
+ status: number;
3
+ statusText?: unknown;
4
+ headers?: {
5
+ get?: (name: string) => string | null;
6
+ };
7
+ clone: () => ResponseLike;
8
+ text: () => Promise<string>;
9
+ };
10
+ /** Whether the resolved value is a fetch `Response` we can read. */
11
+ export declare function isResponse(value: unknown): value is ResponseLike;
12
+ export declare function formatStatus(res: ResponseLike, useColor: boolean): string;
13
+ /**
14
+ * Reads a (cloned) response body and returns both the parsed value and the
15
+ * actual byte size. Size is calculated from the body text — not `Content-Length`,
16
+ * which is absent on compressed responses — so size is always shown.
17
+ */
18
+ export declare function readBody(res: ResponseLike): Promise<{
19
+ data: unknown;
20
+ size: string;
21
+ }>;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ /*
3
+ * response.ts
4
+ * Created by Dewan Mobashirul
5
+ * Copyright (c) 2026 dewan-meadown
6
+ * All rights reserved
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.isResponse = isResponse;
10
+ exports.formatStatus = formatStatus;
11
+ exports.readBody = readBody;
12
+ const format_js_1 = require("./format.js");
13
+ const color_js_1 = require("../../../colors/color.js");
14
+ /** Whether the resolved value is a fetch `Response` we can read. */
15
+ function isResponse(value) {
16
+ const v = value;
17
+ return (typeof v?.status === "number" &&
18
+ typeof v.clone === "function" &&
19
+ typeof v.text === "function");
20
+ }
21
+ /**
22
+ * Status badge color:
23
+ * 2xx → green · 3xx → cyan · 4xx → yellow · 5xx → red
24
+ */
25
+ function statusColor(status) {
26
+ if (status >= 500)
27
+ return "red";
28
+ if (status >= 400)
29
+ return "yellow";
30
+ if (status >= 300)
31
+ return "cyan";
32
+ return "green";
33
+ }
34
+ function formatStatus(res, useColor) {
35
+ const text = typeof res.statusText === "string" && res.statusText
36
+ ? `${res.status} ${res.statusText}`
37
+ : `${res.status}`;
38
+ return useColor ? (0, color_js_1.colorize)(text, statusColor(res.status)) : text;
39
+ }
40
+ /**
41
+ * Reads a (cloned) response body and returns both the parsed value and the
42
+ * actual byte size. Size is calculated from the body text — not `Content-Length`,
43
+ * which is absent on compressed responses — so size is always shown.
44
+ */
45
+ async function readBody(res) {
46
+ try {
47
+ const text = await res.text();
48
+ const bytes = new TextEncoder().encode(text).length;
49
+ const size = (0, format_js_1.formatBytes)(bytes);
50
+ if (text === "")
51
+ return { data: undefined, size };
52
+ try {
53
+ return { data: JSON.parse(text), size };
54
+ }
55
+ catch {
56
+ return { data: text, size };
57
+ }
58
+ }
59
+ catch {
60
+ return { data: undefined, size: "unknown" };
61
+ }
62
+ }
@@ -0,0 +1,2 @@
1
+ export { tapAsync } from "./tapAsync.js";
2
+ export { isThenable } from "./helpers/index.js";
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ /*
3
+ * index.ts
4
+ * Created by Dewan Mobashirul
5
+ * Copyright (c) 2026 dewan-meadown
6
+ * All rights reserved
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.isThenable = exports.tapAsync = void 0;
10
+ var tapAsync_js_1 = require("./tapAsync.js");
11
+ Object.defineProperty(exports, "tapAsync", { enumerable: true, get: function () { return tapAsync_js_1.tapAsync; } });
12
+ var index_js_1 = require("./helpers/index.js");
13
+ Object.defineProperty(exports, "isThenable", { enumerable: true, get: function () { return index_js_1.isThenable; } });
@@ -1,6 +1,4 @@
1
- import { type Caller } from "../caller/getCaller.js";
2
- /** Whether `value` is thenable (a promise we can await + time). */
3
- export declare function isThenable(value: unknown): value is PromiseLike<unknown>;
1
+ import { type Caller } from "../../caller/getCaller.js";
4
2
  /**
5
3
  * The async tap. Fire-and-forget: returns `promise` immediately (unchanged),
6
4
  * and logs a rich block once it resolves. For a `Response`, reads the body from