Commit graph

613 commits

Author SHA1 Message Date
copilot-swe-agent[bot]
417829388c Fix: Disallow include for models without relation fields (SelectIncludeOmit)
Co-authored-by: jiashengguo <16688722+jiashengguo@users.noreply.github.com>
2026-03-17 05:25:01 +00:00
Eugen Istoc
12aeb7bd18
feat(orm): add result plugin extension point (#2442)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-16 15:33:50 -07:00
Yiming Cao
49395f7280
perf(orm): avoid unnecessary pre-mutation read and transactions (#2484) 2026-03-14 12:18:11 -07:00
ymc9
23c86ad344 update test 2026-03-13 10:23:12 -07:00
Yiming Cao
f85711a8a4
refactor(schema): widen types for attributes, default, and foreignKeyFor (#2482) 2026-03-12 22:51:31 -07:00
ymc9
14b55e32b7 add startedAt field to query info 2026-03-12 21:31:37 -07:00
ymc9
d25c934afe fix test 2026-03-12 20:02:42 -07:00
ymc9
1ba4e54066 refactor(schema): widen types for attributes, default, and foreignKeyFor in generated schema
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>
2026-03-12 19:51:43 -07:00
ymc9
de4499ff4c Merge remote-tracking branch 'origin/dev' into feat/diagnostics-property 2026-03-12 19:13:46 -07:00
ymc9
eef5fd64cb improve test 2026-03-12 19:09:37 -07:00
ymc9
24089deb7c update 2026-03-12 19:01:24 -07:00
ymc9
ae407ac040 feat(orm): add $diagnostics() method for cache stats and slow query tracking
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>
2026-03-12 17:16:57 -07:00
Yiming Cao
bf6c9a4f5a
refactor(orm): move validateInput logic into InputValidator (#2480)
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>
2026-03-12 16:46:57 -07:00
github-actions[bot]
2c32dc329e
[CI] Bump version 3.4.6 (#2477)
Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
2026-03-11 11:40:16 -07:00
Yiming Cao
31776a890a
fix(orm): use IS operator for null comparisons in filters (#2475)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 10:57:21 -07:00
ymc9
930d9965ac fix(policy): support now() default value in access policy evaluation
- 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>
2026-03-08 23:11:23 -07:00
Pavel Kudinov
20832441c7
fix(policy): handle DefaultInsertValueNode in createManyAndReturn (#2461)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 16:06:28 -08:00
Yiming Cao
00c53d7fed
fix(sdk): correctly handle mixin fields for delegate model inheritance (#2456) 2026-03-07 10:04:18 -08:00
claude[bot]
956a64ddbe fix(test): correct delegate discriminator enum values to match model names
- 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>
2026-03-07 17:30:46 +00:00
claude[bot]
ffa17203f3 fix(test): add missing dataType field in issue-2351 regression test
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>
2026-03-07 17:14:26 +00:00
github-actions[bot]
bd2b111b8e
[CI] Bump version 3.4.5 (#2457)
Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
2026-03-06 22:26:46 -08:00
ymc9
4a99088bce fix(sdk): correctly handle mixin fields for delegate model inheritance
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>
2026-03-06 22:25:10 -08:00
Yiming Cao
158996c11e
perf(orm): use EXISTS instead of COUNT subquery for some/none/every relation filters (#2455)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-06 20:59:52 -08:00
Pavel Kudinov
8208900e09
fix(orm): fallback to compact temp aliases for overlong names (#2425)
Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
2026-03-05 22:04:58 -08:00
Yiming Cao
75d77defe1
fix(orm): handle self-referential relations in delegate models during schema push (#2449)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-04 19:16:58 -08:00
github-actions[bot]
07586f24cf
[CI] Bump version 3.4.4 (#2450)
Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
2026-03-04 18:48:24 -08:00
Yiming Cao
3c181f6832
fix(cli): report error when plugin module cannot be resolved (#2447)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-04 18:14:00 -08:00
github-actions[bot]
518cbb7ddf
[CI] Bump version 3.4.3 (#2436)
Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
2026-03-03 09:34:03 -08:00
Yiming Cao
7e908f2c52
fix(zod): use named argument lookup for @length validation (#2434)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-02 10:32:11 -08:00
github-actions[bot]
f58550e262
[CI] Bump version 3.4.2 (#2430)
Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
2026-03-01 20:26:23 -08:00
github-actions[bot]
3336505ed6
[CI] Bump version 3.4.1 (#2422)
Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
2026-02-27 19:37:57 -08:00
Yiming Cao
4b42ed9925
fix(orm): disallow create/update on computed fields and delegate discriminator fields (#2419) 2026-02-27 17:54:09 -08:00
Copilot
7c83f7c995
Fix order-dependent assertions in slicing E2E tests (#2416)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
2026-02-27 11:36:31 -08:00
Copilot
e5e452cf0a
Fix: disconnect correct client instance in zod test finally block (#2415)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
2026-02-27 11:36:17 -08:00
Yiming Cao
75bc4a1937
fix(policy): wrong table alias used when injecting for field policies (#2413) 2026-02-26 21:02:36 -05:00
github-actions[bot]
2da0c214dc
[CI] Bump version 3.4.0 (#2408)
Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
2026-02-25 22:40:51 -05:00
Yiming Cao
ca8f43721b
fix(orm): use compact alias names when transforming ORM queries to Kysely (#2406) 2026-02-25 12:41:17 -05:00
Yiming Cao
f2c567b853
fix(orm): _count is not included in select clause's typing when querying from a to-one relation (#2403) 2026-02-24 11:24:47 -05:00
Yiming Cao
89e3acbb38
fix: auto-add "views" preview feature to generated Prisma schema (#2376) (#2402)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 22:52:17 -05:00
Yiming Cao
defb7074f4
chore: add regression test for #2375 (#2400) 2026-02-23 22:41:45 -05:00
Yiming Cao
f3a9850501
fix: reject select with only false fields to prevent empty SELECT SQL (#2401)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 22:21:26 -05:00
Eugen Istoc
d49c39e260
fix: enhance delegate model interaction with afterEntityMutation plugin support in child updates (#2369) 2026-02-22 04:40:32 -08:00
Yiming Cao
1e70052ded
feat(zod): introduce an option to control depth of the built zod schemas (#2392) 2026-02-21 12:08:31 -08:00
Yiming Cao
7a98d4106d
feat: creating zod schemas for zmodel constructs and ORM query input validations (#2389) 2026-02-20 06:31:00 -08:00
Yiming Cao
3e03ab1506
refactor: remove import from orm package in generated schema (#2387) 2026-02-19 18:16:13 -08:00
Yiming Cao
da3b0af343
feat: ORM api slicing (#2383) 2026-02-18 07:45:04 -08:00
Yiming Cao
fc703b8f42
chore: clean up repo merging stale files (#2370) 2026-02-11 11:51:44 +08:00
ymc9
2564cd457b Merge remote-tracking branch 'v3/dev' into dev 2026-02-10 16:20:19 +08:00
Lukas Kahwe Smith
f8b28b6340
validate computed field configuration on startup (#653) 2026-02-08 10:04:41 +08:00
Copilot
5d1053f658
fix(schema): use type-only imports to prevent bundling server dependencies in client code (#668)
* Initial plan

* Fix: Change ModelResult/TypeDefResult imports to type-only imports in ts-schema-generator

Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>

* Regenerate test schemas with type-only imports

Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>

* Fix: Update bun runtime models.ts to use type-only imports

Co-authored-by: Yiming Cao <ymc9@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: Yiming Cao <ymc9@users.noreply.github.com>
2026-02-07 23:25:23 +08:00