Commit graph

83 commits

Author SHA1 Message Date
Keath Pavlenko
1a4de21bdc
fix: detect policy plugin by stable id (#2663)
Some checks are pending
CodeQL / Analyze (javascript-typescript) (push) Waiting to run
2026-05-11 18:28:16 -07:00
Erwan JOLY
ce50d3ba48
fix(orm): coerce ISO strings on DateTime input, with strictDateInput opt-in (#2631) (#2632)
Some checks failed
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-08 05:56:25 -07:00
Yiming Cao
899e74daf6
test(regression): add regression test for issue #2639 (#2657)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 21:47:35 -07:00
Yiming Cao
7283d0e4d1
fix(orm): handle cyclic JSON typedef references in zod factory (#2654) (#2655)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 20:51:04 -07:00
Erwan JOLY
d1db37cee5
fix(orm): format Date as HH:MM:SS for @db.Time / @db.Timetz columns (#2633) (#2634) 2026-05-07 18:02:55 -07:00
Yiming Cao
d5e790061a
fix(orm, zod): allow null in inferred type of required Json fields (#2647) (#2649)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 19:14:07 -07:00
Yiming Cao
2a10bcae09
fix(orm): export UncheckedCreateInput/CheckedCreateInput and add XOR to UpdateInput (#2627)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-29 14:44:21 -07:00
Yiming Cao
d30ebade7f
fix(policy): resolve inherited fields in delegate sub-type create policy checks (#2623)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-27 18:23:37 -07:00
Yiming Cao
09ca875066
test(regression): add regression test for issue #2538 (#2607) 2026-04-22 16:32:01 -07:00
ymc9
fa94d38bb2 test(regression): add regression test for issue #2538
Adds a regression test for nested collection predicates in access
policies generating valid SQL (issue #2538).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-22 15:59:06 -07:00
Yiming Cao
40c45944cc
fix(orm): resolve implicit m2m join table schema for non-public PostgreSQL schemas (#2606)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-22 15:21:43 -07:00
Yiming Cao
1cf4345ffa
fix(policy): join base table when loading before-update entities for @@delegate sub-models (#2605)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-22 11:59:30 -07:00
Eugen Istoc
4e35bc163b
fix(orm): resolve delegate-inherited fields in cursor pagination (#2591) 2026-04-18 15:50:06 -07:00
Yiming Cao
09b96e4ed3
fix(orm): make JsonArray mutable to fix Zod schema type incompatibility (#2585) 2026-04-16 22:03:39 -07:00
Evgenii Novalov
36da18a17f
perf(orm): use EXISTS instead of COUNT subquery for to-one relation filters (#2579)
Co-authored-by: evgenovalov <evgenii@flowlity.com>
2026-04-15 13:07:16 -07:00
Yiming Cao
b8209d7eeb
chore: migrate from tsup to tsdown (#2580) 2026-04-15 12:13:34 -07:00
Lukas Kahwe Smith
3393e4cc21
@computed fields from mixin types (with) cause column does not exist error when the model is explicitly included (#2539)
Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-13 13:49:35 -07:00
Yiming Cao
d22709fb55
fix(orm): prepend DISTINCT ON fields to ORDER BY for PostgreSQL compatibility (#2562)
Co-authored-by: Claude Sonnet 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-04-06 16:47:45 -07:00
Yiming Cao
e9482fe34f
fix(orm): fix _count returning 0 for self-referential relations on delegate models (#2555)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-03 18:16:39 -07:00
Yiming Cao
744c760ac4
fix(orm): split jsonb_build_object calls exceeding PostgreSQL 100-arg limit (#2554)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-03 15:49:18 -07:00
Yiming Cao
dbb3474c65
fix(orm): support DbNull/JsonNull/AnyNull for nullable typed JSON fields (#2552)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-03 15:08:57 -07:00
Yiming Cao
a81d8f4f52
test(regression): add regression test for issue #2410 (#2549)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-03 14:10:06 -07:00
Lukas Wolf
28ae08d739
fix(policy): currentModel and currentOperation inside of collection predicates (#2537) 2026-03-31 22:35:16 -07:00
ymc9
a0a6424c5d Revert "fix(policy): skip m2m update-policy check for newly created side on connect"
This reverts commit 59d302d199.
2026-03-31 20:13:14 -07:00
ymc9
59d302d199 fix(policy): skip m2m update-policy check for newly created side on connect
When creating a model with a nested many-to-many `connect`, the join table
insert triggered an update-policy check on the just-created entity. Because
the connection doesn't exist yet at check time, relation-based policies
(e.g. `parents?[id == auth().id]`) always evaluated to false, causing a
spurious "not updatable" error.

Fix by embedding a lightweight marker in the insert query's end-modifier
comment so the policy handler can identify the newly-created side and skip
its circular update check. The connected side's update policy is still
enforced. Adds regression test for issue #2531.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-31 20:06:12 -07:00
Yiming Cao
4686720178
fix(orm): fix PostgreSQL type mismatch when @db.Uuid fields used in policy expressions (#2532)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-30 18:39:53 -07:00
Yiming Cao
e6317dc9b5
fix(orm): disallow include on models without relation fields (#2508)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-22 20:05:55 -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
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
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
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
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
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
Yiming Cao
75bc4a1937
fix(policy): wrong table alias used when injecting for field policies (#2413) 2026-02-26 21:02:36 -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
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
Yiming Cao
3e03ab1506
refactor: remove import from orm package in generated schema (#2387) 2026-02-19 18:16:13 -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
Yiming Cao
080114bb9a
fix(orm): properly cast values for array filters for postgres (#662)
* fix(orm): properly cast values for array filters for postgres

fixes #651

* add missing Array conversion

* refactor
2026-02-06 20:10:56 +08:00
Yiming Cao
ab9535ea90
fix(language): resolve mixin fields from imported files in scope (#598) (#632)
Fixed issue where access policy rules couldn't reference fields inherited from mixins defined in separate imported files. The language service now correctly resolves these fields during scope computation.

## Root Cause

The `getRecursiveBases()` function only searched for mixin declarations in the current document (`decl.$container.declarations`), which failed for imported mixins.

## Solution

- Modified `getRecursiveBases()` to accept optional `LangiumDocuments` parameter
- Implemented two-strategy approach:
  1. Use resolved reference if available (post-linking)
  2. Search by name across all documents including imports (pre-linking)
- Updated `ZModelScopeComputation.processNode()` to pass `LangiumDocuments`
- Leverages existing `getAllDeclarationsIncludingImports()` helper

## Changes

- **packages/language/src/utils.ts**: Fixed `getRecursiveBases()` to search imported documents
- **packages/language/src/zmodel-scope.ts**: Pass LangiumDocuments to scope computation
- **packages/language/test/mixin.test.ts**: Added tests for imported mixin field resolution
- **packages/testtools**: Added `extraZModelFiles` option for multi-file test schemas
- **tests/regression/test/issue-598.test.ts**: Regression test for the issue

## Test Results

 All language package tests pass (65 tests)
 Regression test validates policy rules can access imported mixin fields
 Handles edge cases: cyclic imports, nested mixins, transitive imports

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-30 13:38:10 +08:00
Yiming Cao
209312a27b
fix(orm): properly handle literal array values in policy evaluation for postgres (#628) 2026-01-29 00:15:07 +08:00
Yiming Cao
84d1e60ae1
perf(orm): more aggressive caching of validation zod schemas (#623)
* WIP: more aggressive caching of validation zod schemas

* refactor: use a decorator-based approach for caching

* update

* update

* update

* update

* update

* remove object-type args from cache key

* update cache key
2026-01-27 11:30:05 +08:00
Yiming Cao
99f68e2f7b
feat(orm): mysql support (#616)
* WIP(orm): mysql support

* WIP: more progress with fixing tests

* WIP: get all client api tests pass

* WIP: get all tests pass

* fix executor

* add MySQL to CI matrix

* fix sqlite test runs

* fix test

* fix delete readback check

* set mysql container max connections

* fix tests

* fix test

* refactor: extract duplicated mysql/pg code into base class

* address PR comments

* refactor: remove order by duplicated code

* refactor: optimize stripTableReference

* addressing PR comments

* fix tests
2026-01-24 23:21:36 +08:00
Yiming Cao
6bf2b51c5d
fix(zmodel): improve attribute argument assignability check (#588)
* fix(zmodel): improve attribute argument assignability check

fixes #584

* fix JSON array check

* update

* update ts schema generator
2026-01-11 16:44:00 +08:00