@optique/logtape 1.0.0-dev.1388 → 1.0.0-dev.1400
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 +24 -2
- package/dist/index.d.cts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +24 -2
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -26,6 +26,7 @@ const __optique_core_primitives = __toESM(require("@optique/core/primitives"));
|
|
|
26
26
|
const __optique_core_modifiers = __toESM(require("@optique/core/modifiers"));
|
|
27
27
|
const __optique_core_message = __toESM(require("@optique/core/message"));
|
|
28
28
|
const node_path = __toESM(require("node:path"));
|
|
29
|
+
const __optique_core_nonempty = __toESM(require("@optique/core/nonempty"));
|
|
29
30
|
const __optique_core_constructs = __toESM(require("@optique/core/constructs"));
|
|
30
31
|
|
|
31
32
|
//#region src/loglevel.ts
|
|
@@ -219,11 +220,14 @@ function debug(options = {}) {
|
|
|
219
220
|
*
|
|
220
221
|
* @param options Configuration options for the parser.
|
|
221
222
|
* @returns A {@link ValueParser} that produces a {@link LogOutput}.
|
|
223
|
+
* @throws {TypeError} If `options.metavar` is an empty string.
|
|
222
224
|
*/
|
|
223
225
|
function logOutputValueParser(options = {}) {
|
|
226
|
+
const metavar = options.metavar ?? "FILE";
|
|
227
|
+
(0, __optique_core_nonempty.ensureNonEmptyString)(metavar);
|
|
224
228
|
return {
|
|
225
229
|
$mode: "sync",
|
|
226
|
-
metavar
|
|
230
|
+
metavar,
|
|
227
231
|
parse(input) {
|
|
228
232
|
if (input === "-") return {
|
|
229
233
|
success: true,
|
|
@@ -266,6 +270,7 @@ function logOutputValueParser(options = {}) {
|
|
|
266
270
|
*
|
|
267
271
|
* @param options Configuration options for the log output parser.
|
|
268
272
|
* @returns A {@link Parser} that produces a {@link LogOutput} or `undefined`.
|
|
273
|
+
* @throws {TypeError} If `options.metavar` is an empty string.
|
|
269
274
|
*
|
|
270
275
|
* @example Basic usage
|
|
271
276
|
* ```typescript
|
|
@@ -301,6 +306,10 @@ function logOutput(options = {}) {
|
|
|
301
306
|
*
|
|
302
307
|
* @param options Configuration options for the console sink.
|
|
303
308
|
* @returns A {@link Sink} function.
|
|
309
|
+
* @throws {TypeError} If `options.stream` is not `"stdout"` or `"stderr"`
|
|
310
|
+
* when `streamResolver` is not provided.
|
|
311
|
+
* @throws {TypeError} If `streamResolver` returns a value other than
|
|
312
|
+
* `"stdout"` or `"stderr"`.
|
|
304
313
|
*
|
|
305
314
|
* @example Static stream selection
|
|
306
315
|
* ```typescript
|
|
@@ -322,10 +331,23 @@ function logOutput(options = {}) {
|
|
|
322
331
|
* @since 0.8.0
|
|
323
332
|
*/
|
|
324
333
|
function createConsoleSink(options = {}) {
|
|
325
|
-
const defaultStream = options.stream ?? "stderr";
|
|
326
334
|
const streamResolver = options.streamResolver;
|
|
335
|
+
const defaultStream = options.stream ?? "stderr";
|
|
336
|
+
const invalidStreamError = (value) => {
|
|
337
|
+
let repr;
|
|
338
|
+
if (typeof value === "string") repr = JSON.stringify(value);
|
|
339
|
+
else if (value === null || typeof value !== "object") repr = String(value);
|
|
340
|
+
else try {
|
|
341
|
+
repr = JSON.stringify(value) ?? String(value);
|
|
342
|
+
} catch {
|
|
343
|
+
repr = String(value);
|
|
344
|
+
}
|
|
345
|
+
return /* @__PURE__ */ new TypeError(`Invalid stream: expected "stdout" or "stderr", got ${repr}.`);
|
|
346
|
+
};
|
|
347
|
+
if (!streamResolver && defaultStream !== "stdout" && defaultStream !== "stderr") throw invalidStreamError(defaultStream);
|
|
327
348
|
return (record) => {
|
|
328
349
|
const stream = streamResolver ? streamResolver(record.level) : defaultStream;
|
|
350
|
+
if (stream !== "stdout" && stream !== "stderr") throw invalidStreamError(stream);
|
|
329
351
|
const messageParts = [];
|
|
330
352
|
for (let i = 0; i < record.message.length; i++) {
|
|
331
353
|
const part = record.message[i];
|
package/dist/index.d.cts
CHANGED
|
@@ -228,9 +228,10 @@ type LogOutput = {
|
|
|
228
228
|
interface ConsoleSinkOptions {
|
|
229
229
|
/**
|
|
230
230
|
* The stream to write to. Either `"stdout"` or `"stderr"`.
|
|
231
|
+
* If `null` or `undefined`, defaults to `"stderr"`.
|
|
231
232
|
* @default `"stderr"`
|
|
232
233
|
*/
|
|
233
|
-
readonly stream?: "stdout" | "stderr";
|
|
234
|
+
readonly stream?: "stdout" | "stderr" | null;
|
|
234
235
|
/**
|
|
235
236
|
* A function that determines which stream to use based on the log level.
|
|
236
237
|
* If provided, this takes precedence over the `stream` option.
|
|
@@ -287,6 +288,7 @@ interface LogOutputOptions {
|
|
|
287
288
|
*
|
|
288
289
|
* @param options Configuration options for the log output parser.
|
|
289
290
|
* @returns A {@link Parser} that produces a {@link LogOutput} or `undefined`.
|
|
291
|
+
* @throws {TypeError} If `options.metavar` is an empty string.
|
|
290
292
|
*
|
|
291
293
|
* @example Basic usage
|
|
292
294
|
* ```typescript
|
|
@@ -313,6 +315,10 @@ declare function logOutput(options?: LogOutputOptions): Parser<"sync", LogOutput
|
|
|
313
315
|
*
|
|
314
316
|
* @param options Configuration options for the console sink.
|
|
315
317
|
* @returns A {@link Sink} function.
|
|
318
|
+
* @throws {TypeError} If `options.stream` is not `"stdout"` or `"stderr"`
|
|
319
|
+
* when `streamResolver` is not provided.
|
|
320
|
+
* @throws {TypeError} If `streamResolver` returns a value other than
|
|
321
|
+
* `"stdout"` or `"stderr"`.
|
|
316
322
|
*
|
|
317
323
|
* @example Static stream selection
|
|
318
324
|
* ```typescript
|
package/dist/index.d.ts
CHANGED
|
@@ -228,9 +228,10 @@ type LogOutput = {
|
|
|
228
228
|
interface ConsoleSinkOptions {
|
|
229
229
|
/**
|
|
230
230
|
* The stream to write to. Either `"stdout"` or `"stderr"`.
|
|
231
|
+
* If `null` or `undefined`, defaults to `"stderr"`.
|
|
231
232
|
* @default `"stderr"`
|
|
232
233
|
*/
|
|
233
|
-
readonly stream?: "stdout" | "stderr";
|
|
234
|
+
readonly stream?: "stdout" | "stderr" | null;
|
|
234
235
|
/**
|
|
235
236
|
* A function that determines which stream to use based on the log level.
|
|
236
237
|
* If provided, this takes precedence over the `stream` option.
|
|
@@ -287,6 +288,7 @@ interface LogOutputOptions {
|
|
|
287
288
|
*
|
|
288
289
|
* @param options Configuration options for the log output parser.
|
|
289
290
|
* @returns A {@link Parser} that produces a {@link LogOutput} or `undefined`.
|
|
291
|
+
* @throws {TypeError} If `options.metavar` is an empty string.
|
|
290
292
|
*
|
|
291
293
|
* @example Basic usage
|
|
292
294
|
* ```typescript
|
|
@@ -313,6 +315,10 @@ declare function logOutput(options?: LogOutputOptions): Parser<"sync", LogOutput
|
|
|
313
315
|
*
|
|
314
316
|
* @param options Configuration options for the console sink.
|
|
315
317
|
* @returns A {@link Sink} function.
|
|
318
|
+
* @throws {TypeError} If `options.stream` is not `"stdout"` or `"stderr"`
|
|
319
|
+
* when `streamResolver` is not provided.
|
|
320
|
+
* @throws {TypeError} If `streamResolver` returns a value other than
|
|
321
|
+
* `"stdout"` or `"stderr"`.
|
|
316
322
|
*
|
|
317
323
|
* @example Static stream selection
|
|
318
324
|
* ```typescript
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import { flag, option } from "@optique/core/primitives";
|
|
|
3
3
|
import { map, multiple, optional, withDefault } from "@optique/core/modifiers";
|
|
4
4
|
import { message } from "@optique/core/message";
|
|
5
5
|
import { basename } from "node:path";
|
|
6
|
+
import { ensureNonEmptyString } from "@optique/core/nonempty";
|
|
6
7
|
import { group, object } from "@optique/core/constructs";
|
|
7
8
|
|
|
8
9
|
//#region src/loglevel.ts
|
|
@@ -196,11 +197,14 @@ function debug(options = {}) {
|
|
|
196
197
|
*
|
|
197
198
|
* @param options Configuration options for the parser.
|
|
198
199
|
* @returns A {@link ValueParser} that produces a {@link LogOutput}.
|
|
200
|
+
* @throws {TypeError} If `options.metavar` is an empty string.
|
|
199
201
|
*/
|
|
200
202
|
function logOutputValueParser(options = {}) {
|
|
203
|
+
const metavar = options.metavar ?? "FILE";
|
|
204
|
+
ensureNonEmptyString(metavar);
|
|
201
205
|
return {
|
|
202
206
|
$mode: "sync",
|
|
203
|
-
metavar
|
|
207
|
+
metavar,
|
|
204
208
|
parse(input) {
|
|
205
209
|
if (input === "-") return {
|
|
206
210
|
success: true,
|
|
@@ -243,6 +247,7 @@ function logOutputValueParser(options = {}) {
|
|
|
243
247
|
*
|
|
244
248
|
* @param options Configuration options for the log output parser.
|
|
245
249
|
* @returns A {@link Parser} that produces a {@link LogOutput} or `undefined`.
|
|
250
|
+
* @throws {TypeError} If `options.metavar` is an empty string.
|
|
246
251
|
*
|
|
247
252
|
* @example Basic usage
|
|
248
253
|
* ```typescript
|
|
@@ -278,6 +283,10 @@ function logOutput(options = {}) {
|
|
|
278
283
|
*
|
|
279
284
|
* @param options Configuration options for the console sink.
|
|
280
285
|
* @returns A {@link Sink} function.
|
|
286
|
+
* @throws {TypeError} If `options.stream` is not `"stdout"` or `"stderr"`
|
|
287
|
+
* when `streamResolver` is not provided.
|
|
288
|
+
* @throws {TypeError} If `streamResolver` returns a value other than
|
|
289
|
+
* `"stdout"` or `"stderr"`.
|
|
281
290
|
*
|
|
282
291
|
* @example Static stream selection
|
|
283
292
|
* ```typescript
|
|
@@ -299,10 +308,23 @@ function logOutput(options = {}) {
|
|
|
299
308
|
* @since 0.8.0
|
|
300
309
|
*/
|
|
301
310
|
function createConsoleSink(options = {}) {
|
|
302
|
-
const defaultStream = options.stream ?? "stderr";
|
|
303
311
|
const streamResolver = options.streamResolver;
|
|
312
|
+
const defaultStream = options.stream ?? "stderr";
|
|
313
|
+
const invalidStreamError = (value) => {
|
|
314
|
+
let repr;
|
|
315
|
+
if (typeof value === "string") repr = JSON.stringify(value);
|
|
316
|
+
else if (value === null || typeof value !== "object") repr = String(value);
|
|
317
|
+
else try {
|
|
318
|
+
repr = JSON.stringify(value) ?? String(value);
|
|
319
|
+
} catch {
|
|
320
|
+
repr = String(value);
|
|
321
|
+
}
|
|
322
|
+
return /* @__PURE__ */ new TypeError(`Invalid stream: expected "stdout" or "stderr", got ${repr}.`);
|
|
323
|
+
};
|
|
324
|
+
if (!streamResolver && defaultStream !== "stdout" && defaultStream !== "stderr") throw invalidStreamError(defaultStream);
|
|
304
325
|
return (record) => {
|
|
305
326
|
const stream = streamResolver ? streamResolver(record.level) : defaultStream;
|
|
327
|
+
if (stream !== "stdout" && stream !== "stderr") throw invalidStreamError(stream);
|
|
306
328
|
const messageParts = [];
|
|
307
329
|
for (let i = 0; i < record.message.length; i++) {
|
|
308
330
|
const part = record.message[i];
|
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.1400+437307fc",
|
|
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.1400+437307fc"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@logtape/file": "^2.0.4",
|