Conversation
📝 WalkthroughWalkthroughThe TypeScript schema generator now extracts enum declarations into a separate Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 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: 2
🤖 Fix all issues with AI agents
In `@packages/sdk/src/ts-schema-generator.ts`:
- Around line 1423-1431: The enumStatements array created for enums.ts doesn't
get the autogenerated "DO NOT MODIFY" banner because generateBannerComments is
only applied to the models statements; update the flow to call
generateBannerComments(enumStatements) (same banner function used for models)
before the file emission so enums.ts receives the banner. Locate the
enumStatements construction (including generateSchemaImport) and ensure you call
generateBannerComments(enumStatements) in the same spot you apply it to the
models statements so enums.ts and any other enum output receive the standard
header.
- Around line 1504-1506: The else branch that calls
fs.unlinkSync(enumsOutputFile) can throw ENOENT when enums.ts was never created;
update the removal logic in ts-schema-generator.ts to either check existence
(using fs.existsSync on enumsOutputFile) before calling fs.unlinkSync or wrap
unlinkSync in a try/catch that ignores errors with code === 'ENOENT' and
rethrows others so only the "file not found" case is swallowed.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@packages/sdk/src/ts-schema-generator.ts`:
- Around line 1485-1510: The current check uses enumStatements.length which is
always >0 due to the initial schema import; change the guard to check the actual
enums collection instead (use enums.length > 0) so enums.ts is only written when
real enums exist, keep the existing logic that calls
generateBannerComments(enumStatements) and writes enumsOutputFile and the export
declaration (createExportDeclaration) when enums.length > 0, and move the
fs.existsSync/enumsOutputFile unlink cleanup into the else branch so stale
enumsOutputFile is removed when enums is empty; ensure any logic that builds
enumStatements (and references options.importWithFileExtension) remains
unchanged.
|
I guess refactor is a more accurate label rather than feat, but I can't change the PR title. |
|
Hi @sanny-io , given the findings in the original issue zenstackhq/zenstack#2345, I think we don't have an immediate need to have a separate file for enums anymore. What do you think? |
Enums are now generated to
enums.tsmodels.tsexports everything fromenums.tsto maintain backwards compatibility.Closes zenstackhq/zenstack#2345
Summary by CodeRabbit