xiaohongshu
xiaohongshu
js-ts-business-crud-transforms
Write JavaScript/TypeScript for business applications (frontend and backend) with CRUD, API integration, and data transforms that are correct, readable, and easy to trust. Use when building or reviewing features involving forms, API responses, list/detail views, aggregations, or request/response ...
Full skill instructions
Apply these practices so generated business application code—CRUD, API integration, data shaping, and backend handlers—is correct, readable, performant, and easy to trust with minimal inspection: explicit types, no silent coercion, single-pass transforms, Map/Set for lookups, and small named helpers.
Don't jump into framework implementation right away. Before writing route handlers, components, or ORM calls:
Doing this first keeps implementation aligned with intent and makes it easier to keep validation, transforms, and CRUD consistent.
This applies to all incoming requests and user input: validate first, discard or reject invalid input, and only then consume or use the input. Never trust raw request/API/form data until it has passed validation.
body?.id or body?.key). If invalid, return 400 (or equivalent) with a consistent JSON shape (e.g. { error: "Missing required field" }) and do not proceed to business logic—discard the bad input.data?.items ?? [], Array.isArray(items)). If invalid, return a safe default (e.g. []) or throw with a clear message—don't pass garbage downstream.schema.safeParse(entry) and handle success/failure explicitly; map parsed data to your internal types only after validation succeeds.Number() is risky: Number("Infinity"), Number(""), Number("12.5.5") yield Infinity, 0, NaN. In business data (amounts, counts, IDs), those are usually invalid. Use schema number checks (e.g. z.number().finite(), or reject non-finite) so NaN/Infinity don't slip into calculations or storage. Same idea for dates, enums, and strings—validate the shape and domain you expect, then use the parsed value.safeParse) → use the result only if valid; otherwise return 400 or a safe default. Don't scatter Number(x) or parseInt(x, 10) in business logic without validation.ItemSummary, ListPreview). Use Pick<T, K>, Omit<T, K>, or dedicated DTOs so it's obvious what crosses the boundary.get<Result>(endpoint: string): Promise<Result> so callers get typed responses.{ error: "message" } with the appropriate status (400 validation, 404 not found, 500 server/DB failure). Same structure across all error responses..find() (or similar lookup) on the same list inside the map—e.g. items.map((item) => ({ ...item, related: items.find((r) => r.id === item.relatedId) })). That is O(n²) and redundant.const byId = new Map(items.map((i) => [i.id, i])) in one pass (or use a single for loop), then items.map((item) => ({ ...item, related: byId.get(item.relatedId) ?? null })). Total O(n).map.get(id)..filter((v): v is T => !!v)).groupByCategory, aggregateByKey, formatForDisplay, parseItem. Keep them pure (same input → same output) when possible.isTypeA(item), isTypeB(item) so that after a check, TypeScript narrows the type and you can safely access type-specific fields.item.id). Build the Map in one pass, then convert to arrays if needed; sort once at the end (e.g. by totalCount or your sort key). Never scan the full list per item (no "for each item, filter/list the rest").record?.count ?? 0, data?.items ?? []. For numbers from API/forms, prefer schema validation (e.g. z.number().finite()) so NaN/Infinity are rejected; avoid raw Number(x) in business logic without validation.{ ...base, extra: entry.extra }). When branching (e.g. trying a value), restore state after the branch if you mutated shared data.id or slug from searchParams); if missing or invalid, return 400 or 404 with the same JSON error shape.NextResponse.json(typedData) or framework equivalent).{ error: "..." } on validation failure.db.update("table", { id, value }) or your ORM/RPC). On result.error, return 500 and a generic message; on success, return 200 and a stable shape (e.g. { success: true }).recordAction, upsertItem) so behavior is obvious.get<T>(endpoint): Promise<T>, post<T>(endpoint, body): Promise<T> so the response type is explicit. Handle !response.ok (e.g. reject or throw) so callers don't assume success.{ status: 'idle' | 'loading' | 'success' | 'error', data?, error? }). Don't leave undefined to mean "loading" if "no data" is also valid.getAggregatedData calling groupByCategory and aggregateByKey).const by default; early return on validation failure or missing data so the "happy path" is unindented.continue or return null plus .filter(Boolean) (with a type guard) to skip invalid items.data / result for the final shaped payload and raw / entry for pre-validated items.Following these practices keeps business application code correct, performant, predictable, and easy to trust with minimal inspection.
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience