feat(mcpedia): Phase 1 MVP — monorepo, Core, Web UI, MCP server, Postgres FTS
- bun workspaces + Turborepo monorepo (apps/web, apps/mcp; packages/*, scripts) - @mcpedia/core single business-logic layer (Document/Content/Search services) - @mcpedia/db Drizzle schema: documents + weighted tsvector (GIN) for FTS - @mcpedia/parser frontmatter, @mcpedia/search Postgres FTS (ts_rank+ts_headline) - Next.js 16 Web UI (home/doc SSG, search dynamic) + react-markdown render - MCP server (stdio) with 4 tools + in-memory smoke test - scripts/indexer walks content/ -> upserts into Postgres - 4 seed docs; README + PHASES status
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
---
|
||||
id: typescript-patterns
|
||||
title: TypeScript Patterns
|
||||
type: note
|
||||
tags:
|
||||
- typescript
|
||||
- patterns
|
||||
status: published
|
||||
author: asep
|
||||
created_at: 2026-08-19
|
||||
updated_at: 2026-08-19
|
||||
---
|
||||
|
||||
# TypeScript Patterns
|
||||
|
||||
A notebook of small, reusable TypeScript patterns that keep code honest.
|
||||
|
||||
## Branded types for ids
|
||||
|
||||
```ts
|
||||
type DocId = string & { readonly __brand: "DocId" };
|
||||
const asDocId = (s: string) => s as DocId;
|
||||
```
|
||||
|
||||
Branding prevents passing an arbitrary string where a document id is expected.
|
||||
|
||||
## Discriminated unions over inheritance
|
||||
|
||||
Prefer a closed set of variants with a `kind` field. Exhaustiveness checks with
|
||||
`switch` catch missing cases at compile time instead of at runtime.
|
||||
|
||||
## Prefer composition
|
||||
|
||||
When two modules share behavior, extract a function. Avoid inheritance trees
|
||||
that couple unrelated code. This matches the MCPedia Core principle: one layer
|
||||
owns the logic, interfaces only call into it.
|
||||
Reference in New Issue
Block a user