From f66b7ba9153afc3dedcfdd4af7dabe4d18a40aef Mon Sep 17 00:00:00 2001 From: mktbsh <59120037+mktbsh@users.noreply.github.com> Date: Fri, 1 May 2026 09:50:37 +0900 Subject: [PATCH 01/17] refactor: enhance readable stream utilities with additional functions --- src/shared/readable.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/shared/readable.ts b/src/shared/readable.ts index 538b708..0d86425 100644 --- a/src/shared/readable.ts +++ b/src/shared/readable.ts @@ -1,4 +1,6 @@ +import type { BinaryReadableStream } from "../stream-types"; import { isInstance } from "./is"; +import { concatU8Arrays } from "./uint8array"; export function toReadableStream( input: ReadableStream | Iterable | AsyncIterable, @@ -32,6 +34,40 @@ export function toReadableStream( }); } +export function readableFromChunks(chunks: T | T[]): ReadableStream { + const queue = Array.isArray(chunks) ? chunks : [chunks]; + + return new ReadableStream({ + start(controller) { + for (const chunk of queue) { + controller.enqueue(chunk); + } + controller.close(); + }, + }); +} + +export async function readAllChunks( + stream: ReadableStream, +): Promise { + const reader = stream.getReader(); + const chunks: T[] = []; + + while (true) { + const { done, value } = await reader.read(); + if (done) { + return chunks; + } + chunks.push(value); + } +} + +export async function readAllBytes( + stream: BinaryReadableStream, +): Promise { + return concatU8Arrays(...(await readAllChunks(stream))); +} + async function* toAsyncIterator(iterator: Iterator): AsyncGenerator { while (true) { const result = iterator.next(); From 9152a23ad8792c3fe6bf1c517ece591d28a8914c Mon Sep 17 00:00:00 2001 From: mktbsh <59120037+mktbsh@users.noreply.github.com> Date: Fri, 1 May 2026 09:51:07 +0900 Subject: [PATCH 02/17] refactor: update VSCode settings to include organizeImports action --- .vscode/settings.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index e46280a..d0c86c4 100755 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,6 +3,7 @@ "editor.formatOnSave": true, "editor.codeActionsOnSave": { "source.fixAll.biome": "explicit", - "source.organizeImports.biome": "explicit" + "source.organizeImports.biome": "explicit", + "source.organizeImports": "never" } } From 9d016596e7402cda55228e35dda2c71896182eda Mon Sep 17 00:00:00 2001 From: mktbsh <59120037+mktbsh@users.noreply.github.com> Date: Fri, 1 May 2026 09:51:13 +0900 Subject: [PATCH 03/17] refactor: remove obsolete readable stream functions from readable.ts --- src/readable.ts | 36 ------------------------------------ 1 file changed, 36 deletions(-) delete mode 100644 src/readable.ts diff --git a/src/readable.ts b/src/readable.ts deleted file mode 100644 index 696e62a..0000000 --- a/src/readable.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { concatU8Arrays } from "./shared/uint8array"; -import type { BinaryReadableStream } from "./stream-types"; - -export function readableFromChunks(chunks: T | T[]): ReadableStream { - const queue = Array.isArray(chunks) ? chunks : [chunks]; - - return new ReadableStream({ - start(controller) { - for (const chunk of queue) { - controller.enqueue(chunk); - } - controller.close(); - }, - }); -} - -export async function readAllChunks( - stream: ReadableStream, -): Promise { - const reader = stream.getReader(); - const chunks: T[] = []; - - while (true) { - const { done, value } = await reader.read(); - if (done) { - return chunks; - } - chunks.push(value); - } -} - -export async function readAllBytes( - stream: BinaryReadableStream, -): Promise { - return concatU8Arrays(...(await readAllChunks(stream))); -} From f7b58308e18b650f7a17fd8245b2a46ba84642bc Mon Sep 17 00:00:00 2001 From: mktbsh <59120037+mktbsh@users.noreply.github.com> Date: Fri, 1 May 2026 09:51:48 +0900 Subject: [PATCH 04/17] refactor: create index.ts to consolidate exports from shared modules Co-authored-by: Copilot --- src/shared/index.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/shared/index.ts diff --git a/src/shared/index.ts b/src/shared/index.ts new file mode 100644 index 0000000..18caf28 --- /dev/null +++ b/src/shared/index.ts @@ -0,0 +1,13 @@ +export { toArrayBuffer } from "./array-buffer"; + +export { + binaryToString, + randomBytes, + stringToBinary, +} from "./binary"; + +export { + readAllBytes, + readAllChunks, + readableFromChunks, +} from "./readable"; From 671ac159cf23e6a92096177c0fb30a940d622fd5 Mon Sep 17 00:00:00 2001 From: mktbsh <59120037+mktbsh@users.noreply.github.com> Date: Fri, 1 May 2026 09:51:59 +0900 Subject: [PATCH 05/17] refactor: reorganize exports in index.ts for improved structure --- src/index.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 4605970..dcea9d3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,11 @@ -export { readAllBytes, readAllChunks, readableFromChunks } from "./readable"; export { binaryToString, randomBytes, stringToBinary, } from "./shared/binary"; + +export { + readAllBytes, + readAllChunks, + readableFromChunks, +} from "./shared/readable"; From 2679c117f5f9e35a1be3d676239b74aef59a4b25 Mon Sep 17 00:00:00 2001 From: mktbsh <59120037+mktbsh@users.noreply.github.com> Date: Fri, 1 May 2026 09:52:12 +0900 Subject: [PATCH 06/17] refactor: update import path for utility functions in base64 test file --- src/base64.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base64.test.ts b/src/base64.test.ts index 531c879..1ac142a 100644 --- a/src/base64.test.ts +++ b/src/base64.test.ts @@ -13,7 +13,7 @@ import { readAllChunks, readableFromChunks, stringToBinary, -} from "./index"; +} from "./shared"; describe("base64", () => { it("encodes byte chunks across 3-byte boundaries", async () => { From ec6278788690c0401250773447d40271b0b67d62 Mon Sep 17 00:00:00 2001 From: mktbsh <59120037+mktbsh@users.noreply.github.com> Date: Fri, 1 May 2026 09:53:36 +0900 Subject: [PATCH 07/17] refactor: update import paths in test files to use shared module --- src/cobs.test.ts | 2 +- src/png.test.ts | 2 +- tsdown.config.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cobs.test.ts b/src/cobs.test.ts index c642ccf..7ba9332 100644 --- a/src/cobs.test.ts +++ b/src/cobs.test.ts @@ -8,7 +8,7 @@ import { readCOBS, writeCOBS, } from "./cobs"; -import { readAllBytes, readAllChunks, readableFromChunks } from "./readable"; +import { readAllBytes, readAllChunks, readableFromChunks } from "./shared"; describe("cobs public API", () => { it("exports the supported cobs helpers", () => { diff --git a/src/png.test.ts b/src/png.test.ts index c979e66..c59aea0 100644 --- a/src/png.test.ts +++ b/src/png.test.ts @@ -24,7 +24,7 @@ import { extractPNGTextChunk, streamPNGTextChunk, } from "./png/public"; -import { readAllBytes, readableFromChunks } from "./readable"; +import { readAllBytes, readableFromChunks } from "./shared"; const MINIMAL_PNG = concatBytes( PNG_SIGNATURE, diff --git a/tsdown.config.ts b/tsdown.config.ts index cf0349a..e2bce88 100644 --- a/tsdown.config.ts +++ b/tsdown.config.ts @@ -8,7 +8,7 @@ export default defineConfig({ "src/jsonl.ts", "src/text.ts", "src/png.ts", - "src/cobs.ts", + "src/cobs.ts" ], outDir: "dist", target: "es2022", From 72284024a5f6c105fe6c6da0e9d8319186bf5748 Mon Sep 17 00:00:00 2001 From: mktbsh <59120037+mktbsh@users.noreply.github.com> Date: Fri, 1 May 2026 09:55:00 +0900 Subject: [PATCH 08/17] refactor: reorganize exports in index.ts for improved clarity and structure Co-authored-by: Copilot --- src/index.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index dcea9d3..545ca84 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,11 +1,17 @@ +export * from "./base64"; +export * from "./byte-queue"; +export * from "./cobs"; +export * from "./encryption"; +export * from "./jsonl"; +export * from "./png"; export { binaryToString, randomBytes, stringToBinary, } from "./shared/binary"; - export { readAllBytes, readAllChunks, readableFromChunks, } from "./shared/readable"; +export * from "./text"; From 77e3e0b527cc42e15a53738c80762496e4a5c99e Mon Sep 17 00:00:00 2001 From: mktbsh <59120037+mktbsh@users.noreply.github.com> Date: Fri, 1 May 2026 10:00:11 +0900 Subject: [PATCH 09/17] refactor: restructure text module by consolidating exports and updating paths --- package.json | 2 +- src/text.ts | 17 ----------------- src/{text.test.ts => text/index.test.ts} | 4 ++-- src/text/{public.ts => index.ts} | 0 tsdown.config.ts | 2 +- 5 files changed, 4 insertions(+), 21 deletions(-) delete mode 100644 src/text.ts rename src/{text.test.ts => text/index.test.ts} (99%) rename src/text/{public.ts => index.ts} (100%) diff --git a/package.json b/package.json index 8211f90..60dcf29 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "./encryption": "./dist/encryption.js", "./jsonl": "./dist/jsonl.js", "./png": "./dist/png.js", - "./text": "./dist/text.js", + "./text": "./dist/text/index.js", "./package.json": "./package.json" }, "types": "./dist/index.d.ts", diff --git a/src/text.ts b/src/text.ts deleted file mode 100644 index 99916f6..0000000 --- a/src/text.ts +++ /dev/null @@ -1,17 +0,0 @@ -export type { - LineJoinStreamOptions, - LineSplitStreamOptions, - TextDecodeStreamOptions, - TextInputChunk, -} from "./text/public"; - -export { - decodeTextStream, - encodeTextStream, - joinLinesStream, - LineJoinStream, - LineSplitStream, - splitLinesStream, - TextDecodeStream, - TextEncodeStream, -} from "./text/public"; diff --git a/src/text.test.ts b/src/text/index.test.ts similarity index 99% rename from src/text.test.ts rename to src/text/index.test.ts index f0b15d4..b25e20e 100644 --- a/src/text.test.ts +++ b/src/text/index.test.ts @@ -5,7 +5,7 @@ import { readAllChunks, readableFromChunks, stringToBinary, -} from "./index"; +} from "../shared"; import { decodeTextStream, encodeTextStream, @@ -14,7 +14,7 @@ import { splitLinesStream, TextDecodeStream, TextEncodeStream, -} from "./text"; +} from "./index"; describe("text", () => { it("decodes UTF-8 chunks split inside a multibyte character", async () => { diff --git a/src/text/public.ts b/src/text/index.ts similarity index 100% rename from src/text/public.ts rename to src/text/index.ts diff --git a/tsdown.config.ts b/tsdown.config.ts index e2bce88..b44a4ca 100644 --- a/tsdown.config.ts +++ b/tsdown.config.ts @@ -6,7 +6,7 @@ export default defineConfig({ "src/base64.ts", "src/encryption.ts", "src/jsonl.ts", - "src/text.ts", + "src/text/index.ts", "src/png.ts", "src/cobs.ts" ], From 6ced77de36f9295bb5f3574b5bc9dd3a1aa11704 Mon Sep 17 00:00:00 2001 From: mktbsh <59120037+mktbsh@users.noreply.github.com> Date: Fri, 1 May 2026 10:02:32 +0900 Subject: [PATCH 10/17] refactor: remove public API tests for consolidated structure --- src/public-api.test.ts | 60 ------------------------------------------ 1 file changed, 60 deletions(-) delete mode 100644 src/public-api.test.ts diff --git a/src/public-api.test.ts b/src/public-api.test.ts deleted file mode 100644 index cc8f800..0000000 --- a/src/public-api.test.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { describe, expect, it } from "vitest"; -import * as base64Api from "./base64"; -import * as rootApi from "./index"; -import * as jsonlApi from "./jsonl"; -import * as textApi from "./text"; - -describe("root public API", () => { - it("only exports the supported high-level helpers", () => { - expect(Object.keys(rootApi).sort()).toEqual([ - "binaryToString", - "randomBytes", - "readAllBytes", - "readAllChunks", - "readableFromChunks", - "stringToBinary", - ]); - }); -}); - -describe("jsonl public API", () => { - it("only exports the supported JSONL stream helpers", () => { - expect(Object.keys(jsonlApi).sort()).toEqual([ - "JSONLEncodeStream", - "JSONLParseError", - "JSONLParseStream", - "JSONLStringifyStream", - "encodeJSONLStream", - "parseJSONLStream", - "stringifyJSONLStream", - ]); - }); -}); - -describe("text public API", () => { - it("only exports the supported text stream helpers", () => { - expect(Object.keys(textApi).sort()).toEqual([ - "LineJoinStream", - "LineSplitStream", - "TextDecodeStream", - "TextEncodeStream", - "decodeTextStream", - "encodeTextStream", - "joinLinesStream", - "splitLinesStream", - ]); - }); -}); - -describe("base64 public API", () => { - it("only exports the supported base64 stream helpers", () => { - expect(Object.keys(base64Api).sort()).toEqual([ - "Base64DecodeStream", - "Base64EncodeStream", - "decodeBase64Stream", - "decodeBase64UrlStream", - "encodeBase64Stream", - "encodeBase64UrlStream", - ]); - }); -}); From ad38e3d763e7a2db3d9eb0c0633a25163692a021 Mon Sep 17 00:00:00 2001 From: mktbsh <59120037+mktbsh@users.noreply.github.com> Date: Fri, 1 May 2026 10:02:51 +0900 Subject: [PATCH 11/17] refactor: consolidate COBS exports and update import paths Co-authored-by: Copilot --- src/cobs.ts | 8 -------- src/{cobs.test.ts => cobs/index.test.ts} | 6 +++--- src/cobs/{public.ts => index.ts} | 0 src/png/framing.ts | 2 +- 4 files changed, 4 insertions(+), 12 deletions(-) delete mode 100644 src/cobs.ts rename src/{cobs.test.ts => cobs/index.test.ts} (97%) rename src/cobs/{public.ts => index.ts} (100%) diff --git a/src/cobs.ts b/src/cobs.ts deleted file mode 100644 index 6be67b3..0000000 --- a/src/cobs.ts +++ /dev/null @@ -1,8 +0,0 @@ -export { - createCOBSDecoderStream, - createCOBSEncoderStream, - decodeCOBSFrame, - encodeCOBSFrame, - readCOBS, - writeCOBS, -} from "./cobs/public"; diff --git a/src/cobs.test.ts b/src/cobs/index.test.ts similarity index 97% rename from src/cobs.test.ts rename to src/cobs/index.test.ts index 7ba9332..eda14d5 100644 --- a/src/cobs.test.ts +++ b/src/cobs/index.test.ts @@ -1,5 +1,6 @@ import { describe, expect, it } from "vitest"; -import * as cobsApi from "./cobs"; +import { readAllBytes, readAllChunks, readableFromChunks } from "../shared"; +import * as cobsApi from "./index"; import { createCOBSDecoderStream, createCOBSEncoderStream, @@ -7,8 +8,7 @@ import { encodeCOBSFrame, readCOBS, writeCOBS, -} from "./cobs"; -import { readAllBytes, readAllChunks, readableFromChunks } from "./shared"; +} from "./index"; describe("cobs public API", () => { it("exports the supported cobs helpers", () => { diff --git a/src/cobs/public.ts b/src/cobs/index.ts similarity index 100% rename from src/cobs/public.ts rename to src/cobs/index.ts diff --git a/src/png/framing.ts b/src/png/framing.ts index 93a3022..0b578db 100644 --- a/src/png/framing.ts +++ b/src/png/framing.ts @@ -1,4 +1,4 @@ -import { decodeCOBSFrame, encodeCOBSFrame } from "../cobs/public"; +import { decodeCOBSFrame, encodeCOBSFrame } from "../cobs"; import { throwError } from "../shared/error"; import { concatU8Arrays } from "../shared/uint8array"; import { From 3211a21ed1fd6ce9a2084dc8c80899e9ade1f2ec Mon Sep 17 00:00:00 2001 From: mktbsh <59120037+mktbsh@users.noreply.github.com> Date: Fri, 1 May 2026 10:02:55 +0900 Subject: [PATCH 12/17] refactor: format export statements for consistency --- src/shared/index.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/shared/index.ts b/src/shared/index.ts index 18caf28..a76ad20 100644 --- a/src/shared/index.ts +++ b/src/shared/index.ts @@ -1,13 +1,13 @@ export { toArrayBuffer } from "./array-buffer"; export { - binaryToString, - randomBytes, - stringToBinary, + binaryToString, + randomBytes, + stringToBinary, } from "./binary"; export { - readAllBytes, - readAllChunks, - readableFromChunks, + readAllBytes, + readAllChunks, + readableFromChunks, } from "./readable"; From 37b4eaf25c88e17af811c9401c16e2583f0a029a Mon Sep 17 00:00:00 2001 From: mktbsh <59120037+mktbsh@users.noreply.github.com> Date: Fri, 1 May 2026 10:04:23 +0900 Subject: [PATCH 13/17] refactor: reorganize encryption module structure and update import paths Co-authored-by: Copilot --- package.json | 4 ++-- src/encryption.ts | 11 ----------- .../index.test.ts} | 16 ++++++++-------- src/encryption/{public.ts => index.ts} | 0 tsdown.config.ts | 4 ++-- 5 files changed, 12 insertions(+), 23 deletions(-) delete mode 100644 src/encryption.ts rename src/{encryption.test.ts => encryption/index.test.ts} (99%) rename src/encryption/{public.ts => index.ts} (100%) diff --git a/package.json b/package.json index 60dcf29..2af00a3 100644 --- a/package.json +++ b/package.json @@ -27,8 +27,8 @@ "exports": { ".": "./dist/index.js", "./base64": "./dist/base64.js", - "./cobs": "./dist/cobs.js", - "./encryption": "./dist/encryption.js", + "./cobs": "./dist/cobs/index.js", + "./encryption": "./dist/encryption/index.js", "./jsonl": "./dist/jsonl.js", "./png": "./dist/png.js", "./text": "./dist/text/index.js", diff --git a/src/encryption.ts b/src/encryption.ts deleted file mode 100644 index e0ba5a1..0000000 --- a/src/encryption.ts +++ /dev/null @@ -1,11 +0,0 @@ -export type { - EncryptionStreamOptions, - WebCryptoStream, -} from "./encryption/public"; -export { - DecryptionStream, - decryptStream, - EncryptionStream, - encryptStream, - webCryptoStream, -} from "./encryption/public"; diff --git a/src/encryption.test.ts b/src/encryption/index.test.ts similarity index 99% rename from src/encryption.test.ts rename to src/encryption/index.test.ts index 3a1f309..182a267 100644 --- a/src/encryption.test.ts +++ b/src/encryption/index.test.ts @@ -1,18 +1,18 @@ import { describe, expect, it } from "vitest"; -import { - DecryptionStream, - decryptStream, - EncryptionStream, - encryptStream, - webCryptoStream, -} from "./encryption"; -import { HEADER_SIZE, TAG_LENGTH } from "./encryption/constants"; import { binaryToString, randomBytes, readAllBytes, readableFromChunks, stringToBinary, +} from "../shared"; +import { HEADER_SIZE, TAG_LENGTH } from "./constants"; +import { + DecryptionStream, + decryptStream, + EncryptionStream, + encryptStream, + webCryptoStream, } from "./index"; const TEST_RECORD_SIZE = 64; diff --git a/src/encryption/public.ts b/src/encryption/index.ts similarity index 100% rename from src/encryption/public.ts rename to src/encryption/index.ts diff --git a/tsdown.config.ts b/tsdown.config.ts index b44a4ca..5d9e724 100644 --- a/tsdown.config.ts +++ b/tsdown.config.ts @@ -4,11 +4,11 @@ export default defineConfig({ entry: [ "src/index.ts", "src/base64.ts", - "src/encryption.ts", + "src/encryption/index.ts", "src/jsonl.ts", "src/text/index.ts", "src/png.ts", - "src/cobs.ts" + "src/cobs/index.ts", ], outDir: "dist", target: "es2022", From 0cebc58724f14adb82858dc5b585071067fb2c8b Mon Sep 17 00:00:00 2001 From: mktbsh <59120037+mktbsh@users.noreply.github.com> Date: Fri, 1 May 2026 10:05:17 +0900 Subject: [PATCH 14/17] refactor: restructure base64 module by consolidating exports and updating paths Co-authored-by: Copilot --- package.json | 2 +- src/base64.ts | 15 --------------- src/{base64.test.ts => base64/index.test.ts} | 16 ++++++++-------- src/base64/{public.ts => index.ts} | 0 tsdown.config.ts | 2 +- 5 files changed, 10 insertions(+), 25 deletions(-) delete mode 100644 src/base64.ts rename src/{base64.test.ts => base64/index.test.ts} (98%) rename src/base64/{public.ts => index.ts} (100%) diff --git a/package.json b/package.json index 2af00a3..75df2e7 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ ], "exports": { ".": "./dist/index.js", - "./base64": "./dist/base64.js", + "./base64": "./dist/base64/index.js", "./cobs": "./dist/cobs/index.js", "./encryption": "./dist/encryption/index.js", "./jsonl": "./dist/jsonl.js", diff --git a/src/base64.ts b/src/base64.ts deleted file mode 100644 index 9d11a95..0000000 --- a/src/base64.ts +++ /dev/null @@ -1,15 +0,0 @@ -export type { - Base64DecodeStreamOptions, - Base64EncodeStreamOptions, - Base64InputChunk, - Base64Variant, -} from "./base64/public"; - -export { - Base64DecodeStream, - Base64EncodeStream, - decodeBase64Stream, - decodeBase64UrlStream, - encodeBase64Stream, - encodeBase64UrlStream, -} from "./base64/public"; diff --git a/src/base64.test.ts b/src/base64/index.test.ts similarity index 98% rename from src/base64.test.ts rename to src/base64/index.test.ts index 1ac142a..1c2956a 100644 --- a/src/base64.test.ts +++ b/src/base64/index.test.ts @@ -1,4 +1,11 @@ import { describe, expect, it } from "vitest"; +import { + binaryToString, + readAllBytes, + readAllChunks, + readableFromChunks, + stringToBinary, +} from "../shared"; import { Base64DecodeStream, Base64EncodeStream, @@ -6,14 +13,7 @@ import { decodeBase64UrlStream, encodeBase64Stream, encodeBase64UrlStream, -} from "./base64"; -import { - binaryToString, - readAllBytes, - readAllChunks, - readableFromChunks, - stringToBinary, -} from "./shared"; +} from "./index"; describe("base64", () => { it("encodes byte chunks across 3-byte boundaries", async () => { diff --git a/src/base64/public.ts b/src/base64/index.ts similarity index 100% rename from src/base64/public.ts rename to src/base64/index.ts diff --git a/tsdown.config.ts b/tsdown.config.ts index 5d9e724..a73f311 100644 --- a/tsdown.config.ts +++ b/tsdown.config.ts @@ -3,7 +3,7 @@ import { defineConfig } from "tsdown"; export default defineConfig({ entry: [ "src/index.ts", - "src/base64.ts", + "src/base64/index.ts", "src/encryption/index.ts", "src/jsonl.ts", "src/text/index.ts", From 11913c32622fff6af3f1a0934039763870a69b9a Mon Sep 17 00:00:00 2001 From: mktbsh <59120037+mktbsh@users.noreply.github.com> Date: Fri, 1 May 2026 10:06:03 +0900 Subject: [PATCH 15/17] refactor: reorganize jsonl module structure and update import paths Co-authored-by: Copilot --- package.json | 2 +- src/jsonl.ts | 15 --------------- src/{jsonl.test.ts => jsonl/index.test.ts} | 4 ++-- src/jsonl/{public.ts => index.ts} | 0 tsdown.config.ts | 2 +- 5 files changed, 4 insertions(+), 19 deletions(-) delete mode 100644 src/jsonl.ts rename src/{jsonl.test.ts => jsonl/index.test.ts} (99%) rename src/jsonl/{public.ts => index.ts} (100%) diff --git a/package.json b/package.json index 75df2e7..a730f74 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "./base64": "./dist/base64/index.js", "./cobs": "./dist/cobs/index.js", "./encryption": "./dist/encryption/index.js", - "./jsonl": "./dist/jsonl.js", + "./jsonl": "./dist/jsonl/index.js", "./png": "./dist/png.js", "./text": "./dist/text/index.js", "./package.json": "./package.json" diff --git a/src/jsonl.ts b/src/jsonl.ts deleted file mode 100644 index f684f6a..0000000 --- a/src/jsonl.ts +++ /dev/null @@ -1,15 +0,0 @@ -export type { - JSONLInputChunk, - JSONLParseStreamOptions, - JSONLStringifyStreamOptions, -} from "./jsonl/public"; - -export { - encodeJSONLStream, - JSONLEncodeStream, - JSONLParseError, - JSONLParseStream, - JSONLStringifyStream, - parseJSONLStream, - stringifyJSONLStream, -} from "./jsonl/public"; diff --git a/src/jsonl.test.ts b/src/jsonl/index.test.ts similarity index 99% rename from src/jsonl.test.ts rename to src/jsonl/index.test.ts index 18c1914..70ce3cb 100644 --- a/src/jsonl.test.ts +++ b/src/jsonl/index.test.ts @@ -5,7 +5,7 @@ import { readAllChunks, readableFromChunks, stringToBinary, -} from "./index"; +} from "../shared"; import { encodeJSONLStream, JSONLEncodeStream, @@ -14,7 +14,7 @@ import { JSONLStringifyStream, parseJSONLStream, stringifyJSONLStream, -} from "./jsonl"; +} from "./index"; type Event = { id: string; diff --git a/src/jsonl/public.ts b/src/jsonl/index.ts similarity index 100% rename from src/jsonl/public.ts rename to src/jsonl/index.ts diff --git a/tsdown.config.ts b/tsdown.config.ts index a73f311..3e09f2a 100644 --- a/tsdown.config.ts +++ b/tsdown.config.ts @@ -5,7 +5,7 @@ export default defineConfig({ "src/index.ts", "src/base64/index.ts", "src/encryption/index.ts", - "src/jsonl.ts", + "src/jsonl/index.ts", "src/text/index.ts", "src/png.ts", "src/cobs/index.ts", From 713800228246ead0cc2810ff1d9257c86e23eea9 Mon Sep 17 00:00:00 2001 From: mktbsh <59120037+mktbsh@users.noreply.github.com> Date: Fri, 1 May 2026 10:07:09 +0900 Subject: [PATCH 16/17] refactor: reorganize PNG module structure and update import paths --- package.json | 2 +- src/png.ts | 9 --------- src/{png.test.ts => png/index.test.ts} | 14 +++++++------- src/png/{public.ts => index.ts} | 0 src/png/transformers.ts | 2 +- tsdown.config.ts | 2 +- 6 files changed, 10 insertions(+), 19 deletions(-) delete mode 100644 src/png.ts rename src/{png.test.ts => png/index.test.ts} (99%) rename src/png/{public.ts => index.ts} (100%) diff --git a/package.json b/package.json index a730f74..a0575d5 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "./cobs": "./dist/cobs/index.js", "./encryption": "./dist/encryption/index.js", "./jsonl": "./dist/jsonl/index.js", - "./png": "./dist/png.js", + "./png": "./dist/png/index.js", "./text": "./dist/text/index.js", "./package.json": "./package.json" }, diff --git a/src/png.ts b/src/png.ts deleted file mode 100644 index e5d60f3..0000000 --- a/src/png.ts +++ /dev/null @@ -1,9 +0,0 @@ -export type { - PNGTextChunkWriteOptions, - PNGTextChunkWriter, -} from "./png/public"; -export { - createPNGTextChunkWriter, - extractPNGTextChunk, - streamPNGTextChunk, -} from "./png/public"; diff --git a/src/png.test.ts b/src/png/index.test.ts similarity index 99% rename from src/png.test.ts rename to src/png/index.test.ts index c59aea0..0d17829 100644 --- a/src/png.test.ts +++ b/src/png/index.test.ts @@ -1,14 +1,14 @@ import { describe, expect, it } from "vitest"; -import { decodeCOBSFrame, encodeCOBSFrame } from "./cobs"; -import * as pngApi from "./png"; +import { decodeCOBSFrame, encodeCOBSFrame } from "../cobs"; +import { readAllBytes, readableFromChunks } from "../shared"; import { PNG_INTERNAL_TEXT_CHUNK_KEYWORD, PNG_PAYLOAD_MAGIC, PNG_PAYLOAD_SEGMENT_DATA_MAX_LENGTH, PNG_PAYLOAD_VERSION, PNG_SIGNATURE, -} from "./png/constants"; -import { crc32 } from "./png/crc32"; +} from "./constants"; +import { crc32 } from "./crc32"; import { createChunk, createPayloadDataSegment, @@ -18,13 +18,13 @@ import { isInternalTextChunk, parsePayloadSegment, parsePNGBytes, -} from "./png/framing"; +} from "./framing"; +import * as pngApi from "./index"; import { createPNGTextChunkWriter, extractPNGTextChunk, streamPNGTextChunk, -} from "./png/public"; -import { readAllBytes, readableFromChunks } from "./shared"; +} from "./index"; const MINIMAL_PNG = concatBytes( PNG_SIGNATURE, diff --git a/src/png/public.ts b/src/png/index.ts similarity index 100% rename from src/png/public.ts rename to src/png/index.ts diff --git a/src/png/transformers.ts b/src/png/transformers.ts index 13337d8..2c68211 100644 --- a/src/png/transformers.ts +++ b/src/png/transformers.ts @@ -1,6 +1,7 @@ import { type ByteQueue, createByteQueue } from "../byte-queue"; import { throwError } from "../shared/error"; import { concatU8Arrays } from "../shared/uint8array"; +import type { PNGTextChunkWriteOptions, PNGTextChunkWriter } from "."; import { PNG_IEND_CHUNK_TYPE, PNG_PAYLOAD_SEGMENT_DATA_MAX_LENGTH, @@ -18,7 +19,6 @@ import { parsePNGChunk, parsePNGChunkHeader, } from "./framing"; -import type { PNGTextChunkWriteOptions, PNGTextChunkWriter } from "./public"; interface Deferred { promise: Promise; diff --git a/tsdown.config.ts b/tsdown.config.ts index 3e09f2a..966d84e 100644 --- a/tsdown.config.ts +++ b/tsdown.config.ts @@ -7,7 +7,7 @@ export default defineConfig({ "src/encryption/index.ts", "src/jsonl/index.ts", "src/text/index.ts", - "src/png.ts", + "src/png/index.ts", "src/cobs/index.ts", ], outDir: "dist", From 9ad56dd0c6e39fb47e037cab5d6239f295066b19 Mon Sep 17 00:00:00 2001 From: mktbsh <59120037+mktbsh@users.noreply.github.com> Date: Fri, 1 May 2026 10:10:39 +0900 Subject: [PATCH 17/17] refactor: consolidate shared module exports and reorganize internal file structure --- .changeset/mighty-snails-report.md | 5 +++++ src/encryption/index.ts | 4 ++-- src/shared/readable.ts | 2 +- src/{transform-stream.ts => shared/stream.ts} | 2 ++ src/stream-types.ts | 1 - 5 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 .changeset/mighty-snails-report.md rename src/{transform-stream.ts => shared/stream.ts} (57%) delete mode 100644 src/stream-types.ts diff --git a/.changeset/mighty-snails-report.md b/.changeset/mighty-snails-report.md new file mode 100644 index 0000000..08133c4 --- /dev/null +++ b/.changeset/mighty-snails-report.md @@ -0,0 +1,5 @@ +--- +"@hsblabs/web-stream-extras": patch +--- + +refactor: consolidate shared module exports and reorganize internal file structure diff --git a/src/encryption/index.ts b/src/encryption/index.ts index b6f3683..f9571f5 100644 --- a/src/encryption/index.ts +++ b/src/encryption/index.ts @@ -2,9 +2,9 @@ import { toArrayBuffer } from "../shared/array-buffer"; import { decodeBase64Url, encodeBase64Url } from "../shared/base64url"; import { randomBytes } from "../shared/binary"; import { throwError } from "../shared/error"; +import type { BinaryReadableStream } from "../shared/stream"; +import { ByteTransformStream } from "../shared/stream"; import { concatU8Arrays, toU8Array } from "../shared/uint8array"; -import type { BinaryReadableStream } from "../stream-types"; -import { ByteTransformStream } from "../transform-stream"; import { AES_GCM_BIT_LENGTH, ALGORITHM_AES_GCM, diff --git a/src/shared/readable.ts b/src/shared/readable.ts index 0d86425..3b4ad65 100644 --- a/src/shared/readable.ts +++ b/src/shared/readable.ts @@ -1,5 +1,5 @@ -import type { BinaryReadableStream } from "../stream-types"; import { isInstance } from "./is"; +import type { BinaryReadableStream } from "./stream"; import { concatU8Arrays } from "./uint8array"; export function toReadableStream( diff --git a/src/transform-stream.ts b/src/shared/stream.ts similarity index 57% rename from src/transform-stream.ts rename to src/shared/stream.ts index ab2bcb5..f57d2dd 100644 --- a/src/transform-stream.ts +++ b/src/shared/stream.ts @@ -1,3 +1,5 @@ +export type BinaryReadableStream = ReadableStream; + export class ByteTransformStream extends TransformStream< Uint8Array, Uint8Array diff --git a/src/stream-types.ts b/src/stream-types.ts deleted file mode 100644 index f3d6c2f..0000000 --- a/src/stream-types.ts +++ /dev/null @@ -1 +0,0 @@ -export type BinaryReadableStream = ReadableStream;