v3: comments say what the code can't — the documentation pass wanted JSDoc on every export and every field of an exported interface, which filled the code with restatements ("The dump.", "Whether it is loading.", "The props of X.", "Renders the X.") and module docs that told a reader nothing ("The hot and new feeds, and the props every main feed of the index takes."); some were wrong as well as vague. Every comment in api/, shared/ and src/ is rewritten under one rule, now stated in the README's "Comments" section: every module and export still has a JSDoc, and it gives context (who uses it and where), usage (what a caller must know: a precondition, what it leaves to the caller, a side effect) or its place in the chain (where its input comes from, where its output goes); a field, parameter, private function or local gets one only when it adds to its parent's, and context about a whole type goes on the type; a type's doc is phrased from the value's side ("Returned to Y by X when Z", "Passed to Y by X"); full sentences, as short as they can be, no label-colon-list; // goes wherever the code isn't obvious and says why, and the section banners and narration go. Every claim was checked against the code, which turned up some forty comments that were wrong: DumpCard's claimed it was only used by the hot and new feeds, the WebSocket welcome claimed to be a socket's first message (presence comes first), UpdateUserRequest said null removes a description (it keeps it), deletedDumpIds leaves out that it also holds dumps made private, THEME_COLOR claimed to mirror index.html's, and the like. The routers' JSDoc now says where they are mounted and what becomes of a thrown APIException. doc-lint.ts lets a field without a doc through; a module or export without one still fails. No code changes; 204 backend and 628 frontend tests pass, and doc:lint, deno check, deno lint and tsc are clean.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
/**
|
||||
* Following users and playlists, and the feeds made of what one follows.
|
||||
* Stores who follows which users and playlists, and builds the feeds and
|
||||
* lists made from it. `routes/follows.ts` serves the caller's own, and
|
||||
* `routes/users.ts` what any user follows.
|
||||
*
|
||||
* @module
|
||||
*/
|
||||
@@ -25,11 +27,9 @@ import { isPlaylistRow, playlistRowToApi } from "../model/playlist.ts";
|
||||
import { type Page, pageOf } from "../lib/pagination.ts";
|
||||
import { attachCategoryIds } from "./category-service.ts";
|
||||
|
||||
// ── Follow / unfollow a user ──────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Makes `followerId` follow `followedUserId`, and notifies them the first
|
||||
* time. Following again changes nothing.
|
||||
* Makes `followerId` follow `followedUserId`, and notifies the followed user.
|
||||
* Following again changes nothing.
|
||||
*
|
||||
* @throws {APIException} 400 when a user tries to follow themselves.
|
||||
*/
|
||||
@@ -41,6 +41,7 @@ export function followUser(followerId: string, followedUserId: string): void {
|
||||
"Cannot follow yourself",
|
||||
);
|
||||
}
|
||||
// The unique index answers "already following" without a race.
|
||||
let isNew = true;
|
||||
try {
|
||||
db.prepare(
|
||||
@@ -70,11 +71,10 @@ export function unfollowUser(followerId: string, followedUserId: string): void {
|
||||
).run(followerId, followedUserId);
|
||||
}
|
||||
|
||||
// ── Follow / unfollow a playlist ─────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Makes `followerId` follow a public playlist, and notifies its owner the
|
||||
* first time. Following again changes nothing.
|
||||
* Makes `followerId` follow a public playlist, and notifies its owner.
|
||||
* Following again changes nothing. A follow outlives the playlist going
|
||||
* private, but the feeds and lists skip it while it is.
|
||||
*
|
||||
* @throws {APIException} 404 when there is no such playlist, 403 when it is
|
||||
* private.
|
||||
@@ -124,9 +124,12 @@ export function unfollowPlaylist(followerId: string, playlistId: string): void {
|
||||
).run(followerId, playlistId);
|
||||
}
|
||||
|
||||
// ── Follow status ─────────────────────────────────────────────────────────────
|
||||
|
||||
/** Returns the ids of every user and playlist `followerId` follows. */
|
||||
/**
|
||||
* Returns the ids of every user and playlist `followerId` follows, private
|
||||
* playlists included, for `GET /api/follows/status`.
|
||||
*
|
||||
* @throws {APIException} 500 when a row doesn't parse.
|
||||
*/
|
||||
export function getFollowStatus(followerId: string): FollowStatus {
|
||||
const rawUserRows = db.prepare(
|
||||
`SELECT id, follower_id, followed_user_id, followed_playlist_id, created_at
|
||||
@@ -152,11 +155,12 @@ export function getFollowStatus(followerId: string): FollowStatus {
|
||||
};
|
||||
}
|
||||
|
||||
// ── Followed-users feed ───────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Returns a page of the public dumps posted by the users `followerId` follows,
|
||||
* newest first, optionally only those in `categoryId`.
|
||||
* newest first, optionally only those in `categoryId`. It feeds the "users"
|
||||
* half of the index's "followed" tab.
|
||||
*
|
||||
* @throws {APIException} 500 when a row doesn't parse as a dump.
|
||||
*/
|
||||
export function getFollowedUsersDumpFeed(
|
||||
followerId: string,
|
||||
@@ -166,7 +170,6 @@ export function getFollowedUsersDumpFeed(
|
||||
): Page<Dump> {
|
||||
const offset = (page - 1) * limit;
|
||||
|
||||
// Optional category filter: join the membership table and constrain to it.
|
||||
const catJoin = categoryId
|
||||
? "INNER JOIN dump_categories dc ON dc.dump_id = d.id AND dc.category_id = ?"
|
||||
: "";
|
||||
@@ -196,11 +199,13 @@ export function getFollowedUsersDumpFeed(
|
||||
return pageOf(items, limit);
|
||||
}
|
||||
|
||||
// ── Followed-playlists dump feed ──────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Returns a page of the public dumps in the public playlists `followerId`
|
||||
* follows, most recently added first, optionally only those in `categoryId`.
|
||||
* follows, optionally only those in `categoryId`. It feeds the "playlists"
|
||||
* half of the index's "followed" tab. A dump in several of them shows once,
|
||||
* dated by its latest addition.
|
||||
*
|
||||
* @throws {APIException} 500 when a row doesn't parse as a dump.
|
||||
*/
|
||||
export function getFollowedPlaylistsDumpFeed(
|
||||
followerId: string,
|
||||
@@ -242,11 +247,11 @@ export function getFollowedPlaylistsDumpFeed(
|
||||
return pageOf(items, limit);
|
||||
}
|
||||
|
||||
// ── Followed playlists (as playlist objects) ──────────────────────────────────
|
||||
|
||||
/**
|
||||
* Returns a page of the public playlists `userId` follows, most recently
|
||||
* followed first.
|
||||
* followed first, for their profile and playlists pages.
|
||||
*
|
||||
* @throws {APIException} 500 when a row doesn't parse as a playlist.
|
||||
*/
|
||||
export function getFollowedPlaylistsByUser(
|
||||
userId: string,
|
||||
@@ -277,9 +282,13 @@ export function getFollowedPlaylistsByUser(
|
||||
return pageOf(rawRows.map(playlistRowToApi), limit);
|
||||
}
|
||||
|
||||
// ── Followed users (as user objects) ─────────────────────────────────────────
|
||||
|
||||
/** Returns a page of the users `userId` follows, most recently followed first. */
|
||||
/**
|
||||
* Returns a page of the users `userId` follows, most recently followed first,
|
||||
* for their profile page. The users carry their password hash and email: pass
|
||||
* them through `toPublicUser` before sending them.
|
||||
*
|
||||
* @throws {APIException} 500 when a row doesn't parse as a user.
|
||||
*/
|
||||
export function getFollowedUsersByUser(
|
||||
userId: string,
|
||||
page: number,
|
||||
|
||||
Reference in New Issue
Block a user