zenstack/packages/language/test/procedure-validation.test.ts
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

43 lines
864 B
TypeScript

import { describe, it } from 'vitest';
import { loadSchemaWithError } from './utils';
describe('Procedure validation', () => {
it('rejects unknown parameter type', async () => {
await loadSchemaWithError(
`
model User {
id Int @id
}
procedure foo(a: NotAType): Int
`,
/unknown type|could not resolve reference/i,
);
});
it('rejects unknown return type', async () => {
await loadSchemaWithError(
`
model User {
id Int @id
}
procedure foo(): NotAType
`,
/unknown type|could not resolve reference/i,
);
});
it('rejects reserved procedure names', async () => {
await loadSchemaWithError(
`
model User {
id Int @id
}
procedure __proto__(): Int
`,
/reserved/i,
);
});
});