Skip to content

🚸 api: body-schema cleanup — drop redundant .optional().default()#2434

Merged
andrew-bierman merged 3 commits into
developmentfrom
worktree-agent-af46ed922554599df
May 17, 2026
Merged

🚸 api: body-schema cleanup — drop redundant .optional().default()#2434
andrew-bierman merged 3 commits into
developmentfrom
worktree-agent-af46ed922554599df

Conversation

@andrew-bierman
Copy link
Copy Markdown
Collaborator

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 as
required-with-default, forcing every typed client to pass it. Dropping the
.default(N) and applying the fallback inside the handler restores genuine
optionality at the type level without changing the at-rest validation behavior
(handlers were already doing the right thing in most cases).

Changes

File Field(s) Handler change
schemas/imageDetection.ts matchLimit none — service has matchLimit: number = 3 default
schemas/packs.ts (CreatePackRequestSchema) isPublic added ?? false in routes/packs/index.ts
schemas/packs.ts (CreatePackItemRequestSchema) consumable, worn none — handler already used || false
schemas/packTemplates.ts (CreatePackTemplateItemRequestSchema) quantity, consumable, worn added ?? false for consumable/worn; quantity already had || 1
schemas/packTemplates.ts (GenerateFromOnlineContentRequestSchema) isAppTemplate none — handler already used isAppTemplate ?? true
routes/trailConditions/reports.ts (CreateReportRequestSchema) hazards, waterCrossings, photos none — handler already used ?? [] / ?? 0

localCreatedAt / localUpdatedAt defaults stay required (offline-first sync
semantics).

Notes on the original two-task scope

The original follow-up list also included deleting dead shortId helpers from
packages/cli/src/api/ids.ts and packages/mcp/src/client.ts. On the branch
this PR is built from (main), packages/cli/src/api/ does not exist and
neither shortId nor nowIso appears anywhere in packages/cli or
packages/mcp (rg "shortId|nowIso" packages/cli/src packages/mcp/src returns
no matches). Those helpers live on the still-unmerged worktree-mcp-cli-eden
branch that powers #2433 — deletion is best done as part of merging that PR.
So this PR ships Task A only.

Test plan

  • CI: bunx biome check
  • CI: bun check:casts:strict
  • CI: bun scripts/lint/no-raw-typeof.ts
  • CI: bun scripts/lint/no-raw-regex.ts
  • CI: api typecheck (skipped locally — has been slow in this monorepo)
  • Manual: regenerated Eden Treaty consumers should no longer require matchLimit, isPublic, consumable, worn, quantity, isAppTemplate, hazards, waterCrossings, or photos on POST bodies.
  • Manual: existing clients that DO pass those fields continue to work.

Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 16, 2026

Warning

Rate limit exceeded

@andrew-bierman has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 24 minutes and 43 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 1efeb03e-d76b-4e4d-a343-00a1937cc292

📥 Commits

Reviewing files that changed from the base of the PR and between e5a8f95 and a57a4ce.

📒 Files selected for processing (8)
  • .bun-version
  • package.json
  • packages/api/src/routes/packTemplates/index.ts
  • packages/api/src/routes/packs/index.ts
  • packages/schemas/src/imageDetection.ts
  • packages/schemas/src/packTemplates.ts
  • packages/schemas/src/packs.ts
  • packages/schemas/src/trailConditions.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch worktree-agent-af46ed922554599df

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 16, 2026

Coverage Report for API Unit Tests Coverage (./packages/api)

Status Category Percentage Covered / Total
🔵 Lines 70.11% 502 / 716
🔵 Statements 70.11% (🎯 65%) 502 / 716
🔵 Functions 92.68% 38 / 41
🔵 Branches 88.32% 227 / 257
File CoverageNo changed files found.
Generated in workflow #1318 for commit a57a4ce by the Vitest Coverage Report Action

@github-actions github-actions Bot added the api label May 16, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 16, 2026

Coverage Report for Expo Unit Tests Coverage (./apps/expo)

Status Category Percentage Covered / Total
🔵 Lines 82.76% 485 / 586
🔵 Statements 82.76% (🎯 75%) 485 / 586
🔵 Functions 92.59% 50 / 54
🔵 Branches 90.9% 170 / 187
File CoverageNo changed files found.
Generated in workflow #1318 for commit a57a4ce by the Vitest Coverage Report Action

@andrew-bierman andrew-bierman marked this pull request as ready for review May 16, 2026 22:49
Copilot AI review requested due to automatic review settings May 16, 2026 22:49
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(...) from matchLimit, isPublic, consumable, worn, quantity, isAppTemplate, hazards, waterCrossings, photos body fields across four schemas.
  • Add ?? false fallbacks in packs create and packTemplates create-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.

@andrew-bierman andrew-bierman changed the base branch from main to development May 17, 2026 00:23
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>
@andrew-bierman andrew-bierman force-pushed the worktree-agent-af46ed922554599df branch from f1f1159 to 178c1f1 Compare May 17, 2026 00:59
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>
@cloudflare-workers-and-pages
Copy link
Copy Markdown
Contributor

cloudflare-workers-and-pages Bot commented May 17, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

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

@cloudflare-workers-and-pages
Copy link
Copy Markdown
Contributor

Deploying packrat-landing with  Cloudflare Pages  Cloudflare Pages

Latest commit: ecc2845
Status:🚫  Build failed.

View logs

@cloudflare-workers-and-pages
Copy link
Copy Markdown
Contributor

Deploying packrat-guides with  Cloudflare Pages  Cloudflare Pages

Latest commit: ecc2845
Status:🚫  Build failed.

View logs

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>
@github-actions github-actions Bot added the dependencies Pull requests that update a dependency file label May 17, 2026
@andrew-bierman andrew-bierman merged commit 8aa9079 into development May 17, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api dependencies Pull requests that update a dependency file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants