@optique/logtape 1.0.0-dev.1420 → 1.0.0-dev.1431

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 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;
@@ -461,7 +478,8 @@ Original error: ${e}`);
461
478
  * ```
462
479
  *
463
480
  * @throws {TypeError} If the `level` discriminant is not one of `"option"`,
464
- * `"verbosity"`, or `"debug"`.
481
+ * `"verbosity"`, or `"debug"`, or if a log level option (`default`,
482
+ * `debugLevel`, `normalLevel`, or `baseLevel`) is not a valid log level.
465
483
  * @since 0.8.0
466
484
  */
467
485
  function loggingOptions(config) {
@@ -474,6 +492,7 @@ function loggingOptions(config) {
474
492
  const long = config.long ?? "--log-level";
475
493
  const short = config.short ?? "-l";
476
494
  const defaultLevel = config.default ?? "info";
495
+ validateLogLevel(defaultLevel, "default");
477
496
  levelParser = (0, __optique_core_modifiers.withDefault)((0, __optique_core_primitives.option)(short, long, logLevel()), defaultLevel);
478
497
  break;
479
498
  }
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
@@ -572,7 +584,8 @@ type LoggingOptionsConfig = LoggingOptionsWithLevel | LoggingOptionsWithVerbosit
572
584
  * ```
573
585
  *
574
586
  * @throws {TypeError} If the `level` discriminant is not one of `"option"`,
575
- * `"verbosity"`, or `"debug"`.
587
+ * `"verbosity"`, or `"debug"`, or if a log level option (`default`,
588
+ * `debugLevel`, `normalLevel`, or `baseLevel`) is not a valid log level.
576
589
  * @since 0.8.0
577
590
  */
578
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
@@ -572,7 +584,8 @@ type LoggingOptionsConfig = LoggingOptionsWithLevel | LoggingOptionsWithVerbosit
572
584
  * ```
573
585
  *
574
586
  * @throws {TypeError} If the `level` discriminant is not one of `"option"`,
575
- * `"verbosity"`, or `"debug"`.
587
+ * `"verbosity"`, or `"debug"`, or if a log level option (`default`,
588
+ * `debugLevel`, `normalLevel`, or `baseLevel`) is not a valid log level.
576
589
  * @since 0.8.0
577
590
  */
578
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;
@@ -438,7 +455,8 @@ Original error: ${e}`);
438
455
  * ```
439
456
  *
440
457
  * @throws {TypeError} If the `level` discriminant is not one of `"option"`,
441
- * `"verbosity"`, or `"debug"`.
458
+ * `"verbosity"`, or `"debug"`, or if a log level option (`default`,
459
+ * `debugLevel`, `normalLevel`, or `baseLevel`) is not a valid log level.
442
460
  * @since 0.8.0
443
461
  */
444
462
  function loggingOptions(config) {
@@ -451,6 +469,7 @@ function loggingOptions(config) {
451
469
  const long = config.long ?? "--log-level";
452
470
  const short = config.short ?? "-l";
453
471
  const defaultLevel = config.default ?? "info";
472
+ validateLogLevel(defaultLevel, "default");
454
473
  levelParser = withDefault(option(short, long, logLevel()), defaultLevel);
455
474
  break;
456
475
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/logtape",
3
- "version": "1.0.0-dev.1420+7622cdfa",
3
+ "version": "1.0.0-dev.1431+53a2612f",
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.1420+7622cdfa"
66
+ "@optique/core": "1.0.0-dev.1431+53a2612f"
67
67
  },
68
68
  "devDependencies": {
69
69
  "@logtape/file": "^2.0.4",