-
-
Notifications
You must be signed in to change notification settings - Fork 12
feat(schema): generate enum type helpers #91
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
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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
Documentation and Community
|
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.
Pull Request Overview
This PR updates enum handling to generate enum helpers (const alias and union type) instead of native TypeScript enums, and adapts samples and tests to use the new pattern.
- In the SDK generator, emit
export const Enum = schema.enums.Enumplus a correspondingexport type Enum = …helper and adjust the documentation generator. - Update the sample blog models and runtime typing tests to import and use the new enum helpers.
- Extend the test schema and zmodel to define a
Roleenum and add arolefield to theUsermodel.
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 |
|---|---|
| samples/blog/zenstack/models.ts | Replace native enum Role with generated const Role alias and type Role union helper |
| packages/sdk/src/ts-schema-generator.ts | Change enum emission to variable statement + type alias, update generateDocs signature |
| packages/runtime/test/typing/verify-typing.ts | Add enums() function and tests to verify the new Role helper types |
| packages/runtime/test/typing/typing-test.zmodel | Define enum Role and add role field to the User model |
| packages/runtime/test/typing/schema.ts | Add role property under User and top‐level enums.Role definition |
| packages/runtime/test/typing/models.ts | Export Role as const and as a union type in the test models file |
Comments suppressed due to low confidence (2)
samples/blog/zenstack/models.ts:29
- [nitpick] The JSDoc for "User roles" applies to the
type Rolebut not to theconst Role. Moving or duplicating this comment above theconst Role = schema.enums.Role;declaration would improve IDE hover documentation.
/**
packages/sdk/src/ts-schema-generator.ts:1024
- The commented example for generating native enums is now outdated. Consider removing or updating that block to clearly show the new
export const Enum = schema.enums.Enumpattern.
// generate: export const Enum = schema.enums.Enum;
No description provided.