▍ humdrum codex / soft

Remove unused source create/delete API + store helpers

ca07f9496d3955fc41b18ad5059531cebeba7dfa
humdrum-tiv <45084903+humdrum-tiv@users.noreply.github.com> · 2026-06-09 12:51

parent e54e9567

Remove unused source create/delete API + store helpers

The source set is now fixed (issue 4), so nothing creates or deletes
sources from the UI. Drop the dead POST /api/sources and
DELETE /api/sources/[id] handlers, the createSource/deleteSource store
helpers, and the now-orphaned CreateSource schema.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

4 files changed

app/api/sources/[id]/route.ts +1 −10
@@ -1,7 +1,7 @@
 import { withErrors, ok, apiError, parseJson } from "@/lib/api";
 import { requireUser } from "@/lib/auth";
 import { UpdateSource } from "@/lib/schemas/source";
-import { getSource, updateSource, deleteSource } from "@/lib/store";
+import { getSource, updateSource } from "@/lib/store";
 import { currentState, ensureFresh } from "@/lib/refresh";
 
 // GET /api/sources/:id — cached state; ?fresh=1 refreshes if stale first.
@@ -25,12 +25,3 @@   const patch = await parseJson(req, UpdateSource);
   const source = updateSource(id, patch);
   return ok({ source });
 });
-
-// DELETE /api/sources/:id
-export const DELETE = withErrors(async (req, { params }) => {
-  await requireUser(req);
-  const { id } = await params;
-  if (!getSource(id)) return apiError("not_found", "Source not found", 404);
-  deleteSource(id);
-  return ok({ ok: true });
-});
app/api/sources/route.ts +2 −11
@@ -1,7 +1,6 @@
-import { withErrors, ok, parseJson } from "@/lib/api";
+import { withErrors, ok } from "@/lib/api";
 import { requireUser } from "@/lib/auth";
-import { CreateSource } from "@/lib/schemas/source";
-import { listSources, createSource } from "@/lib/store";
+import { listSources } from "@/lib/store";
 import { currentState, ensureFresh, isSourceStale } from "@/lib/refresh";
 
 // GET /api/sources — all sources with state. Each item:
@@ -27,11 +26,3 @@     stale: isSourceStale(s),
   }));
   return ok({ sources: states });
 });
-
-// POST /api/sources — create a new source.
-export const POST = withErrors(async (req) => {
-  await requireUser(req);
-  const input = await parseJson(req, CreateSource);
-  const source = createSource(input);
-  return ok({ source }, { status: 201 });
-});
lib/schemas/source.ts +0 −9
@@ -44,14 +44,5 @@   size: SourceSize.default("md"),
 });
 export type Source = z.infer<typeof Source>;
 
-export const CreateSource = Source.omit({ id: true }).partial({
-  enabled: true,
-  config: true,
-  refreshSeconds: true,
-  position: true,
-  size: true,
-});
-export type CreateSource = z.infer<typeof CreateSource>;
-
 export const UpdateSource = Source.partial().omit({ id: true, kind: true });
 export type UpdateSource = z.infer<typeof UpdateSource>;
lib/store.ts +0 −31
@@ -6,7 +6,6 @@ import { randomUUID } from "node:crypto";
 import { desc, eq } from "drizzle-orm";
 import { db } from "@/db";
 import { sources, snapshots, todos, editions, settings } from "@/db/schema";
-import type { SourceKind } from "@/lib/schemas/source";
 import { Settings, SETTINGS_DEFAULTS } from "@/lib/schemas/setting";
 
 const now = () => new Date().toISOString();
@@ -21,32 +20,6 @@ export function getSource(id: string) {
   return db.select().from(sources).where(eq(sources.id, id)).get();
 }
 
-export function createSource(input: {
-  kind: SourceKind;
-  label: string;
-  enabled?: boolean;
-  config?: Record<string, unknown>;
-  refreshSeconds?: number;
-  position?: number;
-  size?: string;
-}) {
-  const id = randomUUID();
-  const maxPos = db.select().from(sources).all().length;
-  db.insert(sources)
-    .values({
-      id,
-      kind: input.kind,
-      label: input.label,
-      enabled: input.enabled ?? true,
-      config: input.config ?? {},
-      refreshSeconds: input.refreshSeconds ?? 900,
-      position: input.position ?? maxPos,
-      size: input.size ?? "md",
-    })
-    .run();
-  return getSource(id)!;
-}
-
 export function updateSource(
   id: string,
   patch: Partial<{
@@ -62,10 +35,6 @@   if (Object.keys(patch).length > 0) {
     db.update(sources).set(patch).where(eq(sources.id, id)).run();
   }
   return getSource(id);
-}
-
-export function deleteSource(id: string) {
-  db.delete(sources).where(eq(sources.id, id)).run();
 }
 
 /* ───────────────── snapshots ───────────────── */