fix: fix minor gotchas

This commit is contained in:
2026-04-15 14:12:16 +08:00
parent ae2445b79c
commit 392d5f1431
6 changed files with 10 additions and 158 deletions
+4 -5
View File
@@ -4,7 +4,7 @@
- **Build:** `npm run build` (tsup, CJS + ESM + d.ts for all entry points)
- **Test:** `npm run test` (vitest run) | `npm run test:watch` (vitest watch)
- **Type check:** `npx tsc --noEmit` (no dedicated script; run before committing)
- **Type check:** `npm run typecheck`
- **Run a single test:** `npx vitest run -t "test name pattern"`
No linter or formatter is configured. No CI pipeline exists.
@@ -27,15 +27,14 @@ Build produces separate bundles per entry point (see `tsup.config.ts`). The csv-
## Key conventions
- Schema syntax uses **semicolons** (`;`) as separators, not commas
- Identifiers with hyphens (e.g., `word-smith`) are treated as string schemas
- Unknown identifiers throw a `ParseError` — only recognized keywords (`string`, `number`, `int`, `float`, `boolean`) and string literals (`"on"`, `'off'`) are valid types
- `@tablename` / `@tablename[]` are reference schemas resolved at CSV load time
- References can appear nested inside tuples, arrays, and unions; the loader resolves them recursively
- `src/test.ts` is an ad-hoc console script, not a vitest suite — don't treat it as a real test
## Gotchas
- **Circular references** between CSV tables cause stack overflow. The loader detects this via an in-progress loading set and throws `"Circular reference detected"`.
- **No `lint` or `typecheck` npm script** — run `tsc --noEmit` manually before committing changes.
- **Run `npm run typecheck` before committing** to catch type errors.
- **Union member ordering matters** — `parseValue` tries union members in order; the first one that parses wins. This affects references in unions (e.g., `@users[] | string` will try `@users[]` first).
- **csv-parse quote handling** — Double-quoted schema values like `"active" | "inactive"` in CSV rows confuse the csv-parse library. Use unquoted identifiers in the schema row of CSV data when possible.
- **csv-parse quote handling** — Double-quoted schema values like `"active" | "inactive"` in CSV rows confuse the csv-parse library. Use single-quoted string literals (`'on' | 'off'`) or unquoted identifiers in the schema row of CSV data when possible.
- **Module imports use `.js` extension** — source files import from `../index.js` etc. (ESM convention), not `../index.ts`.