@cap-js/cds-types 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -15,8 +15,19 @@ Find more information on the APIs in the [Node.js SDK documentation](https://cap
15
15
 
16
16
  ## Support, Feedback, Contributing
17
17
 
18
+ ### Local Setup
19
+
20
+ After cloning, just run
21
+
22
+ ```sh
23
+ npm run setup
24
+ ```
25
+
26
+ which installs all dependencies.
27
+
18
28
  This project is open to feature requests/suggestions, bug reports etc. via [GitHub issues](https://github.com/cap-js/cds-types/issues). Contribution and feedback are encouraged and always welcome. For more information about how to contribute, the project structure, as well as additional contribution information, see our [Contribution Guidelines](CONTRIBUTING.md).
19
29
 
30
+
20
31
  ## Security / Disclosure
21
32
 
22
33
  If you find any bug that may be a security problem, please follow our instructions at [in our security policy](https://github.com/SAP/.github/blob/main/SECURITY.md) on how to report it. Please do not create GitHub issues for security-related doubts or problems.
package/apis/cds.d.ts CHANGED
@@ -16,7 +16,7 @@ export * from './cqn'
16
16
  // API extractor cannot handle export * as ql from './ql', so split it into an import and an export statement
17
17
  import * as ql from './ql'
18
18
  export { ql }
19
- export { QLExtensions } from './ql' // cds-ql.ts test tries to import this from top level? Correct? Or ql.QLExtensions?
19
+ export { QLExtensions } from './ql' // cds-ql.ts test tries to import this from top level? Correct? Or ql.QLExtensions?
20
20
 
21
21
  // trick to work around "delete" as reserved identifier
22
22
  import { Service } from './services'
@@ -24,14 +24,14 @@ declare const delete_: Service['delete']
24
24
  export { delete_ as delete }
25
25
 
26
26
  declare global {
27
- // these provide the functionality from SELECT, INSERT, etc in the global facade
28
- const SELECT: ql.QL<any>['SELECT']
29
- const INSERT: ql.QL<any>['INSERT']
30
- const UPSERT: ql.QL<any>['UPSERT']
31
- const UPDATE: ql.QL<any>['UPDATE']
32
- const DELETE: ql.QL<any>['DELETE']
33
- const CREATE: ql.QL<any>['CREATE']
34
- const DROP: ql.QL<any>['DROP']
27
+ // these provide the functionality from SELECT, INSERT, etc in the global facade
28
+ const SELECT: ql.QL<any>['SELECT']
29
+ const INSERT: ql.QL<any>['INSERT']
30
+ const UPSERT: ql.QL<any>['UPSERT']
31
+ const UPDATE: ql.QL<any>['UPDATE']
32
+ const DELETE: ql.QL<any>['DELETE']
33
+ const CREATE: ql.QL<any>['CREATE']
34
+ const DROP: ql.QL<any>['DROP']
35
35
 
36
36
  // and these allow us to use them as type too, i.e. `const q: SELECT<Book> = ...`
37
37
  type SELECT<T> = ql.SELECT<T>
@@ -40,5 +40,5 @@ declare global {
40
40
  type UPDATE<T> = ql.UPDATE<T>
41
41
  type DELETE<T> = ql.DELETE<T>
42
42
  type CREATE<T> = ql.CREATE<T>
43
- type DROP<T> = ql.DROP<T>
44
- }
43
+ type DROP<T> = ql.DROP<T>
44
+ }
package/apis/core.d.ts CHANGED
@@ -6,44 +6,57 @@ type Intersect<T extends readonly unknown[]> = T extends [infer Head, ...infer T
6
6
  ? Head & Intersect<Tail>
7
7
  : unknown
8
8
 
9
- // These are classes actually -> using the new() => interface trick
10
9
  /**
11
10
  * Base class for linked Associations from reflected models.
12
11
  * @see [capire](https://cap.cloud.sap/docs/node.js/cds-reflect#cds-Association)
13
12
  */
14
- export type Association = new(_?:object) => LinkedAssociation
13
+ export interface Association extends LinkedAssociation {}
14
+ export declare class Association { constructor (_?: object) }
15
+
15
16
  /**
16
17
  * Base class for linked Compositions from reflected models.
17
- * @see [capire](https://cap.cloud.sap/docs/node.js/cds-reflect#cds-Association)
18
+ * @see [capire](https://cap.cloud.sap/docs/node.js/cds-reflect#cds-composition)
18
19
  */
19
- export type Composition = new(_?:object) => LinkedAssociation
20
+ export interface Composition extends Association {}
21
+ export declare class Composition { constructor (_?: object) }
22
+
20
23
  /**
21
24
  * Base class for linked entities from reflected models.
22
25
  * @see [capire](https://cap.cloud.sap/docs/node.js/cds-reflect#cds-entity)
23
26
  */
24
- export type entity = new(_?:object) => LinkedEntity
25
- export type event = new(_?:object) => linked & csn.struct
26
- export type type = new(_?:object) => linked & csn.type
27
- export type array = new(_?:object) => linked & csn.type
28
- export type struct = new(_?:object) => linked & csn.struct
27
+ export interface entity extends LinkedEntity {}
28
+ export declare class entity { constructor (_?: object) }
29
+
30
+ export interface event extends linked, csn.struct {}
31
+ export class event { constructor (_?: object) }
32
+
33
+ export interface type extends linked, csn.type {}
34
+ export class type { constructor (_?: object) }
35
+
36
+ export interface array extends linked, csn.type {}
37
+ export class array { constructor (_?: object) }
38
+
39
+ export interface struct extends linked, csn.struct {}
40
+ export class struct { constructor (_?: object) }
29
41
 
30
42
  // infer (query : cqn, model : csn) : LinkedDefinition
31
43
  export const builtin: {
44
+
32
45
  /**
33
46
  * Base classes of linked definitions from reflected models.
34
47
  * @see [capire](https://cap.cloud.sap/docs/node.js/cds-reflect#cds-builtin-classes)
35
48
  */
36
49
  classes: {
37
- Association: Association
38
- Composition: Composition
39
- entity: entity
40
- event: event
41
- type: type
42
- array: array
43
- struct: struct
44
- service: service
45
- }
46
- types: {}
50
+ Association: typeof Association,
51
+ Composition: typeof Composition,
52
+ entity: typeof entity,
53
+ event: typeof event,
54
+ type: typeof type,
55
+ array: typeof array,
56
+ struct: typeof struct,
57
+ service: service,
58
+ },
59
+ types: Record<string, object>,
47
60
  }
48
61
 
49
62
  /**
@@ -57,8 +70,8 @@ export const builtin: {
57
70
  * }.prototype)
58
71
  * ```
59
72
  */
60
- export function extend<T>(target: T): {
61
- with<E extends readonly unknown[]>(...ext: E): T & Intersect<E>
73
+ export function extend<T> (target: T): {
74
+ with<E extends readonly any[]>(...ext: E): T & Intersect<E>,
62
75
  }
63
76
 
64
77
  /**
@@ -75,7 +88,7 @@ export function extend<T>(target: T): {
75
88
  * The first usage of `facade.sub` will load the sub module
76
89
  * using standard Node.js's `module.require` functions.
77
90
  */
78
- export function lazify <T>(target: T) : T
91
+ export function lazify<T> (target: T): T
79
92
 
80
93
  /**
81
94
  * Prepare a node module for lazy-loading submodules instead
@@ -92,4 +105,4 @@ export function lazify <T>(target: T) : T
92
105
  * The first usage of `facade.sub` will load the sub module
93
106
  * using standard Node.js's `module.require` functions.
94
107
  */
95
- export function lazified <T>(target: T) : T
108
+ export function lazified<T> (target: T): T
package/apis/cqn.d.ts CHANGED
@@ -1,87 +1,98 @@
1
- import { entity } from "./csn" // cyclic dependency
1
+ import { entity } from './csn' // cyclic dependency
2
+ import { UnionToIntersection, UnionsToIntersections } from './internal/inference'
2
3
 
3
4
  // FIXME: a union type would be more appropriate here
4
5
  export type Query = Partial<SELECT & INSERT & UPDATE & DELETE & CREATE & DROP & UPSERT>
5
6
 
6
- export type SELECT = {SELECT:{
7
- distinct?: true
8
- one? : boolean
9
- from : source
10
- mixin?: {[key:string]: expr}
11
- columns? : column_expr[]
12
- excluding? : string[]
13
- where? : predicate
14
- having? : predicate
15
- groupBy? : expr[]
16
- orderBy? : ordering_term[]
17
- limit?: { rows:val, offset:val }
18
- }}
19
-
20
- export type INSERT = {INSERT:{
21
- into : ref | name
22
- entries : data[]
23
- columns : string[]
24
- values : scalar[]
25
- rows : scalar[][]
26
- as : SELECT
27
- }}
28
-
29
- export type UPSERT = {UPSERT:{
30
- into : ref | name
31
- columns : string[]
32
- entries : data[]
33
- values : scalar[]
34
- rows : scalar[][]
35
- }}
36
-
37
- export type UPDATE = {UPDATE:{
38
- entity : ref | name
39
- data : { [key:string] : expr }
40
- where? : predicate
41
- }}
42
-
43
- export type DELETE = {DELETE:{
44
- from : ref | name
45
- where? : predicate
46
- }}
47
-
48
- export type CREATE = {CREATE:{
49
- entity : entity | name
50
- as: SELECT
51
- }}
52
-
53
- export type DROP = {DROP:{
54
- entity : name
55
- table: ref
56
- view: ref
57
- }}
7
+ export type SELECT = { SELECT: {
8
+ distinct?: true,
9
+ one?: boolean,
10
+ from: source,
11
+ mixin?: { [key: string]: expr },
12
+ columns?: column_expr[],
13
+ excluding?: string[],
14
+ where?: predicate,
15
+ having?: predicate,
16
+ groupBy?: expr[],
17
+ orderBy?: ordering_term[],
18
+ limit?: { rows: val, offset: val },
19
+ }, }
20
+
21
+ export type INSERT = { INSERT: {
22
+ into: ref | name,
23
+ entries: data[],
24
+ columns: string[],
25
+ values: scalar[],
26
+ rows: scalar[][],
27
+ as: SELECT,
28
+ }, }
29
+
30
+ export type UPSERT = { UPSERT: {
31
+ into: ref | name,
32
+ columns: string[],
33
+ entries: data[],
34
+ values: scalar[],
35
+ rows: scalar[][],
36
+ }, }
37
+
38
+ export type UPDATE = { UPDATE: {
39
+ entity: ref | name,
40
+ data: { [key: string]: expr },
41
+ where?: predicate,
42
+ }, }
43
+
44
+ export type DELETE = { DELETE: {
45
+ from: ref | name,
46
+ where?: predicate,
47
+ }, }
48
+
49
+ export type CREATE = { CREATE: {
50
+ entity: entity | name,
51
+ as: SELECT,
52
+ }, }
53
+
54
+ export type DROP = { DROP: {
55
+ entity: name,
56
+ table: ref,
57
+ view: ref,
58
+ }, }
58
59
 
59
60
  /** @private */
60
61
  type scalar = number | string | boolean | null
62
+
61
63
  /** @private */
62
- type data = Record<string,any>
64
+ type data = Record<string, any>
65
+
63
66
  /** @private */
64
67
  type name = string
68
+
65
69
  /** @private */
66
- type source = ( ref | SELECT ) & { as?: name, join?:name, on?:xpr }
67
- export type column_expr = expr & { as?: name, cast?:any, expand?: column_expr[], inline?: column_expr[] }
68
- export type predicate = _xpr
70
+ type source = UnionToIntersection<ref | SELECT> & { as?: name, join?: name, on?: xpr }
71
+ export type column_expr = UnionToIntersection<expr> & { as?: name, cast?: any, expand?: column_expr[], inline?: column_expr[] }
72
+ export type predicate = UnionsToIntersections<_xpr>
73
+
69
74
  /** @private */
70
- type ordering_term = expr & { sort?: "asc"|"desc", nulls?: "first"|"last" }
75
+ type ordering_term = expr & { sort?: 'asc' | 'desc', nulls?: 'first' | 'last' }
71
76
 
72
77
  export type expr = ref | val | xpr | function_call | SELECT
78
+
73
79
  /** @private */
74
- type ref = {ref:( name & { id?:string, where?:expr, args?:expr[] } )[]}
80
+ type ref = { ref: (name & { id?: string, where?: expr, args?: expr[] })[] }
81
+
75
82
  /** @private */
76
- type val = {val:any}
83
+ type val = { val: any }
84
+
77
85
  /** @private */
78
- type xpr = {xpr:_xpr}
86
+ type xpr = { xpr: _xpr }
87
+
79
88
  /** @private */
80
- type _xpr = ( expr | operator ) []
89
+ type _xpr = (expr | operator) []
90
+
81
91
  /** @private */
82
92
  type operator = string
93
+
83
94
  /** @private */
84
- type function_call = {func: string, args: {[key: string]: unknown}[]}
95
+ type function_call = { func: string, args: { [key: string]: any }[] }
85
96
 
86
- export type enum_literal = {"#": string}
87
- export type expr_literal = {"=": string}
97
+ export type enum_literal = { '#': string }
98
+ export type expr_literal = { '=': string }
package/apis/csn.d.ts CHANGED
@@ -4,6 +4,7 @@ import { SELECT, ref, predicate } from './cqn'
4
4
  * A parsed CDS model in CSN object notation.
5
5
  */
6
6
  export interface CSN {
7
+
7
8
  /**
8
9
  * The assigned namespace. If parsed from multiple sources,
9
10
  * this is the topmost model's namespace, if any, not the
@@ -49,16 +50,18 @@ export type Definition = context & service & type & struct & entity & Associatio
49
50
  * Extensions capture `extend Foo with { ... }` directives.
50
51
  */
51
52
  export type Extension = {
52
- extend: FQN
53
- elements?: { [name: string]: Element }
54
- includes?: FQN[]
53
+ extend: FQN,
54
+ elements?: { [name: string]: Element },
55
+ includes?: FQN[],
55
56
  }
56
57
 
57
58
  export type Element = type & struct & Association
58
59
 
59
60
  export type kinds = 'type' | 'entity' | 'event' | 'service' | 'context' | 'struct'
60
61
 
61
- export interface any_ { kind?: kinds }
62
+ export interface any_ {
63
+ kind?: kinds
64
+ }
62
65
  export interface context extends any_ { }
63
66
  export interface service extends any_ { }
64
67
 
@@ -68,6 +71,7 @@ export interface type extends any_ {
68
71
  }
69
72
 
70
73
  export interface struct extends type {
74
+
71
75
  /**
72
76
  * References to definitions to be included.
73
77
  * Not available after extensions have been applied.
@@ -76,40 +80,45 @@ export interface struct extends type {
76
80
  elements: { [name: string]: Element }
77
81
  }
78
82
 
79
- export interface entity extends Omit<struct,'elements'> {
83
+ export interface entity extends Omit<struct, 'elements'> {
84
+
80
85
  /**
81
86
  * Entities with a query signify a view
82
87
  */
83
88
  query?: SELECT
89
+
84
90
  /**
85
91
  * Elements of entities may have additional qualifiers
86
92
  */
87
- elements : EntityElements
93
+ elements: EntityElements
88
94
  // REVISIT: following should move to LinkedCSN
89
95
  keys: { [name: string]: Definition }
90
- drafts: entity
96
+ drafts?: entity
91
97
  }
92
98
 
93
99
  export type EntityElements = {
94
- [name:string]: Element & {
95
- key? : boolean
96
- virtual? : boolean
97
- unique? : boolean
98
- notNull? : boolean
99
- }
100
+ [name: string]: Element & {
101
+ key?: boolean,
102
+ virtual?: boolean,
103
+ unique?: boolean,
104
+ notNull?: boolean,
105
+ },
100
106
  }
101
107
 
102
108
  export interface Association extends type {
103
109
  type: 'cds.Association' | 'cds.Composition'
104
110
  target: FQN
111
+
105
112
  /**
106
113
  * The specified cardinality. to-one = `{max:1}`, to-many = `{max:'*'}`
107
114
  */
108
- cardinality?: { src?: 1; min?: 1 | 0; max?: 1 | '*' }
115
+ cardinality?: { src?: 1, min?: 1 | 0, max?: 1 | '*' }
116
+
109
117
  /**
110
118
  * The parsed on condition in case of unmanaged Associations
111
119
  */
112
120
  on?: predicate
121
+
113
122
  /**
114
123
  * The optionally specified keys in case of managed Associations
115
124
  */
package/apis/env.d.ts CHANGED
@@ -4,17 +4,17 @@
4
4
  * filtered through the currently active profiles, thus highly dependent on the current working
5
5
  * directory and process environment.
6
6
  */
7
- export const env : {
8
- build: any,
9
- hana: any,
10
- i18n: any,
11
- mtx: any,
12
- requires: any,
13
- folders: any,
14
- odata: any,
15
- query: any,
16
- sql: any
17
- } & { [key: string]: any } // to allow additional values we have not yet captured
7
+ export const env: {
8
+ build: any,
9
+ hana: any,
10
+ i18n: any,
11
+ mtx: any,
12
+ requires: any,
13
+ folders: any,
14
+ odata: any,
15
+ query: any,
16
+ sql: any,
17
+ } & { [key: string]: any } // to allow additional values we have not yet captured
18
18
 
19
19
  export const requires: any
20
20
  export const version: string
package/apis/events.d.ts CHANGED
@@ -9,66 +9,102 @@ import * as express from 'express'
9
9
  * @see [capire docs](https://cap.cloud.sap/docs/node.js/events)
10
10
  */
11
11
  export class EventContext {
12
- constructor(properties:{event:string, data?:object, query?:object, headers?:object});
13
- http?: {req: express.Request, res: express.Response}
12
+
13
+ constructor (properties: { event: string, data?: object, query?: object, headers?: object })
14
+ http?: { req: express.Request, res: express.Response }
15
+
14
16
  tenant: string
17
+
15
18
  user: User
19
+
16
20
  id: string
21
+
17
22
  locale: `${string}_${string}`
23
+
18
24
  timestamp: Date
25
+
19
26
  features?: { [key: string]: boolean }
27
+
20
28
  }
21
29
 
22
30
  /**
23
31
  * @see [capire docs](https://cap.cloud.sap/docs/node.js/events)
24
32
  */
25
33
  export class Event extends EventContext {
34
+
26
35
  event: string
36
+
27
37
  data: any
38
+
28
39
  headers: any
40
+
29
41
  }
30
42
 
31
43
  /**
32
44
  * @see [capire docs](https://cap.cloud.sap/docs/node.js/events)
33
45
  */
34
46
  export class Request extends Event {
35
- params: (string | {})[]
47
+
48
+ params: (string | object)[]
49
+
36
50
  method: string
51
+
37
52
  path: string
53
+
38
54
  target: LinkedDefinition
55
+
39
56
  /**
40
57
  * Shortcut to {@link Request.target | target (entity) name}
41
58
  * @see https://cap.cloud.sap/docs/node.js/events#req-entity
42
59
  */
43
60
  entity: string
61
+
44
62
  query: Query
63
+
45
64
  subject: ref
46
65
 
47
- reply(results: any): void
48
-
49
- notify(code: number, message: string, target?: string, args?: any[]): Error
50
- info(code: number, message: string, target?: string, args?: any[]): Error
51
- warn(code: number, message: string, target?: string, args?: any[]): Error
52
- error(code: number, message: string, target?: string, args?: any[]): Error
53
- reject(code: number, message: string, target?: string, args?: any[]): Error
54
-
55
- notify(code: number, message: string, args?: any[]): Error
56
- info(code: number, message: string, args?: any[]): Error
57
- warn(code: number, message: string, args?: any[]): Error
58
- error(code: number, message: string, args?: any[]): Error
59
- reject(code: number, message: string, args?: any[]): Error
60
-
61
- notify(message: string, target?: string, args?: any[]): Error
62
- info(message: string, target?: string, args?: any[]): Error
63
- warn(message: string, target?: string, args?: any[]): Error
64
- error(message: string, target?: string, args?: any[]): Error
65
- reject(message: string, target?: string, args?: any[]): Error
66
-
67
- notify(message: { code?: number | string; message: string; target?: string; args?: any[] }): Error
68
- info(message: { code?: number | string; message: string; target?: string; args?: any[] }): Error
69
- warn(message: { code?: number | string; message: string; target?: string; args?: any[] }): Error
70
- error(message: { code?: number | string; message: string; target?: string; args?: any[], status?: number }): Error
71
- reject(message: { code?: number | string; message: string; target?: string; args?: any[], status?: number }): Error
66
+ reply (results: any): void
67
+
68
+ notify (code: number, message: string, target?: string, args?: any[]): Error
69
+
70
+ info (code: number, message: string, target?: string, args?: any[]): Error
71
+
72
+ warn (code: number, message: string, target?: string, args?: any[]): Error
73
+
74
+ error (code: number, message: string, target?: string, args?: any[]): Error
75
+
76
+ reject (code: number, message: string, target?: string, args?: any[]): Error
77
+
78
+ notify (code: number, message: string, args?: any[]): Error
79
+
80
+ info (code: number, message: string, args?: any[]): Error
81
+
82
+ warn (code: number, message: string, args?: any[]): Error
83
+
84
+ error (code: number, message: string, args?: any[]): Error
85
+
86
+ reject (code: number, message: string, args?: any[]): Error
87
+
88
+ notify (message: string, target?: string, args?: any[]): Error
89
+
90
+ info (message: string, target?: string, args?: any[]): Error
91
+
92
+ warn (message: string, target?: string, args?: any[]): Error
93
+
94
+ error (message: string, target?: string, args?: any[]): Error
95
+
96
+ reject (message: string, target?: string, args?: any[]): Error
97
+
98
+ notify (message: { code?: number | string, message: string, target?: string, args?: any[] }): Error
99
+
100
+ info (message: { code?: number | string, message: string, target?: string, args?: any[] }): Error
101
+
102
+ warn (message: { code?: number | string, message: string, target?: string, args?: any[] }): Error
103
+
104
+ error (message: { code?: number | string, message: string, target?: string, args?: any[], status?: number }): Error
105
+
106
+ reject (message: { code?: number | string, message: string, target?: string, args?: any[], status?: number }): Error
107
+
72
108
  }
73
109
 
74
110
 
@@ -77,7 +113,8 @@ export class Request extends Event {
77
113
  * @see [capire docs](https://cap.cloud.sap/docs/node.js/authentication#cds-user)
78
114
  */
79
115
  export class User {
80
- constructor(obj?: string | { id: string; attr: Record<string, string>; roles: Record<string, string> } | User)
116
+
117
+ constructor (obj?: string | { id: string, attr: Record<string, string>, roles: Array<string> | Record<string, string> } | User)
81
118
  id: string
82
119
 
83
120
  /**
@@ -91,15 +128,22 @@ export class User {
91
128
  tenant: string | undefined
92
129
 
93
130
  attr: Record<string, string>
131
+
94
132
  roles: Array<string> | Record<string, string>
133
+
95
134
  static Privileged: typeof Privileged
96
- is(role: string): boolean
135
+
136
+ is (role: string): boolean
137
+
97
138
  }
98
139
 
99
140
  /**
100
141
  * Subclass for executing code with superuser privileges.
101
142
  */
102
143
  declare class Privileged extends User {
103
- constructor()
104
- is(): boolean
144
+
145
+ constructor ()
146
+
147
+ is (): boolean
148
+
105
149
  }