From: Ardis Lu Date: Sat, 27 Sep 2025 06:06:44 +0000 (-0700) Subject: Improve JSDoc type import consistency X-Git-Tag: v0.1.7~8 X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=b49e2d5fdbb19872104e1cc0cdd181a58db300bf;p=csvio Improve JSDoc type import consistency --- diff --git a/src/core.js b/src/core.js index 5d35eee..9eec421 100644 --- a/src/core.js +++ b/src/core.js @@ -4,6 +4,7 @@ import { fileURLToPath } from 'node:url'; import { ReadableStream, WritableStream, TransformStream, TextDecoderStream } from 'node:stream/web'; /** @import { PathLike } from 'node:fs'; */ /** @import { FileHandle } from 'node:fs/promises'; */ +/** @import { TransformerFlushCallback, TransformerTransformCallback } from 'node:stream/web'; */ /** * Parse and normalize a `PathLike` object into a string. @@ -154,7 +155,7 @@ export class CSVReader { return createProxy(this, stream); } - /** @type {import('node:stream/web').TransformerTransformCallback>} */ + /** @type {TransformerTransformCallback>} */ #transform(chunk, controller) { for (const char of chunk) { /* Escape mode logic */ @@ -202,7 +203,7 @@ export class CSVReader { } } - /** @type {import('node:stream/web').TransformerFlushCallback>} */ + /** @type {TransformerFlushCallback>} */ #flush(controller) { if (this.#field !== '' || this.#row.length !== 0) { // CSV terminated without a trailing CRLF, leaving a row in the queue this.#row.push(this.#field); // Last field is always un-pushed if CSV terminated with nothing @@ -392,7 +393,7 @@ export class CSVTransformer extends TransformStream { } } - /** @type {import('node:stream/web').TransformerTransformCallback,Array>} */ + /** @type {TransformerTransformCallback,Array>} */ async #transform(chunk, controller) { // If row is an array of objects, then the transformation has "normalized" the data and there is no header row. // Instead, the header data has been incorporated into the object keys. The transformation is responsible @@ -424,7 +425,7 @@ export class CSVTransformer extends TransformStream { } } - /** @type {import('node:stream/web').TransformerFlushCallback>} */ + /** @type {TransformerFlushCallback>} */ async #flush(controller) { if (this.#batch.length > 0) { this.#concurrent.push(this.#wrappedFn(this.#batch)); diff --git a/src/errorStrategies.js b/src/errorStrategies.js index 1a1fe2b..354a47a 100644 --- a/src/errorStrategies.js +++ b/src/errorStrategies.js @@ -1,6 +1,5 @@ import { setTimeout } from 'node:timers/promises'; - -/** @import {TransformationErrorFunction} from './core.js'; */ +/** @import { TransformationErrorFunction } from './core.js'; */ /** * A wrapper around `node:timers/promises`'s async `setTimeout`. This wrapper is required to mock for testing purposes. diff --git a/src/normalization.js b/src/normalization.js index dbba4b3..3d51af7 100644 --- a/src/normalization.js +++ b/src/normalization.js @@ -1,4 +1,5 @@ import { TransformStream } from 'node:stream/web'; +/** @import { TransformerTransformCallback } from 'node:stream/web'; */ /** * Get the decimal separator character to parse numbers formatted in different locales. @@ -143,7 +144,7 @@ export class CSVNormalizer extends TransformStream { } } - /** @type {import('node:stream/web').TransformerTransformCallback,Array>>} */ + /** @type {TransformerTransformCallback,Array>>} */ #transform(chunk, controller) { // Assume first non-empty row is headers and use it to prepare the columns object // Note: the headers row is NOT forwarded downstream @@ -318,7 +319,7 @@ export class CSVDenormalizer extends TransformStream { constructor() { let firstRow = true; super({ - /** @type {import('node:stream/web').TransformerTransformCallback,Array>} */ + /** @type {TransformerTransformCallback,Array>} */ transform(chunk, controller) { if (firstRow) { firstRow = false; diff --git a/test/utils.js b/test/utils.js index 02ec5b6..fe1b940 100644 --- a/test/utils.js +++ b/test/utils.js @@ -5,7 +5,6 @@ import { normalize } from 'node:path'; import { ReadableStream } from 'node:stream/web'; /** @import { TestContext } from 'node:test'; */ /** @import { PathLike } from 'node:fs'; */ -/** @import { FileHandle } from 'node:fs/promises'; */ import { utils } from '../src/errorStrategies.js';