Skip to content

refactor: codex compliance — type safety, validation, sync correctness#115

Merged
kale-stew merged 6 commits into
mainfrom
refactor/codex
Jun 4, 2026
Merged

refactor: codex compliance — type safety, validation, sync correctness#115
kale-stew merged 6 commits into
mainfrom
refactor/codex

Conversation

@kale-stew

Copy link
Copy Markdown
Owner

Summary

Hardens the Notion→D1 sync and photos API for type safety, input validation, and error handling, then drives the codebase to a clean `astro check` (0 errors / 0 warnings) and scaffolds Biome for linting. Built on the original codex-compliance work; the last two commits squash-merge the type-error cleanup and lint setup.

Key Changes

  • Notion sync correctness (src/pages/api/cron.ts): store notion_id for climbs/peaks/gear (was silently NULL, breaking body sync), report accurate insert-vs-update counts, and extract shared parsing helpers into src/lib/notion-helpers.ts (also fixes parseAreaFallback mangling hyphenated areas like Bridger-Teton).
  • Cloudflare env typing (src/env.d.ts): merge bindings into the global Cloudflare.Env interface so env.DB/R2_IMAGES/IMAGES resolve everywhere (cleared ~26 errors).
  • Photos API (utils/photos-api.ts, route files): validate the GET /api/photos query with Zod, dedupe Zod error formatting, build the Hono app once per isolate instead of per request.
  • Type errors → 0 (merge: type errs): typed DOM queries as HTMLElement + null guards in client scripts (index, peaks, admin/climbs, blog, about), typed D1.first() rows, narrowed filtered arrays, dropped the removed platformProxy adapter option, z from astro/zod, widened the seed generic, asserted the BGE embedding shape.
  • Tests (tests/, vitest.config.ts): vitest + 36 unit tests covering the extracted sync helpers (imported, not duplicated).
  • Lint (merge: lint): Biome dep + config + lint/lint:fix scripts, tuned to repo style. Not yet applied repo-wide.

Test Steps

  1. npm test → 36/36 pass
  2. npx astro check → 0 errors, 0 warnings (4 pre-existing .mjs hints remain)
  3. npm run build → completes
  4. Manual: hit /, /peaks (filter buttons), /about, a blog post — render with no console errors (verified locally after seeding D1)

Risks / Follow-ups

  • After merge, run npm run lint:fix for Biome's first repo-wide format pass (deliberately deferred to keep this diff reviewable).
  • notion_id backfill depends on migrations 0006/0007 being applied to remote D1.
  • 4 unused-var hints remain in scripts/migrate/*.mjs (unrelated tooling; left untouched).
  • astro check requires @astrojs/check (already installed locally); not added to deps here.

@github-actions
github-actions Bot temporarily deployed to preview June 4, 2026 05:53 Inactive
@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown

🧹 Preview cleaned up — PR merged!

The preview worker has been deleted.

@github-actions
github-actions Bot temporarily deployed to preview June 4, 2026 05:57 Inactive
kale-stew added 6 commits June 3, 2026 23:02
- add shared type definitions (src/lib/types.ts) for D1 entities
- add fetch-with-timeout utility with AbortController pattern
- add Zod schemas for API input validation
- integrate zValidator middleware into photos-api admin routes
- add structured logging (logSync) to cron.ts sync operations
- configure Notion client with 15s timeout
- add fetch timeouts for image downloads (10s)
- export CloudflareEnv from env.d.ts for type inference
- remove (env as any) casts throughout codebase
- use ClimbListItem type in climbs.astro for proper typing
store notion_id for climbs/peaks/gear (was silently null, breaking body
sync) and report accurate insert vs update counts. extract parsing helpers
into src/lib/notion-helpers.ts so the cron sync and unit tests share one
implementation, and fix parseAreaFallback to preserve internal hyphens
(e.g. Bridger-Teton). add vitest and unit tests covering the helpers.
0 errors / 0 warnings from astro check.

- pages/components: type DOM queries as HTMLElement, add null guards,
  type D1 .first() rows, narrow filtered arrays (index, peaks,
  admin/climbs, blog, about, ClimbTable).
- config/scripts: drop the removed platformProxy adapter option, import z
  from astro/zod, widen the seed generic, assert the BGE embedding shape.
- remove unused imports and vars (APIErrorCode, MAX_CUSTOM_WIDTH, mock params).
adds biome (dep, biome.json, lint/lint:fix scripts) tuned to the repo
style (single quotes, no semicolons, 2-space, 100 cols). not yet applied
repo-wide; run 'npm run lint:fix' after this lands.
@kale-stew
kale-stew merged commit b3e11fe into main Jun 4, 2026
1 check passed
@kale-stew
kale-stew deleted the refactor/codex branch June 4, 2026 06:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant