@optique/logtape 1.0.0-dev.1410 → 1.0.0-dev.1424
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/index.cjs +22 -0
- package/dist/index.d.cts +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +22 -0
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -42,6 +42,17 @@ const LOG_LEVELS = [
|
|
|
42
42
|
"fatal"
|
|
43
43
|
];
|
|
44
44
|
/**
|
|
45
|
+
* Validates that the given value is a valid {@link LogLevel}.
|
|
46
|
+
*
|
|
47
|
+
* @param value The value to validate.
|
|
48
|
+
* @param paramName The parameter name for the error message.
|
|
49
|
+
* @throws {TypeError} If the value is not a valid log level.
|
|
50
|
+
* @since 1.0.0
|
|
51
|
+
*/
|
|
52
|
+
function validateLogLevel(value, paramName) {
|
|
53
|
+
if (!LOG_LEVELS.includes(value)) throw new TypeError(`Invalid log level for ${paramName}: ${String(value)}. Expected ${LOG_LEVELS.map((l) => `"${l}"`).join(", ")}.`);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
45
56
|
* Creates a {@link ValueParser} for LogTape log levels.
|
|
46
57
|
*
|
|
47
58
|
* This parser validates that the input is one of the valid LogTape severity
|
|
@@ -114,6 +125,7 @@ const WARNING_INDEX = 2;
|
|
|
114
125
|
*
|
|
115
126
|
* @param options Configuration options for the verbosity parser.
|
|
116
127
|
* @returns A {@link Parser} that produces a {@link LogLevel}.
|
|
128
|
+
* @throws {TypeError} If `baseLevel` is not a valid log level.
|
|
117
129
|
*
|
|
118
130
|
* @example Basic usage
|
|
119
131
|
* ```typescript
|
|
@@ -148,6 +160,7 @@ function verbosity(options = {}) {
|
|
|
148
160
|
const short = options.short ?? "-v";
|
|
149
161
|
const long = options.long ?? "--verbose";
|
|
150
162
|
const baseLevel = options.baseLevel ?? "warning";
|
|
163
|
+
validateLogLevel(baseLevel, "baseLevel");
|
|
151
164
|
const baseIndex = VERBOSITY_LEVELS.indexOf(baseLevel);
|
|
152
165
|
const effectiveBaseIndex = baseIndex >= 0 ? baseIndex : WARNING_INDEX;
|
|
153
166
|
const flagParser = (0, __optique_core_primitives.flag)(short, long, { description: options.description ?? __optique_core_message.message`Be more verbose. Can be repeated.` });
|
|
@@ -170,6 +183,8 @@ function verbosity(options = {}) {
|
|
|
170
183
|
*
|
|
171
184
|
* @param options Configuration options for the debug flag parser.
|
|
172
185
|
* @returns A {@link Parser} that produces a {@link LogLevel}.
|
|
186
|
+
* @throws {TypeError} If `debugLevel` or `normalLevel` is not a valid log
|
|
187
|
+
* level.
|
|
173
188
|
*
|
|
174
189
|
* @example Basic usage
|
|
175
190
|
* ```typescript
|
|
@@ -203,6 +218,8 @@ function debug(options = {}) {
|
|
|
203
218
|
const long = options.long ?? "--debug";
|
|
204
219
|
const debugLevel = options.debugLevel ?? "debug";
|
|
205
220
|
const normalLevel = options.normalLevel ?? "info";
|
|
221
|
+
validateLogLevel(debugLevel, "debugLevel");
|
|
222
|
+
validateLogLevel(normalLevel, "normalLevel");
|
|
206
223
|
const flagParser = (0, __optique_core_primitives.flag)(short, long, { description: options.description ?? __optique_core_message.message`Enable debug logging.` });
|
|
207
224
|
return (0, __optique_core_modifiers.map)((0, __optique_core_modifiers.optional)(flagParser), (value) => {
|
|
208
225
|
return value === true ? debugLevel : normalLevel;
|
|
@@ -460,6 +477,9 @@ Original error: ${e}`);
|
|
|
460
477
|
* // --debug
|
|
461
478
|
* ```
|
|
462
479
|
*
|
|
480
|
+
* @throws {TypeError} If the `level` discriminant is not one of `"option"`,
|
|
481
|
+
* `"verbosity"`, or `"debug"`, or if a log level option (`default`,
|
|
482
|
+
* `debugLevel`, `normalLevel`, or `baseLevel`) is not a valid log level.
|
|
463
483
|
* @since 0.8.0
|
|
464
484
|
*/
|
|
465
485
|
function loggingOptions(config) {
|
|
@@ -472,6 +492,7 @@ function loggingOptions(config) {
|
|
|
472
492
|
const long = config.long ?? "--log-level";
|
|
473
493
|
const short = config.short ?? "-l";
|
|
474
494
|
const defaultLevel = config.default ?? "info";
|
|
495
|
+
validateLogLevel(defaultLevel, "default");
|
|
475
496
|
levelParser = (0, __optique_core_modifiers.withDefault)((0, __optique_core_primitives.option)(short, long, logLevel()), defaultLevel);
|
|
476
497
|
break;
|
|
477
498
|
}
|
|
@@ -494,6 +515,7 @@ function loggingOptions(config) {
|
|
|
494
515
|
levelParser = debug(debugOptions);
|
|
495
516
|
break;
|
|
496
517
|
}
|
|
518
|
+
default: throw new TypeError(`Unsupported level configuration: ${String(config.level)}. Expected "option", "verbosity", or "debug".`);
|
|
497
519
|
}
|
|
498
520
|
const defaultOutput = { type: "console" };
|
|
499
521
|
const outputParser = (0, __optique_core_modifiers.withDefault)(logOutput({ long: outputLong }), defaultOutput);
|
package/dist/index.d.cts
CHANGED
|
@@ -8,6 +8,15 @@ import { Parser } from "@optique/core/parser";
|
|
|
8
8
|
* All valid log levels in order from lowest to highest severity.
|
|
9
9
|
*/
|
|
10
10
|
declare const LOG_LEVELS: readonly LogLevel$1[];
|
|
11
|
+
/**
|
|
12
|
+
* Validates that the given value is a valid {@link LogLevel}.
|
|
13
|
+
*
|
|
14
|
+
* @param value The value to validate.
|
|
15
|
+
* @param paramName The parameter name for the error message.
|
|
16
|
+
* @throws {TypeError} If the value is not a valid log level.
|
|
17
|
+
* @since 1.0.0
|
|
18
|
+
*/
|
|
19
|
+
|
|
11
20
|
/**
|
|
12
21
|
* Options for creating a log level value parser.
|
|
13
22
|
* @since 0.8.0
|
|
@@ -105,6 +114,7 @@ interface VerbosityOptions {
|
|
|
105
114
|
*
|
|
106
115
|
* @param options Configuration options for the verbosity parser.
|
|
107
116
|
* @returns A {@link Parser} that produces a {@link LogLevel}.
|
|
117
|
+
* @throws {TypeError} If `baseLevel` is not a valid log level.
|
|
108
118
|
*
|
|
109
119
|
* @example Basic usage
|
|
110
120
|
* ```typescript
|
|
@@ -177,6 +187,8 @@ interface DebugOptions {
|
|
|
177
187
|
*
|
|
178
188
|
* @param options Configuration options for the debug flag parser.
|
|
179
189
|
* @returns A {@link Parser} that produces a {@link LogLevel}.
|
|
190
|
+
* @throws {TypeError} If `debugLevel` or `normalLevel` is not a valid log
|
|
191
|
+
* level.
|
|
180
192
|
*
|
|
181
193
|
* @example Basic usage
|
|
182
194
|
* ```typescript
|
|
@@ -571,6 +583,9 @@ type LoggingOptionsConfig = LoggingOptionsWithLevel | LoggingOptionsWithVerbosit
|
|
|
571
583
|
* // --debug
|
|
572
584
|
* ```
|
|
573
585
|
*
|
|
586
|
+
* @throws {TypeError} If the `level` discriminant is not one of `"option"`,
|
|
587
|
+
* `"verbosity"`, or `"debug"`, or if a log level option (`default`,
|
|
588
|
+
* `debugLevel`, `normalLevel`, or `baseLevel`) is not a valid log level.
|
|
574
589
|
* @since 0.8.0
|
|
575
590
|
*/
|
|
576
591
|
declare function loggingOptions(config: LoggingOptionsConfig): Parser<"sync", LoggingOptionsResult, unknown>;
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,15 @@ import { Parser } from "@optique/core/parser";
|
|
|
8
8
|
* All valid log levels in order from lowest to highest severity.
|
|
9
9
|
*/
|
|
10
10
|
declare const LOG_LEVELS: readonly LogLevel$1[];
|
|
11
|
+
/**
|
|
12
|
+
* Validates that the given value is a valid {@link LogLevel}.
|
|
13
|
+
*
|
|
14
|
+
* @param value The value to validate.
|
|
15
|
+
* @param paramName The parameter name for the error message.
|
|
16
|
+
* @throws {TypeError} If the value is not a valid log level.
|
|
17
|
+
* @since 1.0.0
|
|
18
|
+
*/
|
|
19
|
+
|
|
11
20
|
/**
|
|
12
21
|
* Options for creating a log level value parser.
|
|
13
22
|
* @since 0.8.0
|
|
@@ -105,6 +114,7 @@ interface VerbosityOptions {
|
|
|
105
114
|
*
|
|
106
115
|
* @param options Configuration options for the verbosity parser.
|
|
107
116
|
* @returns A {@link Parser} that produces a {@link LogLevel}.
|
|
117
|
+
* @throws {TypeError} If `baseLevel` is not a valid log level.
|
|
108
118
|
*
|
|
109
119
|
* @example Basic usage
|
|
110
120
|
* ```typescript
|
|
@@ -177,6 +187,8 @@ interface DebugOptions {
|
|
|
177
187
|
*
|
|
178
188
|
* @param options Configuration options for the debug flag parser.
|
|
179
189
|
* @returns A {@link Parser} that produces a {@link LogLevel}.
|
|
190
|
+
* @throws {TypeError} If `debugLevel` or `normalLevel` is not a valid log
|
|
191
|
+
* level.
|
|
180
192
|
*
|
|
181
193
|
* @example Basic usage
|
|
182
194
|
* ```typescript
|
|
@@ -571,6 +583,9 @@ type LoggingOptionsConfig = LoggingOptionsWithLevel | LoggingOptionsWithVerbosit
|
|
|
571
583
|
* // --debug
|
|
572
584
|
* ```
|
|
573
585
|
*
|
|
586
|
+
* @throws {TypeError} If the `level` discriminant is not one of `"option"`,
|
|
587
|
+
* `"verbosity"`, or `"debug"`, or if a log level option (`default`,
|
|
588
|
+
* `debugLevel`, `normalLevel`, or `baseLevel`) is not a valid log level.
|
|
574
589
|
* @since 0.8.0
|
|
575
590
|
*/
|
|
576
591
|
declare function loggingOptions(config: LoggingOptionsConfig): Parser<"sync", LoggingOptionsResult, unknown>;
|
package/dist/index.js
CHANGED
|
@@ -19,6 +19,17 @@ const LOG_LEVELS = [
|
|
|
19
19
|
"fatal"
|
|
20
20
|
];
|
|
21
21
|
/**
|
|
22
|
+
* Validates that the given value is a valid {@link LogLevel}.
|
|
23
|
+
*
|
|
24
|
+
* @param value The value to validate.
|
|
25
|
+
* @param paramName The parameter name for the error message.
|
|
26
|
+
* @throws {TypeError} If the value is not a valid log level.
|
|
27
|
+
* @since 1.0.0
|
|
28
|
+
*/
|
|
29
|
+
function validateLogLevel(value, paramName) {
|
|
30
|
+
if (!LOG_LEVELS.includes(value)) throw new TypeError(`Invalid log level for ${paramName}: ${String(value)}. Expected ${LOG_LEVELS.map((l) => `"${l}"`).join(", ")}.`);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
22
33
|
* Creates a {@link ValueParser} for LogTape log levels.
|
|
23
34
|
*
|
|
24
35
|
* This parser validates that the input is one of the valid LogTape severity
|
|
@@ -91,6 +102,7 @@ const WARNING_INDEX = 2;
|
|
|
91
102
|
*
|
|
92
103
|
* @param options Configuration options for the verbosity parser.
|
|
93
104
|
* @returns A {@link Parser} that produces a {@link LogLevel}.
|
|
105
|
+
* @throws {TypeError} If `baseLevel` is not a valid log level.
|
|
94
106
|
*
|
|
95
107
|
* @example Basic usage
|
|
96
108
|
* ```typescript
|
|
@@ -125,6 +137,7 @@ function verbosity(options = {}) {
|
|
|
125
137
|
const short = options.short ?? "-v";
|
|
126
138
|
const long = options.long ?? "--verbose";
|
|
127
139
|
const baseLevel = options.baseLevel ?? "warning";
|
|
140
|
+
validateLogLevel(baseLevel, "baseLevel");
|
|
128
141
|
const baseIndex = VERBOSITY_LEVELS.indexOf(baseLevel);
|
|
129
142
|
const effectiveBaseIndex = baseIndex >= 0 ? baseIndex : WARNING_INDEX;
|
|
130
143
|
const flagParser = flag(short, long, { description: options.description ?? message`Be more verbose. Can be repeated.` });
|
|
@@ -147,6 +160,8 @@ function verbosity(options = {}) {
|
|
|
147
160
|
*
|
|
148
161
|
* @param options Configuration options for the debug flag parser.
|
|
149
162
|
* @returns A {@link Parser} that produces a {@link LogLevel}.
|
|
163
|
+
* @throws {TypeError} If `debugLevel` or `normalLevel` is not a valid log
|
|
164
|
+
* level.
|
|
150
165
|
*
|
|
151
166
|
* @example Basic usage
|
|
152
167
|
* ```typescript
|
|
@@ -180,6 +195,8 @@ function debug(options = {}) {
|
|
|
180
195
|
const long = options.long ?? "--debug";
|
|
181
196
|
const debugLevel = options.debugLevel ?? "debug";
|
|
182
197
|
const normalLevel = options.normalLevel ?? "info";
|
|
198
|
+
validateLogLevel(debugLevel, "debugLevel");
|
|
199
|
+
validateLogLevel(normalLevel, "normalLevel");
|
|
183
200
|
const flagParser = flag(short, long, { description: options.description ?? message`Enable debug logging.` });
|
|
184
201
|
return map(optional(flagParser), (value) => {
|
|
185
202
|
return value === true ? debugLevel : normalLevel;
|
|
@@ -437,6 +454,9 @@ Original error: ${e}`);
|
|
|
437
454
|
* // --debug
|
|
438
455
|
* ```
|
|
439
456
|
*
|
|
457
|
+
* @throws {TypeError} If the `level` discriminant is not one of `"option"`,
|
|
458
|
+
* `"verbosity"`, or `"debug"`, or if a log level option (`default`,
|
|
459
|
+
* `debugLevel`, `normalLevel`, or `baseLevel`) is not a valid log level.
|
|
440
460
|
* @since 0.8.0
|
|
441
461
|
*/
|
|
442
462
|
function loggingOptions(config) {
|
|
@@ -449,6 +469,7 @@ function loggingOptions(config) {
|
|
|
449
469
|
const long = config.long ?? "--log-level";
|
|
450
470
|
const short = config.short ?? "-l";
|
|
451
471
|
const defaultLevel = config.default ?? "info";
|
|
472
|
+
validateLogLevel(defaultLevel, "default");
|
|
452
473
|
levelParser = withDefault(option(short, long, logLevel()), defaultLevel);
|
|
453
474
|
break;
|
|
454
475
|
}
|
|
@@ -471,6 +492,7 @@ function loggingOptions(config) {
|
|
|
471
492
|
levelParser = debug(debugOptions);
|
|
472
493
|
break;
|
|
473
494
|
}
|
|
495
|
+
default: throw new TypeError(`Unsupported level configuration: ${String(config.level)}. Expected "option", "verbosity", or "debug".`);
|
|
474
496
|
}
|
|
475
497
|
const defaultOutput = { type: "console" };
|
|
476
498
|
const outputParser = withDefault(logOutput({ long: outputLong }), defaultOutput);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@optique/logtape",
|
|
3
|
-
"version": "1.0.0-dev.
|
|
3
|
+
"version": "1.0.0-dev.1424+71e81eec",
|
|
4
4
|
"description": "LogTape logging integration for Optique CLI parser",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"CLI",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
}
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@optique/core": "1.0.0-dev.
|
|
66
|
+
"@optique/core": "1.0.0-dev.1424+71e81eec"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@logtape/file": "^2.0.4",
|