Skip to content

blog: zenstack next chapter part 2 #441

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

Merged
merged 6 commits into from
Apr 11, 2025
Merged

blog: zenstack next chapter part 2 #441

merged 6 commits into from
Apr 11, 2025

Conversation

ymc9
Copy link
Member

@ymc9 ymc9 commented Apr 11, 2025

Summary by CodeRabbit

  • Documentation
    • Enhanced a blog article with a new link for improved navigation to related content.
    • Added a new blog post detailing ZenStack V3 enhancements, including a high-level CRUD API, computed fields, and a procedure construct for encapsulating business logic.
    • Updated the ZModel language syntax to recognize a new keyword, proc, for improved functionality.

Copy link

vercel bot commented Apr 11, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
zenstack-new-site ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 11, 2025 0:53am

Copy link
Contributor

coderabbitai bot commented Apr 11, 2025

Walkthrough

This pull request makes two main updates. First, it modifies a reference in the existing blog post (blog/next-chapter-1/index.md) by updating a list item's text to include a hyperlink pointing to the next chapter. Second, it introduces a new blog post (blog/next-chapter-2/index.md) that details ZenStack V3 features, including a high-level CRUD API, computed fields via the new @computed attribute, and a procedure construct to encapsulate business logic.

Changes

File(s) Change Summary
blog/next-chapter-1/index.md Updated text in list point 3 to embed a hyperlink pointing to ../next-chapter-2/index.md.
blog/next-chapter-2/index.md Added a new file introducing ZenStack V3 features: high-level CRUD API integration, computed fields (@computed), and procedure constructs.
src/lib/prism-zmodel.js Updated regular expression for keyword property in Prism.languages.zmodel to include the proc keyword.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant ORM as ZenStack V3 ORM
    participant Kysely as Kysely Query Builder

    Developer->>+ORM: Initiate CRUD or procedure call
    ORM->>+Kysely: Build query with computed fields
    Kysely-->>-ORM: Return computed results
    ORM-->>-Developer: Return complete response
Loading

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

🧹 Nitpick comments (4)
blog/next-chapter-2/index.md (4)

51-53: Refine Computed Fields Description

In the sentence describing computed fields—specifically, "like adding a postCount field to return the number of posts a user has"—consider inserting an article for improved clarity. For example:

- ...like adding a `postCount` field to return the number of posts a user has
+ ...like adding a `postCount` field to return the number of posts that a user has
🧰 Tools
🪛 LanguageTool

[uncategorized] ~53-~53: You might be missing the article “a” here.
Context: ...mbining firstName and lastName into full name, but you can't do anything that ne...

(AI_EN_LECTOR_MISSING_DETERMINER_A)


84-92: Clear Example Using Computed Fields in Queries

The sample demonstrating filter and sorting on the computed field is both clear and practical.
Additionally, consider rephrasing "returned in the result" to "included in the result" for smoother reading:

- ...the `postCount` field will be returned in the result
+ ...the `postCount` field will be included in the result
🧰 Tools
🪛 LanguageTool

[grammar] ~84-~84: The usual collocation for “returned” is “to”, not “in”.
Context: ...rmodel, thepostCount` field will be returned in the result. You can also use it to filt...

(RETURN_IN_THE)


125-140: Well-Documented Procedure Implementation

The example showing the procedure implementation inside the ZenStackClient configuration is practical. It also illustrates real-world actions like sending a welcome email. Consider adding error handling for production readiness.


180-187: Conclusion Section – Enhance Tone with Stronger Adjective

The conclusion effectively outlines future directions for ZenStack v3. To further strengthen your wording, consider replacing "deep customizations" with a term like "profound customizations":

- deep customizations
+ profound customizations
🧰 Tools
🪛 LanguageTool

[style] ~186-~186: Consider an alternative adjective to strengthen your wording.
Context: ...ew plugin system will allow you to make deep customizations to ZenStack in a clean a...

(DEEP_PROFOUND)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 308ce1b and 2d36a43.

⛔ Files ignored due to path filters (1)
  • blog/next-chapter-2/cover.png is excluded by !**/*.png, !**/*.png
📒 Files selected for processing (2)
  • blog/next-chapter-1/index.md (1 hunks)
  • blog/next-chapter-2/index.md (1 hunks)
🧰 Additional context used
🪛 LanguageTool
blog/next-chapter-2/index.md

[uncategorized] ~53-~53: You might be missing the article “a” here.
Context: ...mbining firstName and lastName into full name, but you can't do anything that ne...

(AI_EN_LECTOR_MISSING_DETERMINER_A)


[grammar] ~84-~84: The usual collocation for “returned” is “to”, not “in”.
Context: ...rmodel, thepostCount` field will be returned in the result. You can also use it to filt...

(RETURN_IN_THE)


[style] ~186-~186: Consider an alternative adjective to strengthen your wording.
Context: ...ew plugin system will allow you to make deep customizations to ZenStack in a clean a...

(DEEP_PROFOUND)

🔇 Additional comments (11)
blog/next-chapter-1/index.md (1)

126-127: Updated Hyperlink for Seamless Navigation

The list item now includes a hyperlink to the next chapter (../next-chapter-2/index.md), which greatly improves navigability between related posts. Please verify that the relative path is correct for your deployment.

blog/next-chapter-2/index.md (10)

1-8: Frontmatter Metadata is Clear and Consistent

The metadata block (title, description, tags, authors, image, date) is well defined and aligns with the post’s subject on ZenStack V3. Ensure that the publication date and other metadata continue to match your timeline.


14-15: Clear Reference to the Previous Post

The introductory sentence correctly links to the previous post (../next-chapter-1/index.md), helping readers navigate through the series with ease.


22-31: Effective Code Snippet for CRUD and Query Builder Demonstration

The embedded TypeScript example neatly illustrates both the CRUD API usage and the Kysely query builder approach. The clarity of these examples will help readers grasp the underlying concepts.


32-35: Seamless Blending of Query Approaches

The explanation following the code snippet effectively highlights how the query builder can complement standard CRUD operations. No changes are required here.


51-57: Well-Outlined Computed Fields Feature

The "Computed Fields" section clearly describes the limitations of previous versions and introduces the new @computed attribute for ZenStack v3. The accompanying schema snippet is informative.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~53-~53: You might be missing the article “a” here.
Context: ...mbining firstName and lastName into full name, but you can't do anything that ne...

(AI_EN_LECTOR_MISSING_DETERMINER_A)


57-82: Solid Implementation of Computed Fields Callback

The provided ZenStackClient initialization with the computed callback is well constructed and leverages Kysely’s capabilities effectively. This example should help users understand how to implement dynamic computed fields.


105-109: Comprehensive Introduction to Custom Procedures

The introduction to the "Custom Procedures" section is clear and sets the stage for the detailed examples that follow. The rationale for encapsulating business logic is well stated.


110-124: Clear Schema Example for Procedure Declaration

The Prisma schema snippet that declares a procedure (e.g., proc signUp) is concise and clearly demonstrates how procedures are defined within ZenStack v3.


142-146: Illustrative Procedure Invocation

The snippet demonstrating how to call the custom procedure is succinct and clearly shows the integration of type-safe procedure calls.


147-178: Effective Frontend Integration Example

The example integrating TanStack query hooks with the custom procedures showcases a smooth frontend implementation. The snippet is clear and should be very useful for developers.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

🧹 Nitpick comments (2)
blog/next-chapter-2/index.md (2)

53-53: Minor grammar issue in explanation.

There's a missing article before "full name" in this sentence.

- It's good for simple computations like combining `firstName` and `lastName` into full name, but you can't do anything that needs database-side computation
+ It's good for simple computations like combining `firstName` and `lastName` into a full name, but you can't do anything that needs database-side computation
🧰 Tools
🪛 LanguageTool

[uncategorized] ~53-~53: Possible missing article found.
Context: ...mbining firstName and lastName into full name, but you can't do anything that ne...

(AI_HYDRA_LEO_MISSING_A)


84-84: Consider revising phrasing for clarity.

The phrase "returned in the result" could be improved for better readability.

- Then, when you query the `User` model, the `postCount` field will be returned in the result.
+ Then, when you query the `User` model, the `postCount` field will be included in the result.
🧰 Tools
🪛 LanguageTool

[grammar] ~84-~84: The usual collocation for “returned” is “to”, not “in”.
Context: ...rmodel, thepostCount` field will be returned in the result. You can also use it to filt...

(RETURN_IN_THE)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2d36a43 and 19eda08.

📒 Files selected for processing (2)
  • blog/next-chapter-2/index.md (1 hunks)
  • src/lib/prism-zmodel.js (1 hunks)
🧰 Additional context used
🪛 LanguageTool
blog/next-chapter-2/index.md

[uncategorized] ~53-~53: Possible missing article found.
Context: ...mbining firstName and lastName into full name, but you can't do anything that ne...

(AI_HYDRA_LEO_MISSING_A)


[grammar] ~84-~84: The usual collocation for “returned” is “to”, not “in”.
Context: ...rmodel, thepostCount` field will be returned in the result. You can also use it to filt...

(RETURN_IN_THE)


[style] ~186-~186: Consider an alternative adjective to strengthen your wording.
Context: ...ew plugin system will allow you to make deep customizations to ZenStack in a clean a...

(DEEP_PROFOUND)

🔇 Additional comments (7)
src/lib/prism-zmodel.js (1)

2-2: Correctly added new proc keyword to syntax highlighting.

The addition of the proc keyword to the ZModel syntax highlighter aligns perfectly with the introduction of the new procedure construct feature in ZenStack V3 detailed in the blog post. This ensures proper syntax highlighting for code examples using the new feature.

blog/next-chapter-2/index.md (6)

1-8: LGTM: Blog post frontmatter looks good.

The metadata is complete with all necessary fields including title, description, tags, author, image, and date. The future date (2025-04-10) is appropriate for content that describes upcoming features.


14-14: Excellent cross-referencing to previous content.

Good job linking to the previous post to provide context and continuity in the blog series about ZenStack V3.


20-50: Well-structured explanation of dual API approach.

The explanation of how ZenStack V3 provides both high-level CRUD and low-level query builder APIs is clear and comprehensive. The code examples effectively demonstrate the different approaches and how they can be combined.


51-104: Comprehensive explanation of computed fields feature.

The explanation of the new computed fields feature is thorough and includes all key aspects:

  1. Problem statement and motivation
  2. Syntax for defining computed fields in ZModel
  3. Implementation details using Kysely's expression builder
  4. Usage examples showing filtering and sorting
  5. Integration with access policies
  6. Benefits for tooling ecosystem

This provides readers with a clear understanding of both the what and the how of this powerful new feature.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~53-~53: Possible missing article found.
Context: ...mbining firstName and lastName into full name, but you can't do anything that ne...

(AI_HYDRA_LEO_MISSING_A)


[grammar] ~84-~84: The usual collocation for “returned” is “to”, not “in”.
Context: ...rmodel, thepostCount` field will be returned in the result. You can also use it to filt...

(RETURN_IN_THE)


105-181: Well-documented custom procedures feature.

The explanation of the new proc construct is clear and comprehensive, covering:

  1. Introduction and motivation
  2. Syntax for defining procedures in ZModel
  3. Implementation approach
  4. Usage examples including frontend integration
  5. Integration with access policies
  6. Benefits for the ecosystem

The code examples effectively demonstrate how to define, implement, and use procedures, making this complex feature accessible to readers.


182-186: Strong conclusion with forward-looking element.

The conclusion effectively summarizes the key points about ZenStack V3's extensibility improvements and sets up anticipation for the next post about the plugin system. This maintains reader engagement with the series.

🧰 Tools
🪛 LanguageTool

[style] ~186-~186: Consider an alternative adjective to strengthen your wording.
Context: ...ew plugin system will allow you to make deep customizations to ZenStack in a clean a...

(DEEP_PROFOUND)

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

🧹 Nitpick comments (4)
blog/next-chapter-2/index.md (4)

84-84: Grammatical Refinement Suggestion

The sentence on line 84 could be phrased more naturally. Consider changing:

-Then, when you query the `User` model, the `postCount` field will be returned in the result.
+Then, when you query the `User` model, the `postCount` field will be included in the result.

This small change improves the flow of the sentence.

🧰 Tools
🪛 LanguageTool

[grammar] ~84-~84: The usual collocation for “returned” is “to”, not “in”.
Context: ...rmodel, thepostCount` field will be returned in the result. You can also use it to filt...

(RETURN_IN_THE)


126-139: Procedure Implementation: Verify External Function Availability

The TS code snippet implementing the custom procedure is clear; however, note that the function sendWelcomeEmail is used without an import or definition. Ensure that this function is defined or imported in the actual codebase to avoid runtime issues.


158-178: Front-End Integration Example is Effective

The React snippet using TanStack query hooks offers a clear example of integrating the custom procedures into a frontend component.
Optional Suggestion: In typical React form handling, it is common to call event.preventDefault() within the submission handler to avoid unintended page reloads. If this example is intended for a real-world scenario, consider updating handleSubmit as follows:

-const handleSubmit = async (data) => {
-  await signUp(data);
-};
+const handleSubmit = async (event) => {
+  event.preventDefault(); // Prevent default form submission behavior
+  // Extract form data as needed (e.g., using FormData or a state management hook)
+  const data = /* your form data extraction logic */;
+  await signUp(data);
+};

This change would make the snippet more robust for production use.


182-186: Conclusion Section: Consider a Stronger Descriptor

The conclusion is well written. However, on line 186, the phrase “deep customizations” might be enhanced with a stronger adjective for greater impact. For instance, consider “profound customizations” or “comprehensive customizations” to better convey the capability.

🧰 Tools
🪛 LanguageTool

[style] ~186-~186: Consider an alternative adjective to strengthen your wording.
Context: ...ew plugin system will allow you to make deep customizations to ZenStack in a clean a...

(DEEP_PROFOUND)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 19eda08 and 2852d1c.

⛔ Files ignored due to path filters (1)
  • blog/next-chapter-1/cover.png is excluded by !**/*.png, !**/*.png
📒 Files selected for processing (1)
  • blog/next-chapter-2/index.md (1 hunks)
🧰 Additional context used
🪛 LanguageTool
blog/next-chapter-2/index.md

[grammar] ~84-~84: The usual collocation for “returned” is “to”, not “in”.
Context: ...rmodel, thepostCount` field will be returned in the result. You can also use it to filt...

(RETURN_IN_THE)


[style] ~186-~186: Consider an alternative adjective to strengthen your wording.
Context: ...ew plugin system will allow you to make deep customizations to ZenStack in a clean a...

(DEEP_PROFOUND)

🔇 Additional comments (11)
blog/next-chapter-2/index.md (11)

1-8: Front Matter Metadata is Clear and Well-Formatted

The metadata block clearly defines the title, description, tags, authors, image path, and date. Everything appears to be in order and consistent with standard front matter for a blog post.


10-17: Introduction Section is Clear

The introductory section, including the main heading, cover image, and link to the previous post, establishes context effectively. The relative paths (e.g., for the cover image and the previous post) are correctly applied.


18-31: CRUD and Query Builder Code Example is Well-Demonstrated

The code snippet detailing both the CRUD API and the Kysely-backed query builder API is clear and concise. It effectively contrasts the two approaches.


33-35: Explanation of API Inference is Informative

The text that explains how both APIs are automatically inferred from the ZModel schema is clear and adds value to the reader’s understanding.


36-45: Mixed Query Example is Clear and Practical

The example combining the CRUD API with a query builder expression demonstrates practical usage. The code is legible and follows a logical structure.


51-64: Computed Fields Section is Well-Presented

The “Computed Fields” section—including both the descriptive text and the zmodel snippet defining a computed field—is well structured.


67-82: Implementation of Computed Fields is Clear

The provided TS configuration for the ZenStackClient with a custom computed field is correctly implemented and clearly shows how to integrate Kysely’s expression builder.


94-101: Access Policy Snippet is Consistent

The access policy example using a ZModel snippet to deny deletion based on postCount is concise and clearly illustrates the concept.


107-123: Custom Procedures Declaration is Clear

The ZModel snippet defining the proc signUp procedure along with the SignUpInput type is straightforward and well documented.


142-146: Procedure Call Example is Clear

The example showing how to call the custom procedure with client.$procs.signUp is practical and well demonstrated.


148-156: Endpoint Exposure Example is Well-Documented

The snippet demonstrating how the custom procedure can be exposed as an HTTP endpoint is clear and provides a useful reference for developers integrating with the API.

@ymc9 ymc9 merged commit 9aed6b7 into main Apr 11, 2025
3 checks passed
@ymc9 ymc9 deleted the blog/next-chapter-2 branch April 11, 2025 00:59
@coderabbitai coderabbitai bot mentioned this pull request May 24, 2025
@coderabbitai coderabbitai bot mentioned this pull request Aug 3, 2025
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