Skip to content

Commit 6f5e953

Browse files
committed
docs(api): complete JSDoc coverage and export publicly-referenced types
Driven by the JSR score report, verified locally with deno doc --lint (the same tool JSR scores with) down to zero findings: - both entrypoints carry an explicit @module doc (the score's missing-module-docs item keyed on the tag, not the comment) - every exported symbol member gets JSDoc: LibreDbError.code and constructor, OpenOptions.path, Entry.key/value, KvEntry, DocEntry, TableSchema, CatalogEntry, WriteResult.changed, Store.transact - types referenced by public signatures are exported instead of reachable-but-unnamed: Transaction/Entry/Key/Value/Open/Store from the main entry, the browser equivalents from the browser entry (fixes deno doc private-type-ref findings) - index.ts open gains an explicit parameter/return annotation Changeset: minor (new type exports).
1 parent 3a963e9 commit 6f5e953

10 files changed

Lines changed: 54 additions & 4 deletions

File tree

.changeset/jsr-doc-completeness.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@libredb/libredb": minor
3+
---
4+
5+
Complete the API documentation surface and export the types it references.
6+
7+
Every exported symbol — including interface and class members — now carries JSDoc, and both entrypoints carry an explicit module doc, so generated documentation (JSR, editors) is complete. Types that public signatures reference are now exported instead of being reachable-but-unnamed: `Transaction`, `Entry`, `Key`, `Value`, `Open`, and the lens seam `Store` from the main entry; `Transaction`, `Entry`, `Key`, `Value`, and `Store` from the browser entry. No runtime behavior changes.

src/adapter/store.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,8 @@ import type { Transaction } from "../core.ts";
2828
* {@link import("../core.ts").Database.transact}.
2929
*/
3030
export interface Store {
31+
/** Run `run` inside a transaction, applying its writes atomically — the
32+
* same contract as {@link Database.transact}, which is the seam's one
33+
* requirement of an implementer. */
3134
transact<T>(run: (tx: Transaction) => T): T;
3235
}

src/browser.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@
1010
* given, so misuse is a compile error rather than a runtime throw. The point of
1111
* this entry is the import graph: it reaches nothing in `node:`, so a bundler
1212
* can ship it to a browser. The node:fs adapter lives behind Node only.
13+
*
14+
* @module
1315
*/
1416
import { open as openKernel, type Database, type FileSystem, type RecoveryInfo } from "./core.ts";
1517

1618
export { version, LibreDbError } from "./core.ts";
17-
export type { ErrorCode, RecoveryInfo } from "./core.ts";
19+
export type { Entry, ErrorCode, Key, RecoveryInfo, Transaction, Value } from "./core.ts";
20+
export type { Store } from "./adapter/store.ts";
1821
// OpenOptions (the kernel's permissive type, fs optional) is intentionally NOT
1922
// re-exported here: the browser `open` is typed with BrowserOpenOptions, where fs
2023
// is required alongside a path, so exposing OpenOptions would advertise a

src/core.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,12 @@ export type ErrorCode =
6060
* humans and may change between releases.
6161
*/
6262
export class LibreDbError extends Error {
63+
/** The stable failure code — the part of the error a caller may branch on.
64+
* See {@link ErrorCode} for the meaning of each value. */
6365
readonly code: ErrorCode;
6466

67+
/** Build a kernel error: `message` is prefixed with `libredb: `, and the
68+
* adapter error that caused the failure (if any) rides along as `cause`. */
6569
constructor(code: ErrorCode, message: string, options?: { cause?: unknown }) {
6670
super(`libredb: ${message}`, options);
6771
this.name = "LibreDbError";
@@ -86,7 +90,10 @@ export type Value = Uint8Array;
8690

8791
/** One key/value pair yielded by an ordered range scan. */
8892
export interface Entry {
93+
/** The entry's key. A copy owned by the caller — mutating it cannot touch
94+
* the committed store. */
8995
readonly key: Key;
96+
/** The value stored under {@link key}. Also a caller-owned copy. */
9097
readonly value: Value;
9198
}
9299

@@ -229,6 +236,8 @@ export interface RecoveryInfo {
229236
* kernel is purely in-memory — the natural fit for tests and ephemeral use.
230237
*/
231238
export interface OpenOptions {
239+
/** The file the write-ahead log lives at. Omit it for a purely in-memory
240+
* database (the natural fit for tests and ephemeral use). */
232241
readonly path?: string;
233242
/**
234243
* The filesystem the write-ahead log runs on. Optional at the type level, but a

src/index.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,27 @@
99
* namespaces a database holds, so a tool can render faithful per-kind views;
1010
* {@link isReservedKey} (with {@link RESERVED_MARKER} / {@link CATALOG_PREFIX})
1111
* lets a raw-KV tool hide engine-internal keys instead of hardcoding the layout.
12+
*
13+
* @module
1214
*/
13-
import { open as openKernel, type Open } from "./core.ts";
15+
import { open as openKernel, type Database, type OpenOptions } from "./core.ts";
1416
import { nodeFileSystem } from "./adapter/node-fs.ts";
1517

1618
export { version, LibreDbError } from "./core.ts";
17-
export type { Database, ErrorCode, FileSystem, OpenOptions, RecoveryInfo, WalFile } from "./core.ts";
19+
export type {
20+
Database,
21+
Entry,
22+
ErrorCode,
23+
FileSystem,
24+
Key,
25+
Open,
26+
OpenOptions,
27+
RecoveryInfo,
28+
Transaction,
29+
Value,
30+
WalFile,
31+
} from "./core.ts";
32+
export type { Store } from "./adapter/store.ts";
1833

1934
/**
2035
* Open a LibreDB database on Node or Bun. Identical to the kernel's
@@ -24,7 +39,7 @@ export type { Database, ErrorCode, FileSystem, OpenOptions, RecoveryInfo, WalFil
2439
* The browser entry (`@libredb/libredb/browser`) omits this default so it never
2540
* imports `node:fs`.
2641
*/
27-
export const open: Open = (options) =>
42+
export const open = (options?: OpenOptions): Database =>
2843
options?.path !== undefined && options.fs === undefined
2944
? openKernel({ ...options, fs: nodeFileSystem() })
3045
: openKernel(options);

src/lens/catalog.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,10 @@ export function isReservedKey(key: string): boolean {
154154
* layer); a `document` entry carries only `kind` (documents are schemaless).
155155
*/
156156
export interface CatalogEntry {
157+
/** Which lens the namespace belongs to — the interpretation a cold-opening
158+
* tool needs to render a faithful view. */
157159
readonly kind: "kv" | "document" | "relational";
160+
/** A relational table's declared schema; absent for the schemaless kinds. */
158161
readonly schema?: TableSchema;
159162
}
160163

src/lens/document.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ export type Doc = { [key: string]: JsonValue };
3838
* `Result<DocEntry>` (lens/types.ts), the same envelope the kv lens uses.
3939
*/
4040
export interface DocEntry {
41+
/** The document's id within its collection (the part of the kernel key
42+
* after the `<collection>:` prefix). */
4143
readonly id: string;
44+
/** The decoded document stored under {@link id}. */
4245
readonly doc: Doc;
4346
}
4447

src/lens/kv.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ import type { Store } from "../adapter/store.ts";
2929
/** One key/value pair from a range scan, decoded to strings. The kv-lens
3030
* counterpart of the kernel's byte-level {@link import("../core.ts").Entry}. */
3131
export interface KvEntry {
32+
/** The entry's key, decoded from the kernel's UTF-8 bytes. */
3233
readonly key: string;
34+
/** The value stored under {@link key}, decoded the same way. */
3335
readonly value: string;
3436
}
3537

src/lens/relational.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ export type ColumnType = "string" | "number" | "boolean" | "object";
4343
* handle is built.
4444
*/
4545
export interface TableSchema {
46+
/** The column whose value becomes the row's kernel key. Must name a
47+
* declared `"string"` column. */
4648
readonly primaryKey: string;
49+
/** The declared columns: every row must carry exactly these fields, each
50+
* matching its {@link ColumnType}. */
4751
readonly columns: { readonly [name: string]: ColumnType };
4852
}
4953

src/lens/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export interface Result<Row> extends Iterable<Row> {
4646
* write actually did.
4747
*/
4848
export interface WriteResult {
49+
/** How many stored entries the write created, overwrote, or removed. */
4950
readonly changed: number;
5051
}
5152

0 commit comments

Comments
 (0)