Commit graph

1461 commits

Author SHA1 Message Date
copilot-swe-agent[bot]
5292a9f927 Restore BeforeEntityMutationCallback cast to fix TS2321 excessive stack depth in CI build
Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
2026-03-18 02:26:46 +00:00
copilot-swe-agent[bot]
e077a4d0c3 Remove unnecessary BeforeEntityMutationCallback cast after HasRelations simplification
Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
2026-03-17 21:18:11 +00:00
copilot-swe-agent[bot]
1a5c4373cf Simplify HasRelations using RelationFields extends never form
Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
2026-03-17 21:15:39 +00:00
copilot-swe-agent[bot]
46ea0e2e98 Replace (payload as any).include casts with 'include' in payload narrowing checks
Co-authored-by: jiashengguo <16688722+jiashengguo@users.noreply.github.com>
2026-03-17 07:07:32 +00:00
copilot-swe-agent[bot]
b9d581eab0 Fix build errors caused by SelectIncludeOmit type change
Co-authored-by: jiashengguo <16688722+jiashengguo@users.noreply.github.com>
2026-03-17 06:13:46 +00:00
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
a6ce140730
perf(orm): batch many-to-many relation manipulation (#2486) 2026-03-15 21:21:24 -07:00
Yiming Cao
0778e493a9
perf(orm): improve post query data processing performance (#2485) 2026-03-14 17:32:33 -07:00
Yiming Cao
49395f7280
perf(orm): avoid unnecessary pre-mutation read and transactions (#2484) 2026-03-14 12:18:11 -07:00
ymc9
031701b8c5 fix: change $diagnostics to a property 2026-03-13 10:09:01 -07:00
ymc9
e50ced474a fix(orm): diagnostics should return slow queries sorted by duration 2026-03-13 09:40:55 -07:00
Yiming Cao
f85711a8a4
refactor(schema): widen types for attributes, default, and foreignKeyFor (#2482) 2026-03-12 22:51:31 -07:00
ymc9
c96bdbaf6e address PR comments 2026-03-12 21:35:50 -07:00
ymc9
14b55e32b7 add startedAt field to query info 2026-03-12 21:31:37 -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
d75f7f3d31 address PR comments 2026-03-12 19:11:57 -07:00
ymc9
5a55977316 fix(orm): allow Infinity for slowQueryMaxRecords validation
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>
2026-03-12 19:08:11 -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
Yiming Cao
d4fbb38609
fix(orm): add webpack magic comment to suppress bundler warnings for optional dependencies (#2476) 2026-03-11 11:51:25 -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
Yiming Cao
5aaef621b4
chore: address PR comments (#2463) 2026-03-07 16:26:53 -08: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
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
Jiasheng
87a9f7fb3f
fix(proxy): enhance omit configuration to include Unsupported fields (#2441) 2026-03-04 14:54:44 -08:00
Yiming Cao
a49c2da456
fix(cli): add "@zenstackhq/schema" package installation for "zenstack create" and "zen init" (#2437) 2026-03-03 09:43:45 -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
Román Benjámin
b2305cd54f
fix(cli): exclude Prisma migrations from SQLite pull (#2427) 2026-03-02 09:43:53 -08:00
Jiasheng
4629810fe6
test(proxy): add ut for proxy (#2432) 2026-03-01 22:35:28 -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
Jiasheng
c99c47bca4
fix(studio): add option to skip validation for computed fields when start proxy (#2429) 2026-03-01 20:13:03 -08:00
Yiming Cao
7de2af2be2
fix(cli): dynamically load pg module in "db pull" (#2421) 2026-02-27 19:48:52 -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
Yiming Cao
e46ddc576a
fix(zod): exclude computed and delegate fields from create/update schemas (#2418) 2026-02-27 16:43:47 -08:00
Jiasheng
4fe27ef8be
chore(cli): show notifications for generate command (#2409)
Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
2026-02-27 10:44:01 -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