-
-
Notifications
You must be signed in to change notification settings - Fork 38
blog: update json type guide #384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughThe pull request introduces a new feature in ZenStack that enables strongly typed JSON fields within ZModel schemas. It includes the addition of a Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant ZenStack
participant PrismaClient
participant Zod
User->>ZenStack: Define ZModel with strongly typed JSON
ZenStack->>PrismaClient: Transform typed JSON to Prisma Json
PrismaClient->>User: Return typed data
User->>Zod: Validate input data
Zod-->>User: Return validation results
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (3)
blog/json-typing/index.md (3)
Line range hint
82-108: Add version and database compatibility informationThe example effectively demonstrates the feature but should mention version requirements and database compatibility constraints upfront before showing the code.
Consider adding a note before the code example:
> Note: This feature requires ZenStack version X.Y.Z or later and is currently only supported with PostgreSQL databases.🧰 Tools
🪛 LanguageTool
[style] ~16-~16: You have already used this phrasing in nearby sentences. Consider replacing it to add variety to your writing.
Context: ...You may have some tiny objects that you want to attach to the main entities (e.g., meta...(REP_WANT_TO_VB)
Line range hint
134-143: Improve error message formatting and explanationThe error message example could be more readable with proper formatting and structure explanation.
Consider formatting the error message like this:
-```plain +```typescript +// The error object has this structure: Error calling enhanced Prisma method `image.create`: denied by policy: image entities failed 'create' check, -input failed validation: Validation error: Number must be less than 10000 at "metadata.height" +input failed validation: Validation error: + Number must be less than 10000 at "metadata.height"<details> <summary>🧰 Tools</summary> <details> <summary>🪛 LanguageTool</summary> [style] ~16-~16: You have already used this phrasing in nearby sentences. Consider replacing it to add variety to your writing. Context: ...You may have some tiny objects that you want to attach to the main entities (e.g., meta... (REP_WANT_TO_VB) </details> </details> --- `169-169`: **Enhance the call to action** The call to action could be more engaging and polite. Consider revising to: ```diff -Let us know by leaving a comment below. You can also learn more about this feature in the [official guide](https://zenstack.dev/docs/guides/typing-json). +Please let us know your thoughts by leaving a comment below! You can also learn more about this feature in the [official guide](https://zenstack.dev/docs/guides/typing-json).🧰 Tools
🪛 LanguageTool
[style] ~169-~169: This expression usually appears with a “please” in front of it.
Context: ...it looks the same as relation filters)? Let us know by leaving a comment below. You can als...(INSERT_PLEASE)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
blog/json-typing/index.md(2 hunks)
🧰 Additional context used
🪛 LanguageTool
blog/json-typing/index.md
[style] ~169-~169: This expression usually appears with a “please” in front of it.
Context: ...it looks the same as relation filters)? Let us know by leaving a comment below. You can als...
(INSERT_PLEASE)
🔇 Additional comments (1)
blog/json-typing/index.md (1)
Line range hint 32-44: Clarify type declaration context and add runtime safety warning
The example shows a type declaration without clearly indicating where it should be defined. Additionally, the type casting could be unsafe at runtime if the JSON data doesn't match the expected shape.
Consider:
- Adding a comment indicating where the type should be defined
- Adding a warning about runtime type safety
- Showing how to safely validate the type cast
+// Define your types in a separate .ts file or above your usage
type Metadata {
width: number
height: number
format: string
}
const image = await prisma.image.findFirstOrThrow();
-// an explicit cast into the desired type
+// Warning: Type casting doesn't guarantee runtime safety
const metadata = image.metadata as Metadata;
+// Consider adding runtime validation here
console.log('Image dimensions:', metadata.width, 'by', metadata.height);🧰 Tools
🪛 LanguageTool
[style] ~16-~16: You have already used this phrasing in nearby sentences. Consider replacing it to add variety to your writing.
Context: ...You may have some tiny objects that you want to attach to the main entities (e.g., meta...
(REP_WANT_TO_VB)
Summary by CodeRabbit
New Features
zenstack generatecommand.Documentation