@orkestrel/console 0.0.16 → 0.0.17
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/dist/src/browser/index.d.ts +8 -0
- package/dist/src/browser/index.js +37 -45
- package/dist/src/browser/index.js.map +1 -1
- package/dist/src/core/index.cjs +76 -46
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +23 -0
- package/dist/src/core/index.d.ts +23 -0
- package/dist/src/core/index.js +76 -48
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/server/index.cjs +5 -10
- package/dist/src/server/index.cjs.map +1 -1
- package/dist/src/server/index.js +5 -10
- package/dist/src/server/index.js.map +1 -1
- package/package.json +18 -18
|
@@ -952,6 +952,20 @@ export declare const LEVEL_COLORS: Readonly<Record<LogLevel, Exclude<Color, 'def
|
|
|
952
952
|
*/
|
|
953
953
|
export declare const LEVEL_SEVERITY: Readonly<Record<LogLevel, number>>;
|
|
954
954
|
|
|
955
|
+
/**
|
|
956
|
+
* Yields a position for each requested blank line without allocating the whole sequence.
|
|
957
|
+
* @example
|
|
958
|
+
* ```ts
|
|
959
|
+
* [...new LineIterator(2)] // [0, 1]
|
|
960
|
+
* ```
|
|
961
|
+
*/
|
|
962
|
+
export declare class LineIterator implements IterableIterator<number> {
|
|
963
|
+
#private;
|
|
964
|
+
constructor(count: number);
|
|
965
|
+
next(): IteratorResult<number>;
|
|
966
|
+
[Symbol.iterator](): IterableIterator<number>;
|
|
967
|
+
}
|
|
968
|
+
|
|
955
969
|
/**
|
|
956
970
|
* Lists every {@link LogLevel}, in ascending severity order — the levels a logger exposes as
|
|
957
971
|
* methods and the manager fans out to. The source of truth for the level axis (drives
|
|
@@ -1540,6 +1554,15 @@ export declare function renderBar(options: BarOptions): string;
|
|
|
1540
1554
|
*/
|
|
1541
1555
|
export declare function renderBox(options: BoxOptions): string;
|
|
1542
1556
|
|
|
1557
|
+
/**
|
|
1558
|
+
* Renders a box's top border across the supplied inner span.
|
|
1559
|
+
* @example
|
|
1560
|
+
* ```ts
|
|
1561
|
+
* renderBoxTop({ content: '' }, 3) // '┌───┐'
|
|
1562
|
+
* ```
|
|
1563
|
+
*/
|
|
1564
|
+
export declare function renderBoxTop(options: BoxOptions, span: number): string;
|
|
1565
|
+
|
|
1543
1566
|
/**
|
|
1544
1567
|
* Declares a swappable style renderer — the seam that turns style data into output for one
|
|
1545
1568
|
* target. The cross-environment default is the ANSI renderer (SGR escape codes); a
|
package/dist/src/core/index.d.ts
CHANGED
|
@@ -952,6 +952,20 @@ export declare const LEVEL_COLORS: Readonly<Record<LogLevel, Exclude<Color, 'def
|
|
|
952
952
|
*/
|
|
953
953
|
export declare const LEVEL_SEVERITY: Readonly<Record<LogLevel, number>>;
|
|
954
954
|
|
|
955
|
+
/**
|
|
956
|
+
* Yields a position for each requested blank line without allocating the whole sequence.
|
|
957
|
+
* @example
|
|
958
|
+
* ```ts
|
|
959
|
+
* [...new LineIterator(2)] // [0, 1]
|
|
960
|
+
* ```
|
|
961
|
+
*/
|
|
962
|
+
export declare class LineIterator implements IterableIterator<number> {
|
|
963
|
+
#private;
|
|
964
|
+
constructor(count: number);
|
|
965
|
+
next(): IteratorResult<number>;
|
|
966
|
+
[Symbol.iterator](): IterableIterator<number>;
|
|
967
|
+
}
|
|
968
|
+
|
|
955
969
|
/**
|
|
956
970
|
* Lists every {@link LogLevel}, in ascending severity order — the levels a logger exposes as
|
|
957
971
|
* methods and the manager fans out to. The source of truth for the level axis (drives
|
|
@@ -1540,6 +1554,15 @@ export declare function renderBar(options: BarOptions): string;
|
|
|
1540
1554
|
*/
|
|
1541
1555
|
export declare function renderBox(options: BoxOptions): string;
|
|
1542
1556
|
|
|
1557
|
+
/**
|
|
1558
|
+
* Renders a box's top border across the supplied inner span.
|
|
1559
|
+
* @example
|
|
1560
|
+
* ```ts
|
|
1561
|
+
* renderBoxTop({ content: '' }, 3) // '┌───┐'
|
|
1562
|
+
* ```
|
|
1563
|
+
*/
|
|
1564
|
+
export declare function renderBoxTop(options: BoxOptions, span: number): string;
|
|
1565
|
+
|
|
1543
1566
|
/**
|
|
1544
1567
|
* Declares a swappable style renderer — the seam that turns style data into output for one
|
|
1545
1568
|
* target. The cross-environment default is the ANSI renderer (SGR escape codes); a
|
package/dist/src/core/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { isArray, isError, isFunction, isInstance, isObject } from "@orkestrel/contract";
|
|
1
|
+
import { INTRINSICS, holds, isArray, isError, isFunction, isInstance, isObject, isString } from "@orkestrel/contract";
|
|
2
2
|
import { Emitter } from "@orkestrel/emitter";
|
|
3
|
-
|
|
3
|
+
// src/core/constants.ts
|
|
4
4
|
/**
|
|
5
5
|
* Maps each {@link Color} to its SGR foreground parameter — the 8 base colors at 30–37 and their
|
|
6
6
|
* bright variants at 90–97. `default` is intentionally absent (it emits no code).
|
|
@@ -111,7 +111,7 @@ var BEL = String.fromCharCode(7);
|
|
|
111
111
|
/** Holds the Control Sequence Introducer (`ESC[`) that opens every SGR sequence. */
|
|
112
112
|
var CSI = `[`;
|
|
113
113
|
/** Holds the full SGR reset sequence (`ESC[0m`) appended after a styled run. */
|
|
114
|
-
var RESET =
|
|
114
|
+
var RESET = `[0m`;
|
|
115
115
|
/**
|
|
116
116
|
* Matches any ANSI/VT escape sequence — CSI (SGR color/style plus cursor/erase/scroll,
|
|
117
117
|
* including colon-parameterized SGR), OSC / DCS / PM / APC / SOS string sequences
|
|
@@ -484,8 +484,7 @@ var DEFAULT_THEME = Object.freeze({
|
|
|
484
484
|
}),
|
|
485
485
|
chrome: Object.freeze({ attributes: Object.freeze(["dim"]) })
|
|
486
486
|
});
|
|
487
|
-
|
|
488
|
-
//#region src/core/errors.ts
|
|
487
|
+
// src/core/errors.ts
|
|
489
488
|
/**
|
|
490
489
|
* Carries a {@link ConsoleErrorCode} and an optional `context` bag — the error the console layer
|
|
491
490
|
* throws for an internal invariant violated at a defensive guard.
|
|
@@ -499,6 +498,7 @@ var ConsoleError = class extends Error {
|
|
|
499
498
|
context;
|
|
500
499
|
constructor(code, message, context) {
|
|
501
500
|
super(message);
|
|
501
|
+
Object.defineProperty(this, Symbol.for("@orkestrel/console.ConsoleError"), { value: this });
|
|
502
502
|
this.name = "ConsoleError";
|
|
503
503
|
this.code = code;
|
|
504
504
|
if (context !== void 0) this.context = context;
|
|
@@ -520,10 +520,14 @@ var ConsoleError = class extends Error {
|
|
|
520
520
|
* ```
|
|
521
521
|
*/
|
|
522
522
|
function isConsoleError(value) {
|
|
523
|
-
return
|
|
523
|
+
return holds(() => {
|
|
524
|
+
if (!isInstance(value, Error) || INTRINSICS.prototype(value) === Error.prototype) return false;
|
|
525
|
+
if (INTRINSICS.describe(value, Symbol.for("@orkestrel/console.ConsoleError"))?.value !== value) return false;
|
|
526
|
+
const context = INTRINSICS.reflect.read(value, "context");
|
|
527
|
+
return INTRINSICS.reflect.read(value, "code") === "INVARIANT" && isString(INTRINSICS.reflect.read(value, "message")) && (context === void 0 || isObject(context) || isFunction(context));
|
|
528
|
+
});
|
|
524
529
|
}
|
|
525
|
-
|
|
526
|
-
//#region src/core/helpers.ts
|
|
530
|
+
// src/core/helpers.ts
|
|
527
531
|
/**
|
|
528
532
|
* Removes every ANSI escape sequence from `text`, returning the plain visible string.
|
|
529
533
|
*
|
|
@@ -887,23 +891,32 @@ function renderBox(options) {
|
|
|
887
891
|
const inner = lines.reduce((max, line) => Math.max(max, width(line)), Math.max(0, titleRoom, budget));
|
|
888
892
|
const gutter = " ".repeat(padding);
|
|
889
893
|
const bar = paint(styler, chars.vertical, options.style);
|
|
890
|
-
const
|
|
891
|
-
|
|
892
|
-
|
|
894
|
+
const top = renderBoxTop(options, inner + padding * 2);
|
|
895
|
+
const bottom = paint(styler, `${chars.bottomLeft}${repeatTo(chars.horizontal, inner + padding * 2)}${chars.bottomRight}`, options.style);
|
|
896
|
+
return [
|
|
897
|
+
top,
|
|
898
|
+
...lines.map((line) => `${bar}${gutter}${align(line, inner)}${gutter}${bar}`),
|
|
899
|
+
bottom
|
|
900
|
+
].join("\n");
|
|
901
|
+
}
|
|
902
|
+
/**
|
|
903
|
+
* Renders a box's top border across the supplied inner span.
|
|
904
|
+
* @example
|
|
905
|
+
* ```ts
|
|
906
|
+
* renderBoxTop({ content: '' }, 3) // '┌───┐'
|
|
907
|
+
* ```
|
|
908
|
+
*/
|
|
909
|
+
function renderBoxTop(options, span) {
|
|
910
|
+
const chars = BORDER_CHARS[options.border ?? "single"];
|
|
911
|
+
const styler = options.styler;
|
|
912
|
+
if (options.title === void 0) return paint(styler, `${chars.topLeft}${repeatTo(chars.horizontal, span)}${chars.topRight}`, options.style);
|
|
893
913
|
else {
|
|
894
914
|
const caption = ` ${options.title} `;
|
|
895
915
|
const room = span - width(caption);
|
|
896
916
|
const lead = paint(styler, repeatTo(chars.horizontal, 1), options.style);
|
|
897
917
|
const rest = room - 1 <= 0 ? "" : paint(styler, repeatTo(chars.horizontal, room - 1), options.style);
|
|
898
|
-
|
|
918
|
+
return `${paint(styler, chars.topLeft, options.style)}${lead}${paint(styler, caption, options.style)}${rest}${paint(styler, chars.topRight, options.style)}`;
|
|
899
919
|
}
|
|
900
|
-
const bottom = paint(styler, `${chars.bottomLeft}${repeatTo(chars.horizontal, inner + padding * 2)}${chars.bottomRight}`, options.style);
|
|
901
|
-
const body = lines.map((line) => `${bar}${gutter}${align(line, inner)}${gutter}${bar}`);
|
|
902
|
-
return [
|
|
903
|
-
top,
|
|
904
|
-
...body,
|
|
905
|
-
bottom
|
|
906
|
-
].join("\n");
|
|
907
920
|
}
|
|
908
921
|
/**
|
|
909
922
|
* Renders a bordered grid of `columns` + `rows` with per-column alignment and width-aware
|
|
@@ -1127,8 +1140,7 @@ function renderBar(options) {
|
|
|
1127
1140
|
const filledCells = Math.round(fraction * track);
|
|
1128
1141
|
return `${`${paint(options.styler, repeatTo(fill, filledCells), options.style)}${repeatTo(empty, track - filledCells)}`} ${Math.round(fraction * 100)}% (${current}/${options.total})`;
|
|
1129
1142
|
}
|
|
1130
|
-
|
|
1131
|
-
//#region src/core/renderers/ANSIRenderer.ts
|
|
1143
|
+
// src/core/renderers/ANSIRenderer.ts
|
|
1132
1144
|
/**
|
|
1133
1145
|
* Implements the cross-environment default {@link RendererInterface} — renders style data as ANSI
|
|
1134
1146
|
* SGR escape codes, stateless and event-free.
|
|
@@ -1160,7 +1172,7 @@ var ANSIRenderer = class {
|
|
|
1160
1172
|
if (text === "") return text;
|
|
1161
1173
|
const codes = this.#codes(style);
|
|
1162
1174
|
if (codes.length === 0) return text;
|
|
1163
|
-
return
|
|
1175
|
+
return `[${codes.join(";")}m${text}${RESET}`;
|
|
1164
1176
|
}
|
|
1165
1177
|
#codes(style) {
|
|
1166
1178
|
const codes = [];
|
|
@@ -1170,8 +1182,7 @@ var ANSIRenderer = class {
|
|
|
1170
1182
|
return codes;
|
|
1171
1183
|
}
|
|
1172
1184
|
};
|
|
1173
|
-
|
|
1174
|
-
//#region src/core/Retention.ts
|
|
1185
|
+
// src/core/Retention.ts
|
|
1175
1186
|
/**
|
|
1176
1187
|
* Implements the bounded, level-keyed retention engine the console and process captures buffer
|
|
1177
1188
|
* through — one capped total buffer
|
|
@@ -1227,8 +1238,7 @@ var Retention = class {
|
|
|
1227
1238
|
if (buffer.length > this.#limit) buffer.shift();
|
|
1228
1239
|
}
|
|
1229
1240
|
};
|
|
1230
|
-
|
|
1231
|
-
//#region src/core/Capture.ts
|
|
1241
|
+
// src/core/Capture.ts
|
|
1232
1242
|
/**
|
|
1233
1243
|
* Implements an observable console interceptor — it takes control of the global `console.*` on
|
|
1234
1244
|
* the read side. While `active`, every configured `console.x` call is captured as a frozen
|
|
@@ -1335,8 +1345,7 @@ var Capture = class {
|
|
|
1335
1345
|
});
|
|
1336
1346
|
}
|
|
1337
1347
|
};
|
|
1338
|
-
|
|
1339
|
-
//#region src/core/Styler.ts
|
|
1348
|
+
// src/core/Styler.ts
|
|
1340
1349
|
/**
|
|
1341
1350
|
* Builds the fluent, composable styling surface — the consumer-facing API over the style
|
|
1342
1351
|
* engine. It
|
|
@@ -1478,8 +1487,7 @@ var Styler = class Styler {
|
|
|
1478
1487
|
}));
|
|
1479
1488
|
}
|
|
1480
1489
|
};
|
|
1481
|
-
|
|
1482
|
-
//#region src/core/factories.ts
|
|
1490
|
+
// src/core/factories.ts
|
|
1483
1491
|
/**
|
|
1484
1492
|
* Creates the fluent, composable {@link StylerInterface} — ANSI by default, retargeted by a
|
|
1485
1493
|
* `renderer` and stripped of color by `enabled: false`.
|
|
@@ -1626,8 +1634,7 @@ function createCaptureResult(fn, options) {
|
|
|
1626
1634
|
throw error;
|
|
1627
1635
|
}
|
|
1628
1636
|
}
|
|
1629
|
-
|
|
1630
|
-
//#region src/core/loggers/Logger.ts
|
|
1637
|
+
// src/core/loggers/Logger.ts
|
|
1631
1638
|
/**
|
|
1632
1639
|
* Implements an observable, leveled logger — the entry point into the structured-logging
|
|
1633
1640
|
* pipeline. Each `debug` / `info` / `warn` / `error` call builds a frozen {@link LogRecord},
|
|
@@ -1737,8 +1744,7 @@ var Logger = class {
|
|
|
1737
1744
|
if (this.#entries.length > this.#limit) this.#entries.shift();
|
|
1738
1745
|
}
|
|
1739
1746
|
};
|
|
1740
|
-
|
|
1741
|
-
//#region src/core/loggers/LoggerManager.ts
|
|
1747
|
+
// src/core/loggers/LoggerManager.ts
|
|
1742
1748
|
/**
|
|
1743
1749
|
* Implements an event-free registry of named {@link Logger}s plus a convenience fan-out — the
|
|
1744
1750
|
* manager over the logging layer (a registry, never observable itself; each {@link Logger}
|
|
@@ -1832,16 +1838,41 @@ var LoggerManager = class {
|
|
|
1832
1838
|
this.#loggers.clear();
|
|
1833
1839
|
return;
|
|
1834
1840
|
}
|
|
1835
|
-
if (isArray(names))
|
|
1836
|
-
let removed = true;
|
|
1837
|
-
for (const name of names) if (!this.#loggers.delete(name)) removed = false;
|
|
1838
|
-
return removed;
|
|
1839
|
-
}
|
|
1841
|
+
if (isArray(names)) return Iterator.from(names).reduce((removed, name) => this.#loggers.delete(name) && removed, true);
|
|
1840
1842
|
return this.#loggers.delete(names);
|
|
1841
1843
|
}
|
|
1842
1844
|
};
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
+
// src/core/LineIterator.ts
|
|
1846
|
+
/**
|
|
1847
|
+
* Yields a position for each requested blank line without allocating the whole sequence.
|
|
1848
|
+
* @example
|
|
1849
|
+
* ```ts
|
|
1850
|
+
* [...new LineIterator(2)] // [0, 1]
|
|
1851
|
+
* ```
|
|
1852
|
+
*/
|
|
1853
|
+
var LineIterator = class {
|
|
1854
|
+
#count;
|
|
1855
|
+
#index = 0;
|
|
1856
|
+
constructor(count) {
|
|
1857
|
+
this.#count = count;
|
|
1858
|
+
}
|
|
1859
|
+
next() {
|
|
1860
|
+
if (!(this.#index < this.#count)) return {
|
|
1861
|
+
done: true,
|
|
1862
|
+
value: void 0
|
|
1863
|
+
};
|
|
1864
|
+
const value = this.#index;
|
|
1865
|
+
this.#index += 1;
|
|
1866
|
+
return {
|
|
1867
|
+
done: false,
|
|
1868
|
+
value
|
|
1869
|
+
};
|
|
1870
|
+
}
|
|
1871
|
+
[Symbol.iterator]() {
|
|
1872
|
+
return this;
|
|
1873
|
+
}
|
|
1874
|
+
};
|
|
1875
|
+
// src/core/Reporter.ts
|
|
1845
1876
|
/**
|
|
1846
1877
|
* Implements a lean, event-free narrative reporter — the composable verb set for human /
|
|
1847
1878
|
* build-run output. Each verb formats its line through the shared {@link StylerInterface} and
|
|
@@ -1919,7 +1950,7 @@ var Reporter = class {
|
|
|
1919
1950
|
this.#sink.write(text);
|
|
1920
1951
|
}
|
|
1921
1952
|
blank(count = 1) {
|
|
1922
|
-
|
|
1953
|
+
Iterator.from(new LineIterator(count)).forEach(() => this.#sink.write(""));
|
|
1923
1954
|
}
|
|
1924
1955
|
#resolveStyle(options) {
|
|
1925
1956
|
return {
|
|
@@ -1929,8 +1960,7 @@ var Reporter = class {
|
|
|
1929
1960
|
};
|
|
1930
1961
|
}
|
|
1931
1962
|
};
|
|
1932
|
-
|
|
1933
|
-
//#region src/core/Spinner.ts
|
|
1963
|
+
// src/core/Spinner.ts
|
|
1934
1964
|
/**
|
|
1935
1965
|
* Implements a self-driving, observable activity spinner — a glyph cycle that advances on a
|
|
1936
1966
|
* periodic timer, writing each `\r` + frame line to its {@link SinkInterface} and emitting it on
|
|
@@ -2048,8 +2078,7 @@ var Spinner = class {
|
|
|
2048
2078
|
this.#sink.write(`\r${line}`);
|
|
2049
2079
|
}
|
|
2050
2080
|
};
|
|
2051
|
-
|
|
2052
|
-
//#region src/core/Progress.ts
|
|
2081
|
+
// src/core/Progress.ts
|
|
2053
2082
|
/**
|
|
2054
2083
|
* Implements an update-driven, observable progress bar — {@link update} recomputes the bar through
|
|
2055
2084
|
* {@link renderBar}, writes `\r` + bar to its {@link SinkInterface}, and emits the `{ current,
|
|
@@ -2168,7 +2197,6 @@ var Progress = class {
|
|
|
2168
2197
|
this.#sink.write(`\r${line}${final ? "\n" : ""}`, level);
|
|
2169
2198
|
}
|
|
2170
2199
|
};
|
|
2171
|
-
|
|
2172
|
-
export { ANSIRenderer, ANSI_PATTERN, ATTRIBUTES, ATTRIBUTE_CODES, BACKGROUND_CODES, BAR_EMPTY, BAR_FILL, BEL, BORDER_CHARS, CAPTURE_LEVELS, CAPTURE_LEVEL_MAP, COLORS, CONTROL_PATTERN, CSI, Capture, ConsoleError, DEFAULT_ALIGN, DEFAULT_BAR_WIDTH, DEFAULT_BORDER, DEFAULT_CAPTURE_LIMIT, DEFAULT_LOG_LEVEL, DEFAULT_LOG_LIMIT, DEFAULT_PADDING, DEFAULT_SPINNER_INTERVAL, DEFAULT_THEME, DEFAULT_WIDTH, EMPTY_STYLE, ESC, FOREGROUND_CODES, LEVEL_COLORS, LEVEL_SEVERITY, LOG_LEVELS, Logger, LoggerManager, Progress, RESET, RESET_CODE, Reporter, Retention, SECOND_MS, SEPARATOR_FILL, SEPARATOR_TITLE_GAP, SPINNER_FRAMES, STATUS_COLORS, STATUS_ICONS, STATUS_LEVELS, Spinner, align, cellAt, createCaptureResult, createConsoleSink, createStyler, createTheme, formatArgs, formatDuration, formatRecord, formatTime, freezeStyle, isConsoleError, meetsLevel, paint, renderBar, renderBox, renderSeparator, renderTable, renderTree, renderTreeChildren, repeatTo, selectWriter, stringifyValue, strip, stripControls, width };
|
|
2200
|
+
export { ANSIRenderer, ANSI_PATTERN, ATTRIBUTES, ATTRIBUTE_CODES, BACKGROUND_CODES, BAR_EMPTY, BAR_FILL, BEL, BORDER_CHARS, CAPTURE_LEVELS, CAPTURE_LEVEL_MAP, COLORS, CONTROL_PATTERN, CSI, Capture, ConsoleError, DEFAULT_ALIGN, DEFAULT_BAR_WIDTH, DEFAULT_BORDER, DEFAULT_CAPTURE_LIMIT, DEFAULT_LOG_LEVEL, DEFAULT_LOG_LIMIT, DEFAULT_PADDING, DEFAULT_SPINNER_INTERVAL, DEFAULT_THEME, DEFAULT_WIDTH, EMPTY_STYLE, ESC, FOREGROUND_CODES, LEVEL_COLORS, LEVEL_SEVERITY, LOG_LEVELS, LineIterator, Logger, LoggerManager, Progress, RESET, RESET_CODE, Reporter, Retention, SECOND_MS, SEPARATOR_FILL, SEPARATOR_TITLE_GAP, SPINNER_FRAMES, STATUS_COLORS, STATUS_ICONS, STATUS_LEVELS, Spinner, align, cellAt, createCaptureResult, createConsoleSink, createStyler, createTheme, formatArgs, formatDuration, formatRecord, formatTime, freezeStyle, isConsoleError, meetsLevel, paint, renderBar, renderBox, renderBoxTop, renderSeparator, renderTable, renderTree, renderTreeChildren, repeatTo, selectWriter, stringifyValue, strip, stripControls, width };
|
|
2173
2201
|
|
|
2174
2202
|
//# sourceMappingURL=index.js.map
|