🚸 api: body-schema cleanup — drop redundant .optional().default()#2434
Conversation
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (8)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Coverage Report for API Unit Tests Coverage (./packages/api)
File CoverageNo changed files found. |
Coverage Report for Expo Unit Tests Coverage (./apps/expo)
File CoverageNo changed files found. |
There was a problem hiding this comment.
Pull request overview
Follow-up to #2433 that removes redundant .optional().default(N) patterns from API body schemas. These patterns cause Eden Treaty to type the field as required-with-default, forcing typed clients to supply them. By dropping the .default() and applying fallbacks inside the handlers (where not already done), the fields become truly optional at the type level while preserving runtime behavior.
Changes:
- Drop
.default(...)frommatchLimit,isPublic,consumable,worn,quantity,isAppTemplate,hazards,waterCrossings,photosbody fields across four schemas. - Add
?? falsefallbacks inpackscreate andpackTemplatescreate-item handlers where they were previously missing. - Other handlers already had
?? [],|| false,|| 1, or use parameter defaults at the service layer.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
packages/api/src/schemas/imageDetection.ts |
Drop default on matchLimit; service default = 3 still applies. |
packages/api/src/schemas/packs.ts |
Drop defaults on isPublic, consumable, worn. |
packages/api/src/schemas/packTemplates.ts |
Drop defaults on quantity, consumable, worn, isAppTemplate. |
packages/api/src/routes/trailConditions/reports.ts |
Drop defaults on hazards, waterCrossings, photos; handler already had fallbacks. |
packages/api/src/routes/packs/index.ts |
Add isPublic: data.isPublic ?? false fallback for the dropped schema default. |
packages/api/src/routes/packTemplates/index.ts |
Add ?? false fallbacks for consumable/worn in the create-item handler. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Eden Treaty types `.optional().default(N)` as required-with-default, forcing typed clients to pass these fields. Same UX problem T1 fixed for query schemas in PR #2433; same treatment now for body schemas. schemas/imageDetection: matchLimit (handler uses service default = 3) schemas/packs: isPublic (handler now `?? false`), consumable / worn on CreatePackItemRequestSchema (handler already used `data.foo || false`) schemas/packTemplates: quantity, consumable, worn on CreatePackTemplateItemRequestSchema (handler now applies `?? false` for consumable/worn; quantity already had `|| 1`); isAppTemplate on GenerateFromOnlineContentRequestSchema (handler already uses `isAppTemplate ?? true`) routes/trailConditions/reports: hazards, waterCrossings, photos — handler already uses `?? []` / `?? 0` `localCreatedAt` / `localUpdatedAt` defaults stay required (offline-first sync semantics). Follow-up to PR #2433. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
f1f1159 to
178c1f1
Compare
Resolves conflict in packages/api/src/routes/trailConditions/reports.ts caused by #2414 schema refactor (schemas moved to @packrat/schemas). Re-applies #2434's .optional().default() thickening to the new schema location (packages/schemas/src/trailConditions.ts). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
packrat-admin | ecc2845 | Commit Preview URL Branch Preview URL |
May 17 2026, 05:48 AM |
CF Pages' default bun didn't interpolate $PACKRAT_NATIVEWIND_UI_GITHUB_TOKEN in bunfig.toml scopes, causing a 403 on @packrat-ai/nativewindui during the preinstall. Pinning bun to a version that supports env-var interpolation. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Summary
Follow-up to #2433 (MCP + CLI Eden Treaty migration). T1 in that PR fixed the
same UX problem on query schemas; this surgical PR completes the same
treatment for body schemas.
.optional().default(N)causes Eden Treaty to type the field asrequired-with-default, forcing every typed client to pass it. Dropping the
.default(N)and applying the fallback inside the handler restores genuineoptionality at the type level without changing the at-rest validation behavior
(handlers were already doing the right thing in most cases).
Changes
schemas/imageDetection.tsmatchLimitmatchLimit: number = 3defaultschemas/packs.ts(CreatePackRequestSchema)isPublic?? falseinroutes/packs/index.tsschemas/packs.ts(CreatePackItemRequestSchema)consumable,worn|| falseschemas/packTemplates.ts(CreatePackTemplateItemRequestSchema)quantity,consumable,worn?? falsefor consumable/worn; quantity already had|| 1schemas/packTemplates.ts(GenerateFromOnlineContentRequestSchema)isAppTemplateisAppTemplate ?? trueroutes/trailConditions/reports.ts(CreateReportRequestSchema)hazards,waterCrossings,photos?? []/?? 0localCreatedAt/localUpdatedAtdefaults stay required (offline-first syncsemantics).
Notes on the original two-task scope
The original follow-up list also included deleting dead
shortIdhelpers frompackages/cli/src/api/ids.tsandpackages/mcp/src/client.ts. On the branchthis PR is built from (
main),packages/cli/src/api/does not exist andneither
shortIdnornowIsoappears anywhere inpackages/cliorpackages/mcp(rg "shortId|nowIso" packages/cli/src packages/mcp/srcreturnsno matches). Those helpers live on the still-unmerged
worktree-mcp-cli-edenbranch that powers #2433 — deletion is best done as part of merging that PR.
So this PR ships Task A only.
Test plan
bunx biome checkbun check:casts:strictbun scripts/lint/no-raw-typeof.tsbun scripts/lint/no-raw-regex.tsmatchLimit,isPublic,consumable,worn,quantity,isAppTemplate,hazards,waterCrossings, orphotoson POST bodies.Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com