diff --git a/lib/Lru.ts b/lib/Lru.ts index 4cb35d4cac1139eb80477beb3b0135fa16c27c12..6a324e1c0677ad319cbcd13e78461ea83dd77aa8 100644 --- a/lib/Lru.ts +++ b/lib/Lru.ts @@ -1,6 +1,6 @@ /** - * Least-recently-used cache. - * This module is intended to be imported via the main class. + * least-recently-used cache. + * this module is intended to be imported via the main class. * * ```ts * import { Lru } from '@clo/lib/Lru'; diff --git a/lib/assert.ts b/lib/assert.ts index b7a9fe63cfa16051f28b2182b38baf3df807b351..7d76eff313d65864f6d9ccb651f4556cf1ad9c4f 100644 --- a/lib/assert.ts +++ b/lib/assert.ts @@ -1,6 +1,7 @@ /** * assertions and type narrowing helpers. intended to be imported per symbol. * functions are capitalized to make them stand out in a codebase. + * * @module */ /* node:coverage disable */ diff --git a/lib/async.ts b/lib/async.ts index 7fbd7c00428cbf577905bf1c18698775db6e6f5e..c70b76a05f791da172c4952129286d13751579f5 100644 --- a/lib/async.ts +++ b/lib/async.ts @@ -1,3 +1,9 @@ +/** + * helpers to deal with promises and asynchronous execution. + * + * @module + */ + /*** @deprecated */ interface ARCEValue { value: T; diff --git a/lib/bytes.ts b/lib/bytes.ts index b1733dba492274b0b571a95b6127656b9a0ff8d7..b96b3d64836660fe2fa7dcf34be8f70e93c8612c 100644 --- a/lib/bytes.ts +++ b/lib/bytes.ts @@ -1,3 +1,9 @@ +/** + * helpers to deal with `Uint8Array` and other `ArrayBufferView`s + * + * @module + */ + export function eql( a: T, b: T, diff --git a/lib/error.ts b/lib/error.ts index bfa12df74c4c3c3083853caa544d19c8a2ad9011..a4f980f8c7e0d01260dd46b07894d9d01f24a215 100644 --- a/lib/error.ts +++ b/lib/error.ts @@ -1,5 +1,5 @@ /** - * Helper functions for dealing with the `unknown` type, mainly in `catch` + * helper functions for dealing with the `unknown` type, mainly in `catch` * blocks or promise rejection callbacks. * * @module diff --git a/lib/http.ts b/lib/http.ts index 79575e48f09fd487ed28d9dcb0c648ec0f26ae2c..2e14823c16d2429c1a158a200710767a8ad20346 100644 --- a/lib/http.ts +++ b/lib/http.ts @@ -1,3 +1,10 @@ +/** + * helpers for building applications with an HTTP server, with integrations with + * `@clo/lib/progress` + * + * @module + */ + export interface Server { port: number; url: string; @@ -26,15 +33,6 @@ export interface ServeContext { export async function serve( { respond, port, progress: rootNode = progress.nullNode }: ServeOptions, ): Promise { - const nodeHttp = node.builtin( - "http", - ) as unknown as typeof import("node:http"); - const stream = node.builtin("stream"); - ASSERT( - nodeHttp && stream, - "http.serve must be called in a node.js compatible runtime", - ); - const server = nodeHttp.createServer((req, res) => { const headers = new Headers(); for (const key in req.headers) { @@ -55,7 +53,8 @@ export async function serve( headers, body: hasNoBody ? undefined - : stream.Readable.toWeb(req), + : stream.Readable.toWeb(req) as ReadableStream, + // @ts-expect-error duplex: hasNoBody ? undefined : "half", }, ); @@ -68,7 +67,7 @@ export async function serve( Array.from(response.headers.entries()), ); if (response.body) { - stream.Readable.fromWeb(response.body).pipe(res); + stream.Readable.fromWeb(response.body as import("node:stream/web").ReadableStream).pipe(res); } else { res.end(); } @@ -166,6 +165,8 @@ export interface Range { end: number; } +import * as nodeHttp from "node:http"; +import * as stream from "node:stream"; import { ASSERT, UNWRAP } from "./assert.ts"; import * as error from "./error.ts"; import * as node from "./node.ts"; diff --git a/lib/log.ts b/lib/log.ts index 881fb158655280db90fb2cf2b4ca79500af69e99..14f68909a0d073040862e5fdcd8b03abc9bf7b3a 100644 --- a/lib/log.ts +++ b/lib/log.ts @@ -482,7 +482,7 @@ export function createTerminalWidgetHost( } partialLineIndex = partialLineLength(buffer); buffer = ""; - rendering = false + rendering = false; return; } @@ -1216,8 +1216,8 @@ export type MessageFormatFunction = ( ) => string; import { ASSERT, UNWRAP } from "./assert.ts"; -import * as errors from "./error.ts"; import * as async from "./async.ts"; +import * as errors from "./error.ts"; import * as stack from "./log/stack.ts"; import * as node from "./node.ts"; import * as string from "./string.ts"; diff --git a/lib/mime.ts b/lib/mime.ts index e31688b9a5ddff761b7d93a2dacc9a5f159cba70..36212bf4def3d9e0cdbdacb558709a322e26bce3 100644 --- a/lib/mime.ts +++ b/lib/mime.ts @@ -1,5 +1,6 @@ /** - * a small mime type library. + * a small mime type lookup table library. + * * @module */ diff --git a/lib/node.ts b/lib/node.ts index 9d5f76b44a23d47be3263717b33f174ceda6248a..da53818545e5e85974998f94139780c6adb9d34a 100644 --- a/lib/node.ts +++ b/lib/node.ts @@ -7,6 +7,7 @@ * if you are using a competent bundler, you can define `globalThis.process` as * a bundling constant (esbuild: `--define`) to enable tree shaking across the * library to only include browser code paths. + * * @module */ diff --git a/lib/progress.ts b/lib/progress.ts index 69823d0a1916c17bde8fdd140328641f59d064c6..9fcc01deb41e0165f6980a5d112a2f22a1bc196e 100644 --- a/lib/progress.ts +++ b/lib/progress.ts @@ -40,6 +40,7 @@ * needs more work and feature development. the API of `Node` is stable, though. * * inspired by the [Zig Progress API](https://andrewkelley.me/post/zig-new-cli-progress-bar-explained.html). + * * @module */ diff --git a/lib/queue.ts b/lib/queue.ts index a2e51a0546fefbd6660c2a53f095f018c5abc222..e5c4dbc4607cbb678af0acd0723fae64e7280a69 100644 --- a/lib/queue.ts +++ b/lib/queue.ts @@ -1,6 +1,7 @@ /** * implements a priority queue. jobs are be automatically cancelled via * `AbortSignal` and rescheduled when higher priority tasks come in. + * * @module */ diff --git a/lib/stream.ts b/lib/stream.ts index e836387e08b962bbd206803ac451c62ddd73e582..6c89ea46d5e9158542120383e6d3c8dac4d956d8 100644 --- a/lib/stream.ts +++ b/lib/stream.ts @@ -1,6 +1,8 @@ /** - * this @module contains helpers for creating and consuming `ReadableStream`, + * this module contains helpers for creating and consuming `ReadableStream`, * particularly with binary payloads. + * + * @module */ const shared = new Uint8Array(8); diff --git a/lib/string.ts b/lib/string.ts index c69e3c431548f08b3337c500f8acd5c6641e2a8d..1759fd0bd466a28da88fe4a8e239ab5b973c8dc0 100644 --- a/lib/string.ts +++ b/lib/string.ts @@ -1,3 +1,10 @@ +/** + * helpers for strings, escaping, and encoding. + * + * @module + */ + +/** count the number of `\n` characters are in the string */ export function countNewlines(str: string): number { let count = 0; for (let i = 0, { length } = str; i < length; i += 1) { diff --git a/lib/string/ansi.ts b/lib/string/ansi.ts index 6cfeeadc1d81ae67f98373a54803a0d28a38d238..a80d471a0d93a1e3ae3a5466104c704ab8d6ef74 100644 --- a/lib/string/ansi.ts +++ b/lib/string/ansi.ts @@ -6,7 +6,7 @@ * note that this file only produces escape sequences, and does not yet feature * detection or fallback code. * - * @module + * @module ansi */ /** resets all ansi styles */ diff --git a/lib/subprocess.ts b/lib/subprocess.ts index f2ab0e5330ae98b9d736c54cb3ef8d33cac967ea..157485b77b5ac1d2b97aa11d58dfbacb853b4a1c 100644 --- a/lib/subprocess.ts +++ b/lib/subprocess.ts @@ -1,5 +1,9 @@ -// This file is expecting a full rewrite to abstract the Node API away -// entirely, exposing web streams I/O. +/** + * This file is expecting a full rewrite to abstract the Node API away + * entirely, exposing web streams I/O. + * + * @module + */ const execFileRaw: typeof child_process.execFile.__promisify__ = util.promisify( child_process.execFile, diff --git a/lib/subprocess/ffmpeg.ts b/lib/subprocess/ffmpeg.ts index f1af14cfc660f1680185b0dcd1d37f75ea618d04..5f09a26ca6ff9173b3f07e9812771f3c7c30d752 100644 --- a/lib/subprocess/ffmpeg.ts +++ b/lib/subprocess/ffmpeg.ts @@ -1,3 +1,11 @@ +/** + * subprocess bindings for `ffmpeg`, expecting the binary to be in `$PATH` or + * given as the `ffmpeg` option when relevant. + * + * @module ffmpeg + */ + +/** options for {@linkcode spawn} */ export interface SpawnOptions { args: string[]; ffmpeg?: string; diff --git a/lib/testing.ts b/lib/testing.ts index 5348c1dbe74693db830dffe0532e2ec0203bb046..9d1e8cca21a14559938428de5336761ec2f35c6f 100644 --- a/lib/testing.ts +++ b/lib/testing.ts @@ -1,6 +1,8 @@ /** - * @module contains some utilities for writing tests. many are only useful for + * contains some utilities for writing tests. many are only useful for * testing against other library modules. + * + * @module testing */ /** diff --git a/lib/ts.ts b/lib/ts.ts index acf2ae4ea63ceca211fbeaa2c39506dcbd4cfe65..15b5f1781294dbcd14245bd72c3b6923df8de07f 100644 --- a/lib/ts.ts +++ b/lib/ts.ts @@ -1,4 +1,12 @@ +/** + * helpers for the typescript language + * + * @module ts + */ + +/** return type of `setTimeout` regardless of the environment */ export type Timer = ReturnType; +/** return type of `setInterval` regardless of the environment */ export type Interval = ReturnType; /** opposite of the built-in `Readonly` type */ export type Writeable = { -readonly [P in keyof T]: T[P] }; diff --git a/src/source-of-truth.ts b/src/source-of-truth.ts index e17c7391e866beadaadbc3afc5fe45890d48304d..32c5cb9819ae299e5161e31d9b7ca5b7c48160a6 100644 --- a/src/source-of-truth.ts +++ b/src/source-of-truth.ts @@ -1,4 +1,4 @@ -/** @module +/** * The "source of truth" server is the canonical storage for * paper clover's files. This is technically needed because * the VPS she uses can only store about 20gb of content, where @@ -18,6 +18,7 @@ * need cache busts (paper clover does not), the proper way * would be to push a message to all VPS nodes instead of * checking upstream if a file changed every time. + * @module */ const app = new Hono(); export default app;