The generated schema previously used `as const` on entire model/enum/typeDef
objects, causing TypeScript to deeply infer literal types for all nested
properties. This is unnecessary for `attributes`, `default`, and `foreignKeyFor`
which are only used at runtime, not in CRUD type computations.
Changes:
- Add type assertions (`as readonly AttributeApplication[]`, `as FieldDefault`,
`as readonly string[]`) to prevent deep const inference on these properties
- Extract `FieldDefault` type alias from `FieldDef` for cleaner generated code
- Change `FieldHasDefault` to use key existence check (`'default' extends keyof`)
instead of value type check, enabling the `default` widening
- Conditionally import `AttributeApplication` and `FieldDefault` only when used
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
z.int().nonnegative() rejects Infinity. Use .or(z.literal(Infinity))
to accept both nonnegative integers and Infinity.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Introduces a new `$diagnostics()` method on ZenStackClient that returns
Zod schema cache statistics and slow query information, helping users
monitor and debug ORM performance.
- Add `diagnostics` option to `ClientOptions` with `slowQueryThresholdMs`
and `slowQueryMaxRecords` settings
- Track slow queries in `ZenStackQueryExecutor` when diagnostics is enabled
- Share slow query collection across derived clients (via $setAuth,
$setOptions, $use, transactions, etc.)
- Cap slow query records with an eviction policy that keeps the slowest
queries (default max: 100)
- Validate diagnostics config with Zod in ClientImpl constructor
- Add `Diagnostics`, `QueryInfo`, and `ZodCacheStats` types
- Add e2e tests covering all diagnostics features
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: Yiming Cao <ymc9@users.noreply.github.com>
- Fill now() default in evalGenerator so createdAt fields are populated
before policy checks, preventing DefaultInsertValueNode from being
treated as null during pre-create policy evaluation.
- Fix now() SQL function to produce ISO 8601 format matching each
dialect's DateTime storage format (SQLite: strftime, MySQL:
DATE_FORMAT with trimmed microseconds), ensuring correct comparisons
in policy expressions.
- Add e2e tests for now() in create, read, update, and delete policies.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Change DataType enum from TEXT/NUMBER to DataText/DataNumber
- Remove explicit dataType field from test as it's auto-set by delegate discriminator
- Fixes MySQL test failure: delegate discriminators must use model names
Co-authored-by: Yiming Cao <ymc9@users.noreply.github.com>
The test was failing on MySQL because the dataType enum field was required
but not provided when creating DataText records. MySQL is stricter about
enum validation than SQLite, causing 'Data truncated for column' errors.
Co-authored-by: Yiming Cao <ymc9@users.noreply.github.com>
Fields inherited via a mixin type on a delegate base model were not
getting their `originModel` set in the generated schema, causing the
ORM to include them in the wrong table's INSERT statement.
Introduces `getOwnedFields` and `getDelegateOriginModel` helpers in
`model-utils.ts` and uses them in both `ts-schema-generator` and
`prisma-schema-generator`, replacing the previous logic that only
checked `field.$container` directly.
Fixes#2351
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>