Commit graph

80 commits

Author SHA1 Message Date
Lukas Wolf
7bc2fe57d7
feat(orm): implement delegateMap attribute (#2676) 2026-05-22 08:31:43 -07:00
Yiming Cao
026450bfe7
fix(orm): make orderBy nulls optional (#2670)
Some checks are pending
CodeQL / Analyze (javascript-typescript) (push) Waiting to run
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-13 12:13:11 -07:00
ymc9
1997cf3e98 fix(orm): coalesce NULL → '' in single-field _ftsRelevance ORDER BY
`to_tsvector(NULL)` returns NULL and `ts_rank(NULL, ...)` therefore
returns NULL — under Postgres's default `NULLS FIRST` for `ORDER BY DESC`
this would surface NULL-valued rows ahead of any matching ones, an
asymmetry with the multi-field path where `concat_ws(' ', ...)` already
skips NULLs and yields a 0.0 rank. Coalescing the field to `''` aligns
the two paths.

Adds `subtitle: String? @fullText` to the test fixture and a regression
test that orders a NULL-subtitle row against a matching one — without
the fix, the NULL row ranks first under DESC.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-06 21:07:53 -07:00
ymc9
d0dd954827 feat(orm): add @fullText attribute and Postgres full-text search
Introduces a Prisma-style full-text search capability gated by a new
field-level `@fullText` ZModel attribute. PostgreSQL only — MySQL/SQLite
throw NotSupported. Mirrors the existing `@fuzzy` design.

- Filter operator: `where: { title: { fts: { search, config? } } }`
  emits `to_tsvector(field) @@ to_tsquery(query)` (or with a `::regconfig`
  cast when `config` is provided; otherwise Postgres uses the database's
  `default_text_search_config`).
- OrderBy operator: `_ftsRelevance: { fields, search, config?, sort }`
  emits a single `ts_rank(...)`. Multi-field combines fields with
  `concat_ws(' ', ...)` so AND queries match terms across fields
  (matches Prisma's behavior).
- Type-level gating: the `fts` operator and `_ftsRelevance` orderBy
  appear only on String fields annotated with `@fullText` and only when
  the schema's provider is `postgresql`. Slicing's `'FullText'` filter
  kind controls availability of the runtime operator.
- Cursor pagination is rejected when combined with `_ftsRelevance`
  (parallel to `_fuzzyRelevance`).

Also refactors `buildOrderBy` to dispatch to small per-branch helpers
(`applyScalarOrderBy`, `applyAggregationOrderBy`, `applyRelationOrderBy`,
`applyFuzzyRelevanceOrderBy`, `applyFtsRelevanceOrderBy`).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-06 11:34:30 -07:00
Yiming Cao
8ddbfdebdc
feat(orm): add field-level @fuzzy attribute to gate fuzzy search (#2642)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-05 12:41:09 -07:00
docloulou
679f91fc26
feat(orm): add fuzzy search and relevance ordering (PostgreSQL) (#2573)
Some checks failed
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
2026-05-03 20:11:03 -07:00
Yiming Cao
9cef0272e7
chore: upgrade to TypeScript 6 (#2629) 2026-04-29 20:41:27 -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
14e1d55544
chore: fix up test case (#2600) 2026-04-21 17:33:06 -07:00
Lukas Kahwe Smith
bfdfce13c0
fix(orm): accept plain date strings in DateTime @db.Date field filters (#2572)
Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
2026-04-21 16:46:30 -07:00
Erwan JOLY
3398c87dbb
fix(orm): return @db.Time fields as Date instead of raw string (#2589) (#2590) 2026-04-18 20:17:45 -07:00
Yiming Cao
c858bbd4cf
feat(language): allow relation fields in type declarations for mixin use cases (#2583)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-16 20:01:12 -07:00
Yiming Cao
dc26257553
feat(server): add OpenAPI spec generation for RPC API (#2574)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-11 21:35:24 -07:00
Yiming Cao
39a0a28c51
fix(orm): enforce at most one key per orderBy array element (#2563) 2026-04-06 19:16:27 -07:00
Emil Redzik
c6c8ad1906
fix(orm): unify zenstack v3 and prisma behavior on empty branches in OR filter (#2528)
Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
2026-04-02 23:44:28 -07:00
Emil Redzik
9346fe92ce
fix(orm): fixed postgres orderBy in nested queries (includes/selects) (#2518)
Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
2026-03-28 21:58:31 -07:00
Pavel Kudinov
1adf26c216
fix: preserve transaction state in $use, $unuse, and $unuseAll (#2497)
Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
2026-03-20 22:24:04 -07:00
Yiming Cao
00768de0cc
fix(orm): use uncapitalized model names in OmitConfig and ComputedFieldsOptions (#2496)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-18 17:47:03 -07:00
Yiming Cao
c768af7b7c
fix(orm): exclude Unsupported fields from ORM client (#2468) 2026-03-17 12:36:46 -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
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
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
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
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
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
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
da3b0af343
feat: ORM api slicing (#2383) 2026-02-18 07:45:04 -08:00
Lukas Kahwe Smith
f8b28b6340
validate computed field configuration on startup (#653) 2026-02-08 10:04:41 +08:00
sanny-io
2b3d7d6f61
feat: ignore argument for @updatedAt (#572)
* feat: `ignore` argument for `@updatedAt`

* chore: add tests

* Trigger Build

* Check test.

* Use `getTime`

* Retry.

* Retry.

* Retry.

* Retry.

* Retry.

* Retry.

* Retry.

* Clean up.

* Document param.

* Extract to function.

* Relocate function.

* Adjust formatting.

* Use `getAttributeArg`

* Use `$resolvedParam`

* Null check.

* fix: resolve a merge error

* fix: delay data clone to right before changing it

---------

Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
2026-01-30 16:16:16 +08:00
Yiming Cao
1d47af918f
fix(orm): deal with node-pg timezone issue more reliably (#630)
* fix(orm): deal with node-pg timezone issue more reliably

fixes #606

* addressing PR comments
2026-01-29 16:56:03 +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
Lukas Kahwe Smith
9e819e811b
add test for pg computed values across multiple schema (#615)
* add test for pg computed values across multiple schema

* Add an any cast to type check test file

---------

Co-authored-by: Yiming Cao <yiming@whimslab.io>
2026-01-24 11:12:58 +08:00
sanny-io
27e8910830
feat: between operator (#569)
* feat: `between` operator

* chore: add tests

* Document inclusivity.

* Add reversed order test.

* chore: add REST server test

* Fix test typo.

* Verify correct object returned.

* Additional test cases.

* Make AI suggested changes.

* Remove filter.

* Fix styling.

* Add more REST tests.

* Add more int tests for REST.
2026-01-16 21:30:31 +08:00
Yiming Cao
233b47d2ed
feat: plugin-extended query args (#599)
https://discord.com/channels/1035538056146595961/1460921516936925388
2026-01-16 20:52:42 +08:00
Yiming Cao
154ba296d2
fix(orm): incorrect result type when "_count" is nested inside "include" (#589) 2026-01-11 17:45:51 +08:00
Yiming Cao
92c34c44db
fix(orm): add special treatment to enum arrays for postgres db (#577)
* fix(orm): add special treatment to enum arrays for postgres db

- For input, the string array needs to be casted with "Enum"[]
- For output, the raw pg array string needs to be parsed back to a proper JS string array

fixes #576

* fix enum array filtering and improve test cases

* update

* addressing PR comments
2026-01-08 20:53:28 +08:00
Mike Willbanks
2172614e0e
custom procedures (#551)
* feat: custom procs

* chore: cleanup

* fix: remove $procedures from client

* fix: failing test due to previous alias

* feat(custom-procs)!: make procedures envelope-only via $procs

- Switch procedure calls to `db.$procs.name({ args: {...} })` (no positional args)
- Remove legacy `$procedures` alias entirely (client API + server routing/logging)
- Validate procedure envelope input (`args` object, required/unknown keys)
- Keep TanStack Query procedure hooks as `(args, options)` (with conditional args optionality)
- Update server/ORM/client tests for the envelope API

* fix: code review feedback

* fix: code review comments

* fix: coderabbit review comments

* fix: remove useless proxy method

* test: add a couple of e2e tests that verify both typing and runtime

* test: improve e2e tests

* test: add missing mutation flag

* regenerate test schema

* refactor: procedure params generation fix and type refactors

- Simplified procedure's params definition from a tuple an object, since procs are now called with an envelop now

- Refactored procedure related typing to make them more consistent with other CURD types (that usually takes the schema as the first type parameter, and a name as the second)

- Moved detailed procedure's types to "crud-types" where other ORM client detailed types are defined

- Removed some type duplication from hooks side

- Updated the "orm" sample to demonstrate procedures

* fix: disable infinite custom proc queries for now

---------

Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
2026-01-08 11:21:51 +08:00
FTB_lag
3fde86d9cf
feat(cli): implement watch mode for generate (#554)
* feat(cli): implement watch mode for generate

* chore(root): update pnpm-lock.yaml

* chore(cli): track all model declaration and removed paths, logs in past tense

* fix(cli): typo, unused double array from

* fix(orm): preserve zod validation errors when validating custom json types

* update

* chore(cli): move import, fix parallel generation on watch

* feat(common-helpers): implement single-debounce

* chore(cli): use single-debounce for debouncing

* feat(common-helpers): implement single-debounce

* fix(common-helpers): re run single-debounce

---------

Co-authored-by: Yiming Cao <yiming@whimslab.io>
Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
2026-01-07 21:52:50 +08:00
sanny-io
446a48335f
feat: exists operation (#550)
* feat: exists operation

* Add RPC handling.

* Add frontend handling.

* Add tests.

* Fix postgres error.

* Add JSDoc.

* Remove `@ts-expect-error`

* Disable post-processing.

* Put semicolon back.
2026-01-07 18:05:49 +08:00
Yiming Cao
be330ff403
fix(orm): cuid() generator should respect version argument (#547)
* feat(orm): support where enum

* fix(orm): super transform for where

* feat(orm): support nested enum in where and/or

* fix: resolve field's model from scope instead of relying on table qualification

* fix(orm): cuid() generator should respect version argument

---------

Co-authored-by: FTB_lag <tabolskyy.git@gmail.com>
2025-12-29 23:18:35 +08:00
FTB_lag
6917a8c5ce
feat(orm): support where enum (#544)
* feat(orm): support where enum

* fix(orm): super transform for where

* feat(orm): support nested enum in where and/or

* fix: resolve field's model from scope instead of relying on table qualification

---------

Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
2025-12-29 21:20:27 +08:00
sanny-io
d89f1068f2
fix: check for empty strings and escapement for ID formatting (#542)
* fix: do not accept empty strings, check for escapement

* chore: add more edge cases, remove invalid test
2025-12-29 15:03:34 +08:00
sanny-io
4f06c2007c
Add support for generated identifier format strings (id prefixing). (#509)
* Add support for generated identifier format strings (ID prefixing).

* Add tests.

* Add missing semicolon.

* Cleanup logic.

* Fix typo.

* Use `replaceAll` instead.

* Add language support and tests.

* Simplify logic.

* allow using '\\%s' to escape replacement pattern, improve tests

* Shorten some test names.

---------

Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
2025-12-25 16:04:59 +08:00