zenstackhq / zenstack

Fullstack TypeScript toolkit that enhances Prisma ORM with flexible Authorization layer for RBAC/ABAC/PBAC/ReBAC, offering auto-generated type-safe APIs and frontend hooks.
https://zenstack.dev
MIT License
2.07k stars 88 forks source link

[Feature Request] Auto-Clear Generated Hooks Directory in Tanstack-Query Plugin #1220

Closed iamfj closed 6 months ago

iamfj commented 6 months ago

Is your feature request related to a problem? Please describe. When working with the tanstack-query plugin for Zenstack, which generates hooks from the Zenstack schema, I've encountered a recurring issue. Each time the schema is updated and hooks are regenerated, the old, now-defunct hooks remain in the directory. This has led to situations where the stale hooks, which are incompatible with the updated schema due to removed or altered tables, are mistakenly used. The persistence of outdated hooks can cause confusion and errors, as they no longer reflect the current state of the schema.

Describe the solution you'd like I propose that the tanstack-query plugin should automatically clear the directory where the hooks are generated before each regeneration process. This feature would ensure that only the most current, schema-compatible hooks are present in the directory at any time, eliminating the risk of accidentally using outdated hooks. By integrating this functionality directly into Zenstack, developers would no longer need to manually clear the directory or implement custom workarounds, thereby streamlining the development process and reducing potential errors.

Describe alternatives you've considered As a temporary solution, I've employed the rimraf package to manually delete the hooks directory before every execution of the zenstack generate command. While this workaround effectively addresses the issue by ensuring that the directory is cleared before hook regeneration, it introduces additional steps into the development workflow and relies on developers remembering to execute this step. Incorporating the directory clearing process as a built-in feature of the tanstack-query plugin would automate this task and enhance usability.

Additional context Incorporating this feature would significantly improve the developer experience when using the tanstack-query plugin for Zenstack by ensuring that the generated hooks are always up-to-date with the latest schema. This change would mitigate the risk of errors caused by outdated hooks and streamline the development process, making it more efficient and error-resistant.

ymc9 commented 6 months ago

Thanks for filing this, and I agree it should be the desired behavior. I'm marking it to be fixed in V2 since it's not blocking.

ymc9 commented 6 months ago

Fixed in 2.0.0-beta.8

iamfj commented 6 months ago

Thanks!