@optique/logtape 1.0.0-dev.1388 → 1.0.0-dev.1390

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
@@ -301,6 +301,10 @@ function logOutput(options = {}) {
301
301
  *
302
302
  * @param options Configuration options for the console sink.
303
303
  * @returns A {@link Sink} function.
304
+ * @throws {TypeError} If `options.stream` is not `"stdout"` or `"stderr"`
305
+ * when `streamResolver` is not provided.
306
+ * @throws {TypeError} If `streamResolver` returns a value other than
307
+ * `"stdout"` or `"stderr"`.
304
308
  *
305
309
  * @example Static stream selection
306
310
  * ```typescript
@@ -322,10 +326,23 @@ function logOutput(options = {}) {
322
326
  * @since 0.8.0
323
327
  */
324
328
  function createConsoleSink(options = {}) {
325
- const defaultStream = options.stream ?? "stderr";
326
329
  const streamResolver = options.streamResolver;
330
+ const defaultStream = options.stream ?? "stderr";
331
+ const invalidStreamError = (value) => {
332
+ let repr;
333
+ if (typeof value === "string") repr = JSON.stringify(value);
334
+ else if (value === null || typeof value !== "object") repr = String(value);
335
+ else try {
336
+ repr = JSON.stringify(value) ?? String(value);
337
+ } catch {
338
+ repr = String(value);
339
+ }
340
+ return /* @__PURE__ */ new TypeError(`Invalid stream: expected "stdout" or "stderr", got ${repr}.`);
341
+ };
342
+ if (!streamResolver && defaultStream !== "stdout" && defaultStream !== "stderr") throw invalidStreamError(defaultStream);
327
343
  return (record) => {
328
344
  const stream = streamResolver ? streamResolver(record.level) : defaultStream;
345
+ if (stream !== "stdout" && stream !== "stderr") throw invalidStreamError(stream);
329
346
  const messageParts = [];
330
347
  for (let i = 0; i < record.message.length; i++) {
331
348
  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.
@@ -313,6 +314,10 @@ declare function logOutput(options?: LogOutputOptions): Parser<"sync", LogOutput
313
314
  *
314
315
  * @param options Configuration options for the console sink.
315
316
  * @returns A {@link Sink} function.
317
+ * @throws {TypeError} If `options.stream` is not `"stdout"` or `"stderr"`
318
+ * when `streamResolver` is not provided.
319
+ * @throws {TypeError} If `streamResolver` returns a value other than
320
+ * `"stdout"` or `"stderr"`.
316
321
  *
317
322
  * @example Static stream selection
318
323
  * ```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.
@@ -313,6 +314,10 @@ declare function logOutput(options?: LogOutputOptions): Parser<"sync", LogOutput
313
314
  *
314
315
  * @param options Configuration options for the console sink.
315
316
  * @returns A {@link Sink} function.
317
+ * @throws {TypeError} If `options.stream` is not `"stdout"` or `"stderr"`
318
+ * when `streamResolver` is not provided.
319
+ * @throws {TypeError} If `streamResolver` returns a value other than
320
+ * `"stdout"` or `"stderr"`.
316
321
  *
317
322
  * @example Static stream selection
318
323
  * ```typescript
package/dist/index.js CHANGED
@@ -278,6 +278,10 @@ function logOutput(options = {}) {
278
278
  *
279
279
  * @param options Configuration options for the console sink.
280
280
  * @returns A {@link Sink} function.
281
+ * @throws {TypeError} If `options.stream` is not `"stdout"` or `"stderr"`
282
+ * when `streamResolver` is not provided.
283
+ * @throws {TypeError} If `streamResolver` returns a value other than
284
+ * `"stdout"` or `"stderr"`.
281
285
  *
282
286
  * @example Static stream selection
283
287
  * ```typescript
@@ -299,10 +303,23 @@ function logOutput(options = {}) {
299
303
  * @since 0.8.0
300
304
  */
301
305
  function createConsoleSink(options = {}) {
302
- const defaultStream = options.stream ?? "stderr";
303
306
  const streamResolver = options.streamResolver;
307
+ const defaultStream = options.stream ?? "stderr";
308
+ const invalidStreamError = (value) => {
309
+ let repr;
310
+ if (typeof value === "string") repr = JSON.stringify(value);
311
+ else if (value === null || typeof value !== "object") repr = String(value);
312
+ else try {
313
+ repr = JSON.stringify(value) ?? String(value);
314
+ } catch {
315
+ repr = String(value);
316
+ }
317
+ return /* @__PURE__ */ new TypeError(`Invalid stream: expected "stdout" or "stderr", got ${repr}.`);
318
+ };
319
+ if (!streamResolver && defaultStream !== "stdout" && defaultStream !== "stderr") throw invalidStreamError(defaultStream);
304
320
  return (record) => {
305
321
  const stream = streamResolver ? streamResolver(record.level) : defaultStream;
322
+ if (stream !== "stdout" && stream !== "stderr") throw invalidStreamError(stream);
306
323
  const messageParts = [];
307
324
  for (let i = 0; i < record.message.length; i++) {
308
325
  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.1388+3660675f",
3
+ "version": "1.0.0-dev.1390+84b0f473",
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.1388+3660675f"
66
+ "@optique/core": "1.0.0-dev.1390+84b0f473"
67
67
  },
68
68
  "devDependencies": {
69
69
  "@logtape/file": "^2.0.4",