Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: req.query.elements #27

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions apis/cqn.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { entity } from './csn' // cyclic dependency
import { EntityElements, entity } from './csn' // cyclic dependency
import { UnionToIntersection, UnionsToIntersections } from './internal/inference'

// FIXME: a union type would be more appropriate here
export type Query = Partial<SELECT & INSERT & UPDATE & DELETE & CREATE & DROP & UPSERT>
// FIXME: This type is also used for req.query.
// It misses the QL functionality of req.query.
// It includes SELECT.elements for now but that should be expressed differently.
export type Query = Partial< (SELECT & {elements: EntityElements}) & INSERT & UPDATE & DELETE & CREATE & DROP & UPSERT>

export type SELECT = { SELECT: {
distinct?: true,
Expand Down
1 change: 1 addition & 0 deletions test/typescript/apis/project/cds-ql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ SELECT.from(Foos).columns("x") // x was suggested by code completion
sel.from(Foos)
sel.columns("x") // x was suggested by code completion
sel.SELECT.columns?.filter(e => !e) // check if this is array
sel.elements

// ensure ql returns a proper CQN
const s = SELECT.from(Foos).columns('ID').where('ID =', 42)
Expand Down
5 changes: 5 additions & 0 deletions test/typescript/apis/project/cds-services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ srv.before('*', async req => {
req.tenant
req.target.name
req.entity

req.query
req.query.elements
// req.query.where('x =', 9)
(req.query as SELECT<Foo>).SELECT.from.ref
})

srv.after('*', (results, req) => {
Expand Down
Loading