Skip to content

Feature Request: Generate enums into a separate enums.ts file in ZenStack CLI #2345

@motopods

Description

@motopods

Feature Request: Generate enums into a separate enums.ts file in ZenStack CLI

Currently, ZenStack CLI generates both model types and enum types in the same file (e.g. models.ts). When importing enum value objects from this file, it can cause unexpected bundling behavior in frontend builds.

For example:

import {
  type ModelResult as $ModelResult,
  type TypeDefResult as $TypeDefResult,
} from '@zenstackhq/orm'
import { schema as $schema, type SchemaType as $Schema } from './schema-lite'
export type Order = $ModelResult<$Schema, 'Order'>
export const OrderType = $schema.enums.OrderType.values
export type OrderType = (typeof OrderType)[keyof typeof OrderType]

And then importing it in client code:

import { OrderType } from './zenstack/models'

During Vite bundling, this incorrectly pulls in server-side dependencies from @zenstackhq/orm, including kysely and pg, into the client bundle.

This results in warnings such as:

[plugin rolldown:vite-resolve] Module "util" has been externalized for browser compatibility, 
imported by "/node_modules/.bun/pg@8.18.0+32ccf17b773ffb11/node_modules/pg/lib/utils.js".
See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility

Proposed improvement

Add an option (or change default behavior) in zenstack cli generate to output enums into a separate file such as:

zenstack/
  models.ts
  enums.ts

This would allow frontend projects to safely import enum values/types without pulling in server-only ORM dependencies.

Benefits

  • Prevents accidental bundling of backend-only libraries in client builds
  • Improves tree-shaking and frontend compatibility
  • Makes enum usage cleaner in browser environments

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions