Commit graph

23 commits

Author SHA1 Message Date
Lukas Wolf
7bc2fe57d7
feat(orm): implement delegateMap attribute (#2676) 2026-05-22 08:31:43 -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
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
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
Mike Willbanks
077f03f732
feat(zmodel): collection predicate binding (#548)
* feat: audit policy collection aliases

provides a means to alias collections in @@allow collections by extending the ast
this allows for utilizing collections inside of @@allow like:

```
memberships?[m,
    auth().memberships?[
        tenantId == m.tenantId ...
    ]
  ]
```

* fix: code review comments + syntax fixes

* refactor: extract collection predicate binding to its own language construct (#2)

- adjusted language processing chain accordingly
- fixed several issues in policy transformer/evaluator
- more test cases

* addressing PR comments

---------

Co-authored-by: Yiming Cao <yiming@whimslab.io>
Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
2026-01-18 14:08:10 +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
Yiming Cao
e4b79d0c6f
feat: field-level access control (#557)
* WIP

* WIP: implement read policies

* fix tests

* Update packages/plugins/policy/src/policy-handler.ts

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* fix name mapper

* fix tests

* fix build

* implement update field-level policies

* update tests

* update tests

* add more tests

* add more tests

* simplify queries

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-01-05 18:14:23 +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
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
Yiming Cao
2432f7f40e
fix(zmodel): more validation about "view" (#526) 2025-12-23 12:40:17 +08:00
Yiming Cao
081e434581
fix(zmodel): rejects delegate models with missing opposite relation (#490) 2025-12-14 10:23:00 +08:00
Yiming Cao
0492085c71
test(zmodel): more validation tests (#459) 2025-12-02 10:27:11 +08:00
Yiming Cao
59dfa73f01
refactor: move policy attributes to its own zmodel (#307)
* refactor: move policy attributes to its own zmodel

* update

* update

* fix tests
2025-10-16 21:52:22 -07:00
Yiming Cao
198c3528bf
feat(policy): post-update policies (#275) 2025-09-28 23:42:06 -07:00
Yiming Cao
3a2f1f9161
fix(language): ref resolution failure causes exception in validator (#269)
* fix(language): ref resolution failure causes exception in validator

* fix lint

* update

* fix tests
2025-09-23 19:18:58 -07:00
Yiming Cao
9bf6d7f754
refactor: move policy zmodel back to stdlib (#265)
* refactor: move policy zmodel back to stdlib

* update
2025-09-22 22:43:14 -07:00
Yiming Cao
f9baaaf012
fix(policy): run pg/sqlite tests, misc dual db compatibility fixes (#260)
* fix(policy): run pg/sqlite tests, misc dual db compatibility fixes

* addressing review comments, cleaning up text search casing

* addressing pr comments

* try fixing CI

* update

* fix tests

* update
2025-09-22 16:16:15 -07:00
Yiming Cao
4ef27c7d0f
feat(policy): support comparing auth() with auth model (#244)
* feat(policy): support comparing `auth()` with auth model

* fix file name
2025-09-09 21:33:06 -07:00
Yiming Cao
774f3c41fa
fix: stricter type def validation and compound unique field fix (#223) 2025-08-31 22:57:54 +08:00
Yiming Cao
0df015ad8d
feat: implement zmodel import (#126)
* feat: implement zmodel import

* addressing PR comments

* update
2025-07-30 16:45:55 +08:00
Yiming Cao
cbf1ce3366
feat: implement delegate models (create + read) (#110)
* feat: implement delegate models (create + read)

* update

* update

* update
2025-07-23 22:54:28 +08:00
Yiming Cao
39cf629b0c
feat: implementing mixin (#106)
* feat: implementing mixin

* format

* update
2025-07-21 19:48:48 +08:00