Skip to content

feat: support for cds.Map #404

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

Merged
merged 6 commits into from
Feb 19, 2025
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).

## [Unreleased]
### Added
- Added support for new builtin type `cds.Map`
- Added types for `SELECT.hints()` of `cds.ql` API

### Changed
Expand Down
6 changes: 5 additions & 1 deletion apis/csn.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export interface type extends any_ {
'cds.UUID' | 'cds.String' | 'cds.LargeString' | 'cds.Binary' | 'cds.LargeBinary' | 'cds.Vector' |
'cds.Integer' | 'cds.UInt8' | 'cds.Int16' | 'cds.Int32' | 'cds.Int64' | 'cds.Double' | 'cds.Decimal' |
'cds.Date' | 'cds.Time' | 'cds.DateTime' | 'cds.Timestamp' |
'cds.Association' | 'cds.Composition' |
'cds.Association' | 'cds.Composition' | 'cds.Map' |
FQN & Record<never,never> // allow any other CDS type as well (e.g. 'User')
items?: type
}
Expand All @@ -85,6 +85,10 @@ export interface struct extends type {
elements: { [name: string]: Element }
}

export interface Map extends Omit<struct, 'includes' | 'items'> {
elements: Record<string,never>
}

export interface entity extends Omit<struct, 'elements'> {

/**
Expand Down
6 changes: 6 additions & 0 deletions apis/linked/classes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ declare class struct<K extends kinds = 'elements' | 'type'> extends type<K> impl
elements: Definitions<type<'type'>>
}

/**
* @since 8.6.0
*/
declare interface Map extends csn.Map {}
declare class Map {}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In which cases is inheritance required?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strictly to inherit properties from superclasses.
If we do not need any properties from the classes above (.type?), then inheritance is not needed.


// clashes with services.context when exported from facade
declare interface context_ extends csn.context {}
declare class context_ extends any_ { }
Expand Down
8 changes: 7 additions & 1 deletion test/typescript/apis/project/cds-linked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import cds from '@sap/cds';
import { csn } from '../../../..';
import { as } from './dummy';

const { action, aspect, entity, event, mixin, scalar, struct, type, Decimal, String } = cds.linked.classes
const { action, aspect, entity, event, mixin, scalar, struct, type, Decimal, String, Map } = cds.linked.classes

// is exported from top level
as<LinkedCSN>() === as<cds.linked.LinkedCSN>()
Expand Down Expand Up @@ -91,6 +91,12 @@ new Decimal().scale

new String().length

const never: never = new Map().elements.xyz
new Map().elements
// @ts-expect-error
new Map().items


mixin(class {}, class {})
// @ts-expect-error
mixin(42)
Expand Down
Loading