/playlists is the new page of every public playlist, newest first (GET /api/playlists), and /playlists/<slug> a playlist category's, with a menu of the categories, linked from the user menu as "All playlists"; `playlists` is reserved as a dump category's slug, and one that had it is renamed. A profile's Playlists tab narrows to a playlist category with the same menu as its Dumps tab (?category=), and so do the Dumps and Playlists tabs of /search, each with its own kind (category and playlistCategory for GET /api/search), another tab dropping it. The category service takes the kind throughout, so a dump can't be filed under a playlist category nor the other way round, and categoryJoin is the one filter join the dump, follow and playlist services share. useCategories(kind) gives one kind's set from the one fetch, CategoryChips replaces the chips the dump card and page each drew, useCategoryFilter keeps a list to its category as the socket brings more, and useCategorySelection holds a form's picked categories. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
53 lines
1.6 KiB
TypeScript
53 lines
1.6 KiB
TypeScript
/**
|
|
* Turns the rows the category service reads from `categories` into the {@link
|
|
* Category} the category routes send.
|
|
*
|
|
* @module
|
|
*/
|
|
|
|
import type { SQLOutputValue } from "node:sqlite";
|
|
import {
|
|
type Category,
|
|
type CategoryKind,
|
|
isCategoryKind,
|
|
} from "../../shared/category.ts";
|
|
|
|
/** Returned by the category service's `SELECT`s on `categories`. */
|
|
export interface CategoryRow {
|
|
id: string;
|
|
kind: CategoryKind;
|
|
slug: string;
|
|
name: string;
|
|
/** Sorts the categories, lowest first. */
|
|
position: number;
|
|
created_at: string;
|
|
updated_at: string | null;
|
|
[key: string]: SQLOutputValue;
|
|
}
|
|
|
|
/** Checks whether a row `node:sqlite` returned is a {@link CategoryRow}. */
|
|
export function isCategoryRow(obj: unknown): obj is CategoryRow {
|
|
return !!obj && typeof obj === "object" &&
|
|
"id" in obj && typeof obj.id === "string" &&
|
|
"kind" in obj && isCategoryKind(obj.kind) &&
|
|
"slug" in obj && typeof obj.slug === "string" &&
|
|
"name" in obj && typeof obj.name === "string" &&
|
|
"position" in obj && typeof obj.position === "number" &&
|
|
"created_at" in obj && typeof obj.created_at === "string" &&
|
|
"updated_at" in obj &&
|
|
(typeof obj.updated_at === "string" || obj.updated_at === null);
|
|
}
|
|
|
|
/** Converts `row` to the {@link Category} the category routes send. */
|
|
export function categoryRowToApi(row: CategoryRow): Category {
|
|
return {
|
|
id: row.id,
|
|
kind: row.kind,
|
|
slug: row.slug,
|
|
name: row.name,
|
|
position: row.position,
|
|
createdAt: new Date(row.created_at),
|
|
updatedAt: row.updated_at ? new Date(row.updated_at) : undefined,
|
|
};
|
|
}
|