diff --git a/apis/csn.d.ts b/apis/csn.d.ts index 9449bfd0..fc941924 100644 --- a/apis/csn.d.ts +++ b/apis/csn.d.ts @@ -66,7 +66,12 @@ export interface context extends any_ { } export interface service extends any_ { } export interface type extends any_ { - type?: FQN + type?: 'cds.Boolean' | + 'cds.UUID' | 'cds.String' | 'cds.LargeString' | 'cds.Binary' | 'cds.LargeBinary' | 'cds.Vector' | + 'cds.Integer' | 'cds.UInt8' | 'cds.Int16' | 'cds.Int32' | 'cds.Int64' | 'cds.Float' | 'cds.Double' | 'cds.Decimal' | + 'cds.Date' | 'cds.Time' | 'cds.DateTime' | 'cds.Timestamp' | + 'cds.Association' | 'cds.Composition' | + FQN & Record // allow any other CDS type as well (e.g. 'User') items?: type } @@ -102,11 +107,13 @@ export type EntityElements = { virtual?: boolean, unique?: boolean, notNull?: boolean, + precision?: number, + scale?: number, + length?: number, }, } export interface Association extends type { - type: 'cds.Association' | 'cds.Composition' target: FQN /** diff --git a/apis/linked/classes.d.ts b/apis/linked/classes.d.ts index e0eaec15..87c47645 100644 --- a/apis/linked/classes.d.ts +++ b/apis/linked/classes.d.ts @@ -54,7 +54,10 @@ declare class aspect extends type implements With elements: Definitions> } declare interface type extends Omit { - items: type + items?: type + key?: boolean + notNull?: boolean + virtual?: boolean } declare class type extends any_ { } @@ -79,7 +82,10 @@ declare class Int32 extends Integer { } declare class Int64 extends Integer { } declare class Float extends number { } declare class Double extends Float { } -declare class Decimal extends Float { } +declare class Decimal extends Float { + precision?: number + scale?: number +} declare class date extends scalar { } declare class Date extends date { } diff --git a/apis/linked/internal.d.ts b/apis/linked/internal.d.ts index 2fd5546f..ba8872ae 100644 --- a/apis/linked/internal.d.ts +++ b/apis/linked/internal.d.ts @@ -14,5 +14,7 @@ import type { scalar } from './classes' declare class number_ extends scalar { } -declare class string_ extends scalar { } +declare class string_ extends scalar { + length?: number +} declare class boolean_ extends scalar { } diff --git a/test/typescript/apis/project/cds-linked.ts b/test/typescript/apis/project/cds-linked.ts index 8b8afe23..c5a1f3dc 100644 --- a/test/typescript/apis/project/cds-linked.ts +++ b/test/typescript/apis/project/cds-linked.ts @@ -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 } = cds.linked.classes +const { action, aspect, entity, event, mixin, scalar, struct, type, Decimal, String } = cds.linked.classes // is exported from top level as() === as() @@ -47,7 +47,7 @@ new entity().texts?.kind === 'entity' new entity().drafts?.kind === 'entity' new entity().is_entity === true new entity().is_struct === true; -[...new entity().elements].find(x => x.items.kind === 'type') +[...new entity().elements].find(x => x.items && x.items.kind === 'type') new entity().items?.kind new entity().name // @ts-expect-error @@ -73,6 +73,9 @@ new scalar().kind === 'scalar_' new type().kind === 'type' // @ts-expect-error new type().kind === 'type_' +new type().key +new type().virtual +new type().notNull new event().elements new event().kind === 'event' @@ -83,6 +86,11 @@ new action().kind === 'action' // @ts-expect-error new action().kind === 'action_' +new Decimal().precision +new Decimal().scale + +new String().length + mixin(class {}, class {}) // @ts-expect-error mixin(42)