Skip to content

Commit

Permalink
Allow calling service.read with ref (#361)
Browse files Browse the repository at this point in the history
  • Loading branch information
daogrady authored Dec 4, 2024
1 parent 5d0fc09 commit 9ebe0cd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).

## Version 0.9.0 - tbd
### Added
- Adds missing properties for `log` in `cds.env`
- Added missing properties for `log` in `cds.env`
- Added overload for `service.read` to be called with a `ref`

### Fixed

Expand Down
2 changes: 2 additions & 0 deletions apis/services.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { EventContext } from './events'
import { Request } from './events'
import { ReadableStream } from 'node:stream/web'
import { _TODO } from './internal/util'
import { ref } from './cqn'

type Key = number | string | any

Expand All @@ -21,6 +22,7 @@ export class QueryAPI {
read: {
<T extends ArrayConstructable>(entity: T, key?: Key): Awaitable<SELECT<T>, InstanceType<T>>,
<T>(entity: linked.Definition | string, key?: Key): SELECT<T>,
(entity: ref, key?: Key): SELECT<unknown>,
}

/**
Expand Down
4 changes: 4 additions & 0 deletions test/typescript/apis/project/cds-services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ await srv.delete(Books)
await srv.delete(Books, 'ID')
await srv.delete(Books).where({ id: 123 })
await srv.upsert({}).into(Books)
await srv.read({} as unknown as cds.ref)
await srv.read({} as unknown as cds.ref, 42)

await cds.read(Books, 'ID')
await cds.create(Books)
Expand All @@ -69,6 +71,8 @@ await cds.update(Books, 'ID')
await cds.delete(Books)
await cds.delete(Books, 'ID')
await cds.delete(Books).where({ id: 123 })
await cds.read({} as unknown as cds.ref)
await cds.read({} as unknown as cds.ref, 42)
// GAP: has to be added in runtime, then types, then re-enable this test
// await cds.upsert({}).into(Books)

Expand Down

0 comments on commit 9ebe0cd

Please sign in to comment.