doc: document @@delegateMap attribute#607
Conversation
… discriminator value Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reached
Your plan currently allows 1 review/hour. Refill in 52 minutes and 17 seconds. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more review capacity refills, 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 trial, open-source, and free plans. In all cases, review capacity refills continuously over time. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThis PR adds documentation for a new ChangesPolymorphic Model Discriminator Customization Documentation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
docs/orm/polymorphism.md (1)
73-100: ⚡ Quick winConsider clarifying that
@@delegateMaprelaxes the enum-value-must-match-model-name constraint.The example demonstrates that enum values (e.g.,
ASSET_KIND_VIDEO) don't need to match model names (e.g.,Video), but this isn't explicitly stated. In v2.x documentation, it was noted that "enum fields must match the concrete model names" when using@@delegate. Since@@delegateMapremoves this restriction, adding a brief note would help users understand the key benefit.📝 Suggested clarification
Add a note before or within the enum discriminator subsection:
When the discriminator field is an enum, pass an enum member to `@@delegateMap`. The member must come from the same enum as the discriminator field. Unlike the default behavior where enum values must match concrete model names, `@@delegateMap` allows you to use any enum value:🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@docs/orm/polymorphism.md` around lines 73 - 100, Add a short explicit note in the "Enum discriminator" section clarifying that @@delegateMap relaxes the enum-value-must-match-model-name constraint: mention that when using @@delegateMap you can map any enum member from the same enum (e.g., AssetKind) to a concrete model (e.g., Video, Image) even when the enum value (ASSET_KIND_VIDEO) does not equal the model name (Video), and place this sentence near the existing explanation that references @@delegateMap, AssetKind, Asset, Video, and Image.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/orm/polymorphism.md`:
- Around line 30-46: The discriminator section describing default behavior for
Content.type and the @@delegate usage is missing guidance on TypeScript
narrowing and validation rules; update the polymorphism.md discriminator
subsection to either (1) add concise instructions showing how to leverage the
discriminator (e.g., Content.type = "Video"/"Image") for TypeScript narrowing in
code examples and how to enforce/validate allowed discriminator values at model
boundaries, or (2) add a clear cross-reference/link to the dedicated “TypeScript
narrowing” and “validation rules” section; ensure you mention the concrete model
names (Video, Image), the base field (Content.type), and the
@@delegate/@@delegateMap usage so readers can find the relevant examples.
---
Nitpick comments:
In `@docs/orm/polymorphism.md`:
- Around line 73-100: Add a short explicit note in the "Enum discriminator"
section clarifying that @@delegateMap relaxes the
enum-value-must-match-model-name constraint: mention that when using
@@delegateMap you can map any enum member from the same enum (e.g., AssetKind)
to a concrete model (e.g., Video, Image) even when the enum value
(ASSET_KIND_VIDEO) does not equal the model name (Video), and place this
sentence near the existing explanation that references @@delegateMap, AssetKind,
Asset, Video, and Image.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 04493592-9fd5-4182-918a-451f19dfb2d6
📒 Files selected for processing (2)
docs/orm/polymorphism.mddocs/reference/zmodel/attribute.md
…elegateMap docs Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Summary
@@delegateMapattribute (introduced in zenstack v3.7.1 via zenstackhq/zenstack#2676) for customizing the discriminator value of polymorphic sub-models.docs/orm/polymorphism.mdcovering the default behavior, string-discriminator and enum-discriminator usage, TS narrowing, and validation rules. Marked<AvailableSince version="v3.7.1" />.@@delegateMapnext to@@delegateindocs/reference/zmodel/attribute.md.Test plan
pnpm startand verify the new section renders correctly on/docs/orm/polymorphism/docs/reference/zmodel/attributeand that the cross-link to the ORM section workspnpm buildcompletes without errors🤖 Generated with Claude Code
Summary by CodeRabbit
@@delegateMapattribute, explaining how to override default discriminator value mappings in delegate models.