@sap/cds 7.3.1 → 7.4.1

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.
Files changed (110) hide show
  1. package/CHANGELOG.md +69 -3
  2. package/_i18n/i18n_es_MX.properties +110 -0
  3. package/apis/cds.d.ts +13 -12
  4. package/apis/core.d.ts +27 -108
  5. package/apis/cqn.d.ts +15 -18
  6. package/apis/csn.d.ts +95 -60
  7. package/apis/env.d.ts +25 -0
  8. package/apis/events.d.ts +125 -0
  9. package/apis/{reflect.d.ts → linked.d.ts} +29 -38
  10. package/apis/models.d.ts +60 -45
  11. package/apis/ql.d.ts +19 -5
  12. package/apis/{serve.d.ts → server.d.ts} +59 -33
  13. package/apis/services.d.ts +76 -147
  14. package/apis/test.d.ts +1 -1
  15. package/bin/serve.js +3 -0
  16. package/lib/compile/cds-compile.js +2 -2
  17. package/lib/compile/etc/csv.js +2 -1
  18. package/lib/compile/to/edm.js +8 -3
  19. package/lib/compile/to/gql.js +4 -0
  20. package/lib/dbs/cds-deploy.js +52 -4
  21. package/lib/env/cds-requires.js +27 -15
  22. package/lib/env/defaults.js +1 -0
  23. package/lib/env/schemas/index.js +10 -0
  24. package/lib/index.js +7 -4
  25. package/lib/linked/models.js +8 -5
  26. package/lib/ql/CREATE.js +2 -0
  27. package/lib/ql/DELETE.js +1 -0
  28. package/lib/ql/DROP.js +2 -0
  29. package/lib/ql/INSERT.js +2 -22
  30. package/lib/ql/Query.js +59 -22
  31. package/lib/ql/SELECT.js +5 -0
  32. package/lib/ql/STREAM.js +2 -0
  33. package/lib/ql/UPDATE.js +2 -0
  34. package/lib/ql/UPSERT.js +3 -1
  35. package/lib/ql/cds-ql.js +21 -5
  36. package/lib/ql/infer.js +129 -0
  37. package/lib/req/cds-context.js +8 -5
  38. package/lib/srv/cds-connect.js +3 -1
  39. package/lib/utils/axios.js +4 -2
  40. package/lib/utils/data.js +3 -0
  41. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/error.js +12 -0
  42. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/metadata.js +27 -9
  43. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/batch/BatchProcessor.js +1 -1
  44. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/serializer/TrustedResourceJsonSerializer.js +8 -1
  45. package/libx/_runtime/cds-services/adapter/odata-v4/utils/data.js +11 -8
  46. package/libx/_runtime/common/code-ext/worker.js +5 -16
  47. package/libx/_runtime/common/generic/auth/capabilities.js +11 -2
  48. package/libx/_runtime/common/i18n/messages.properties +1 -0
  49. package/libx/_runtime/common/utils/postProcessing.js +1 -1
  50. package/libx/_runtime/common/utils/resolveView.js +28 -9
  51. package/libx/{common → _runtime/common}/utils/ucsn.js +19 -11
  52. package/libx/_runtime/db/expand/expandCQNToJoin.js +6 -6
  53. package/libx/_runtime/db/expand/rawToExpanded.js +4 -4
  54. package/libx/_runtime/db/sql-builder/InsertBuilder.js +6 -1
  55. package/libx/_runtime/db/sql-builder/UpdateBuilder.js +6 -1
  56. package/libx/_runtime/db/sql-builder/dollar.js +7 -7
  57. package/libx/_runtime/fiori/generic/activate.js +2 -2
  58. package/libx/_runtime/fiori/generic/edit.js +25 -45
  59. package/libx/_runtime/fiori/generic/read.js +3 -5
  60. package/libx/_runtime/fiori/lean-draft.js +171 -84
  61. package/libx/_runtime/fiori/utils/delete.js +7 -1
  62. package/libx/_runtime/fiori/utils/handler.js +4 -6
  63. package/libx/_runtime/fiori/utils/lockInfo.js +27 -0
  64. package/libx/_runtime/fiori/utils/where.js +20 -1
  65. package/libx/_runtime/messaging/AMQPWebhookMessaging.js +3 -2
  66. package/libx/_runtime/messaging/Outbox.js +12 -47
  67. package/libx/_runtime/messaging/common-utils/AMQPClient.js +1 -3
  68. package/libx/_runtime/messaging/common-utils/authorizedRequest.js +3 -0
  69. package/libx/_runtime/messaging/common-utils/connections.js +1 -1
  70. package/libx/_runtime/messaging/enterprise-messaging.js +12 -13
  71. package/libx/_runtime/messaging/file-based.js +7 -5
  72. package/libx/_runtime/messaging/redis-messaging.js +10 -11
  73. package/libx/_runtime/messaging/service.js +12 -26
  74. package/libx/_runtime/remote/Service.js +52 -36
  75. package/libx/_runtime/remote/utils/client.js +24 -125
  76. package/libx/odata/afterburner.js +16 -6
  77. package/libx/odata/grammar.peggy +26 -7
  78. package/libx/odata/metadata.js +18 -1
  79. package/libx/odata/parser.js +1 -1
  80. package/libx/odata/service-document.js +0 -1
  81. package/libx/odata/utils.js +19 -3
  82. package/libx/{_runtime/messaging/outbox/utils.js → outbox/index.js} +94 -24
  83. package/libx/rest/middleware/parse.js +1 -1
  84. package/package.json +2 -2
  85. package/apis/connect.d.ts +0 -39
  86. package/bin/utils/modules.js +0 -7
  87. package/bin/utils/term.js +0 -56
  88. package/lib/env/schema.js +0 -9
  89. package/lib/linked/queries.js +0 -41
  90. package/lib/srv/protocols/odata-v2-proxy.js +0 -3699
  91. package/libx/common/asserts.js +0 -0
  92. package/libx/common/crud.js +0 -0
  93. package/libx/common/etag.js +0 -0
  94. package/libx/common/localized.js +0 -0
  95. package/libx/common/managed.js +0 -0
  96. package/libx/common/paging.js +0 -0
  97. package/libx/common/readme.md +0 -4
  98. package/libx/common/sorting.js +0 -0
  99. package/libx/common/temporal.js +0 -0
  100. package/libx/connect/auth.js +0 -0
  101. package/libx/connect/perf.js +0 -0
  102. package/libx/connect/readme.md +0 -3
  103. package/libx/fiori/draft/readme.md +0 -1
  104. package/libx/fiori/readme.md +0 -1
  105. package/libx/hana/readme.md +0 -1
  106. package/libx/msg/readme.md +0 -3
  107. package/libx/readme.md +0 -1
  108. package/libx/sqlite/readme.md +0 -1
  109. /package/libx/_runtime/{messaging/common-utils → common/utils}/waitingTime.js +0 -0
  110. /package/libx/{_runtime/messaging/outbox → outbox}/OutboxRunner.js +0 -0
@@ -0,0 +1,125 @@
1
+ import { LinkedDefinition } from './linked'
2
+ import { Query } from './cqn'
3
+ import { ref } from './cqn'
4
+ import * as express from "express"
5
+
6
+
7
+ export default class cds {
8
+
9
+ /**
10
+ * @see [capire docs](https://cap.cloud.sap/docs/node.js/events)
11
+ */
12
+ EventContext: typeof EventContext
13
+
14
+ /**
15
+ * @see [capire docs](https://cap.cloud.sap/docs/node.js/events)
16
+ */
17
+ Event: typeof Event
18
+
19
+ /**
20
+ * @see [capire docs](https://cap.cloud.sap/docs/node.js/events)
21
+ */
22
+ Request: typeof Request
23
+
24
+ /**
25
+ * Represents the user in a given context.
26
+ * @see [capire docs](https://cap.cloud.sap/docs/node.js/authentication#cds-user)
27
+ */
28
+ User: typeof User
29
+ }
30
+
31
+
32
+ /**
33
+ * Represents the invocation context of incoming request and event messages.
34
+ * @see [capire docs](https://cap.cloud.sap/docs/node.js/events)
35
+ */
36
+ export class EventContext {
37
+ constructor(properties:{event:string, data?:object, query?:object, headers:object});
38
+ http?: {req: express.Request, res: express.Response}
39
+ tenant: string
40
+ user: User
41
+ id: string
42
+ locale: `${string}_${string}`
43
+ timestamp: Date
44
+ }
45
+
46
+ /**
47
+ * @see [capire docs](https://cap.cloud.sap/docs/node.js/events)
48
+ */
49
+ export class Event extends EventContext {
50
+ event: string
51
+ data: any
52
+ headers: any
53
+ }
54
+
55
+ /**
56
+ * @see [capire docs](https://cap.cloud.sap/docs/node.js/events)
57
+ */
58
+ export class Request extends Event {
59
+ params: (string | {})[]
60
+ method: string
61
+ path: string
62
+ target: LinkedDefinition
63
+ /**
64
+ * Shortcut to {@link target.name}
65
+ * @see https://cap.cloud.sap/docs/node.js/events#req-entity
66
+ */
67
+ entity: string
68
+ query: Query
69
+ subject: ref
70
+
71
+ reply(results: any): void
72
+
73
+ notify(code: number, message: string, target?: string, args?: any[]): Error
74
+ info(code: number, message: string, target?: string, args?: any[]): Error
75
+ warn(code: number, message: string, target?: string, args?: any[]): Error
76
+ error(code: number, message: string, target?: string, args?: any[]): Error
77
+ reject(code: number, message: string, target?: string, args?: any[]): Error
78
+
79
+ notify(code: number, message: string, args?: any[]): Error
80
+ info(code: number, message: string, args?: any[]): Error
81
+ warn(code: number, message: string, args?: any[]): Error
82
+ error(code: number, message: string, args?: any[]): Error
83
+ reject(code: number, message: string, args?: any[]): Error
84
+
85
+ notify(message: string, target?: string, args?: any[]): Error
86
+ info(message: string, target?: string, args?: any[]): Error
87
+ warn(message: string, target?: string, args?: any[]): Error
88
+ error(message: string, target?: string, args?: any[]): Error
89
+ reject(message: string, target?: string, args?: any[]): Error
90
+
91
+ notify(message: { code?: number | string; message: string; target?: string; args?: any[] }): Error
92
+ info(message: { code?: number | string; message: string; target?: string; args?: any[] }): Error
93
+ warn(message: { code?: number | string; message: string; target?: string; args?: any[] }): Error
94
+ error(message: { code?: number | string; message: string; target?: string; args?: any[], status?: number }): Error
95
+ reject(message: { code?: number | string; message: string; target?: string; args?: any[], status?: number }): Error
96
+ }
97
+
98
+
99
+ export class User {
100
+ constructor(obj?: string | { id: string; attr: Record<string, string>; roles: Record<string, string> } | User)
101
+ id: string
102
+
103
+ /**
104
+ * @deprecated Use https://cap.cloud.sap/docs/node.js/events#locale instead
105
+ */
106
+ locale: string
107
+
108
+ /**
109
+ * @deprecated Use https://cap.cloud.sap/docs/node.js/events#tenant instead
110
+ */
111
+ tenant: string | undefined
112
+
113
+ attr: Record<string, string>
114
+ roles: Array<string> | Record<string, string>
115
+ static Privileged: typeof Privileged
116
+ is(role: string): boolean
117
+ }
118
+
119
+ /**
120
+ * Subclass for executing code with superuser privileges.
121
+ */
122
+ declare class Privileged extends User {
123
+ constructor()
124
+ is(): boolean
125
+ }
@@ -1,39 +1,25 @@
1
- import {
2
- CSN as ParsedModel,
3
- Association as ParsedAssociation,
4
- entity as ParsedEntity,
5
- kind
6
- } from "./csn"
1
+ import { CSN, FQN, Association, Definition, entity, kinds } from "./csn"
7
2
 
3
+ export type LinkedDefinition = linked & Definition & LinkedEntity & LinkedAssociation
4
+ export type Definitions = { [name: string]: LinkedDefinition }
8
5
 
9
- export type Definitions = { [name:string]: Definition }
10
- export type Definition = LinkedDefinition & entity & Association
11
- type Visitor = (def:Definition, name:string, parent:Definition, defs:Definitions) => void
12
- type Filter = string | ((def:Definition) => boolean)
13
-
14
-
15
- /**
16
- * Applying cds.reflect in a model ensures that all contained definitions have their `name` and `kind` filled in.
17
- */
18
- export interface LinkedDefinition {
19
- is (kind: kind | 'Association' | 'Composition') : boolean
20
- name : string
6
+ export interface linked {
7
+ is(kind: kinds | 'Association' | 'Composition'): boolean
8
+ name: FQN
21
9
  }
22
10
 
23
- interface Association extends LinkedDefinition, ParsedAssociation {
24
- is2one : boolean
25
- is2many : boolean
11
+ interface LinkedEntity extends linked, entity {
12
+ constructor (properties: object)
13
+ keys: Definitions
14
+ drafts: LinkedEntity
26
15
  }
27
16
 
28
- interface entity extends LinkedDefinition, ParsedEntity {
29
- keys : Definitions
17
+ interface LinkedAssociation extends linked, Association {
18
+ is2one: boolean
19
+ is2many: boolean
30
20
  }
31
21
 
32
-
33
- export interface LinkedModel extends ReflectedModel {}
34
-
35
-
36
- export interface ReflectedModel extends ParsedModel {
22
+ export interface LinkedCSN extends CSN {
37
23
 
38
24
  /**
39
25
  * Fetches definitions matching the given filter, returning an iterator on them.
@@ -43,13 +29,13 @@ export interface ReflectedModel extends ParsedModel {
43
29
  * let entities = [...m.each('entity')] //> capture all
44
30
  * let entities = m.all('entity') //> equivalent shortcut
45
31
  */
46
- each (x:Filter, defs?: Definitions) : IterableIterator<LinkedDefinition>
32
+ each(x: Filter, defs?: Definitions): IterableIterator<any>
47
33
 
48
34
  /**
49
35
  * Fetches definitions matching the given filter, returning them in an array.
50
36
  * Convenience shortcut for `[...reflect.each('entity')]`
51
37
  */
52
- all (x:Filter, defs?: Definitions) : LinkedDefinition[]
38
+ all(x: Filter, defs?: Definitions): any[]
53
39
 
54
40
  /**
55
41
  * Fetches definitions matching the given filter, returning the first match, if any.
@@ -58,19 +44,21 @@ export interface ReflectedModel extends ParsedModel {
58
44
  * @param {Filter} [x] the filter
59
45
  * @param {Definitions} [defs] the definitions to fetch in, default: `this.definitions`
60
46
  */
61
- find (x:Filter, defs?: Definitions) : LinkedDefinition
47
+ find(x: Filter, defs?: Definitions): any
62
48
 
63
49
  /**
64
50
  * Calls the visitor for each definition matching the given filter.
65
51
  * @see [capire](https://github.wdf.sap.corp/pages/cap/node.js/api#cds-reflect-foreach)
66
52
  */
67
- foreach (x?:Filter, visitor?:Visitor, defs?: Definitions) : this
53
+ foreach(x: Filter, visitor: Visitor, defs?: Definitions): this
54
+ foreach(visitor: Visitor, defs?: Definitions): this
68
55
 
69
56
  /**
70
57
  * Same as foreach but recursively visits each element definition
71
58
  * @see [capire](https://github.wdf.sap.corp/pages/cap/node.js/api#cds-reflect-foreach)
72
59
  */
73
- forall (x?:Filter, visitor?:Visitor, defs?: Definitions) : this
60
+ forall(x: Filter, visitor: Visitor, defs?: Definitions): this
61
+ forall(visitor: Visitor, defs?: Definitions): this
74
62
 
75
63
  /**
76
64
  * Fetches definitions declared as children of a given parent context or service.
@@ -82,7 +70,7 @@ export interface ReflectedModel extends ParsedModel {
82
70
  * @param parent either the parent itself or its fully-qualified name
83
71
  * @param filter an optional filter to apply before picking a child
84
72
  */
85
- childrenOf (parent:LinkedDefinition|string, filter?:((def:Definition)=>boolean)) : Definitions
73
+ childrenOf(parent: any | string, filter?: ((def: LinkedDefinition) => boolean)): Definitions
86
74
 
87
75
  /**
88
76
  * Provides convenient access to the model's top-level definitions.
@@ -98,9 +86,12 @@ export interface ReflectedModel extends ParsedModel {
98
86
  * const {Books,Authors} = model.exports
99
87
  * SELECT.from (Books) .where ({ID:11})
100
88
  */
101
- exports : Definitions & ((namespace: string) => Definitions)
102
- entities : Definitions & ((namespace: string) => Definitions)
103
- services : Definitions & ((namespace: string) => Definitions)
104
- definitions : Definitions
89
+ exports: Definitions & ((namespace: string) => Definitions)
90
+ entities: Definitions & ((namespace: string) => Definitions)
91
+ services: Definitions & ((namespace: string) => Definitions)
92
+ definitions: Definitions
105
93
 
106
94
  }
95
+
96
+ type Visitor = (def: LinkedDefinition, name: string, parent: LinkedDefinition, defs: Definitions) => void
97
+ type Filter = string | ((def: LinkedDefinition) => boolean)
package/apis/models.d.ts CHANGED
@@ -1,9 +1,7 @@
1
- import { Query, expr, _xpr } from "./cqn"
1
+ import { Query as CQN, expr, _xpr } from "./cqn"
2
+ import { LinkedCSN } from "./linked"
2
3
  import { CSN } from "./csn"
3
4
 
4
- type csn = CSN
5
- type cqn = Query
6
-
7
5
  type _flavor = 'parsed' | 'xtended' | 'inferred'
8
6
  type _odata_options = {
9
7
  flavor?: 'v2' | 'v4' | 'w4'| 'x4',
@@ -29,8 +27,13 @@ type EDMX = XML
29
27
  type filename = string
30
28
 
31
29
 
32
- export = cds
33
- declare class cds {
30
+ export default class cds {
31
+
32
+ /**
33
+ * The effective CDS model loaded during bootstrapping, which contains all service and entity definitions,
34
+ * including required services.
35
+ */
36
+ model?: LinkedCSN
34
37
 
35
38
  /**
36
39
  * Provides a set of methods to parse a given model, query or expression.
@@ -38,9 +41,9 @@ declare class cds {
38
41
  */
39
42
  parse : {
40
43
  /** Shortcut to `cds.parse.cdl()` */
41
- (cdl:CDL) : csn
42
- cdl (cdl:CDL) : csn
43
- cql (src:string) : cqn
44
+ (cdl:CDL) : CSN
45
+ cdl (cdl:CDL) : CSN
46
+ cql (src:string) : CQN
44
47
  expr (src:string) : expr
45
48
  xpr (src:string) : _xpr
46
49
  ref (src:string) : string[]
@@ -53,49 +56,49 @@ declare class cds {
53
56
  */
54
57
  compile : {
55
58
  /** Shortcut for `cds.compile.to.csn()` */
56
- cdl (model:CDL, o?:_options) : csn,
59
+ cdl (model:CDL, o?:_options) : CSN,
57
60
 
58
61
  for: {
59
- odata (model:csn, o?:_options) : csn
60
- sql (model:csn, o?:_options) : csn
62
+ odata (model:CSN, o?:_options) : CSN
63
+ sql (model:CSN, o?:_options) : CSN
61
64
  },
62
65
  to: {
63
66
  parsed:{
64
- csn (files:filename[], o?:_options) : Promise<csn>
65
- csn (model:CDL, o?:_options) : csn
67
+ csn (files:filename[], o?:_options) : Promise<CSN>
68
+ csn (model:CDL, o?:_options) : CSN
66
69
  }
67
70
  xtended:{
68
- csn (files:filename[], o?:_options) : Promise<csn>
69
- csn (model:CDL, o?:_options) : csn
71
+ csn (files:filename[], o?:_options) : Promise<CSN>
72
+ csn (model:CDL, o?:_options) : CSN
70
73
  }
71
74
  inferred:{
72
- csn (files:filename[], o?:_options) : Promise<csn>
73
- csn (model:CDL, o?:_options) : csn
75
+ csn (files:filename[], o?:_options) : Promise<CSN>
76
+ csn (model:CDL, o?:_options) : CSN
74
77
  }
75
- csn (files:filename[], o?:_options) : Promise<csn>
76
- csn (model:CDL, o?:_options) : csn
77
- yml (model:csn, o?:_options) : YAML
78
- yaml (model:csn, o?:_options) : YAML
79
- json (model:csn, o?:_options) : JSON
80
- sql (model:csn, o?:_options) : SQL[]
81
- cdl (model:csn, o?:_options) : CDL | Iterable<[CDL,{file:filename}]>
82
- edm (model:csn, o?:_options|_odata_options) : EDM | string
83
- edmx (model:csn, o?:_options|_odata_options) : EDMX | Iterable<[EDMX,{file:filename}]>
84
- hdbcds (model:csn, o?:_options) : SQL | Iterable<[SQL,{file:filename}]>
85
- hdbtable (model:csn, o?:_options) : SQL | Iterable<[SQL,{file:filename}]>
78
+ csn (files:filename[], o?:_options) : Promise<CSN>
79
+ csn (model:CDL, o?:_options) : CSN
80
+ yml (model:CSN, o?:_options) : YAML
81
+ yaml (model:CSN, o?:_options) : YAML
82
+ json (model:CSN, o?:_options) : JSON
83
+ sql (model:CSN, o?:_options) : SQL[]
84
+ cdl (model:CSN, o?:_options) : CDL | Iterable<[CDL,{file:filename}]>
85
+ edm (model:CSN, o?:_options|_odata_options) : EDM | string
86
+ edmx (model:CSN, o?:_options|_odata_options) : EDMX | Iterable<[EDMX,{file:filename}]>
87
+ hdbcds (model:CSN, o?:_options) : SQL | Iterable<[SQL,{file:filename}]>
88
+ hdbtable (model:CSN, o?:_options) : SQL | Iterable<[SQL,{file:filename}]>
86
89
  }
87
90
 
88
91
  /** Fluent API variant */
89
- (model: csn | CDL) : {
92
+ (model: CSN | CDL) : {
90
93
  for: {
91
- odata (o?:_options) : csn
92
- sql (o?:_options) : csn
94
+ odata (o?:_options) : CSN
95
+ sql (o?:_options) : CSN
93
96
  },
94
97
  to: {
95
- parsed:{ csn (o?:_options) : csn }
96
- xtended:{ csn (o?:_options) : csn }
97
- inferred:{ csn (o?:_options) : csn }
98
- csn (o?:_options) : csn
98
+ parsed:{ csn (o?:_options) : CSN }
99
+ xtended:{ csn (o?:_options) : CSN }
100
+ inferred:{ csn (o?:_options) : CSN }
101
+ csn (o?:_options) : CSN
99
102
  yml (o?:_options) : YAML
100
103
  yaml (o?:_options) : YAML
101
104
  json (o?:_options) : JSON
@@ -111,14 +114,14 @@ declare class cds {
111
114
  /** Async fluent variant reading from files */
112
115
  (files: filename[]) : {
113
116
  for: {
114
- odata (o?:_options) : Promise<csn>
115
- sql (o?:_options) : Promise<csn>
117
+ odata (o?:_options) : Promise<CSN>
118
+ sql (o?:_options) : Promise<CSN>
116
119
  },
117
120
  to: {
118
- parsed:{ csn (o?:_options) : Promise <csn> }
119
- xtended:{ csn (o?:_options) : Promise <csn> }
120
- inferred:{ csn (o?:_options) : Promise <csn> }
121
- csn (o?:_options) : Promise <csn>
121
+ parsed:{ csn (o?:_options) : Promise <CSN> }
122
+ xtended:{ csn (o?:_options) : Promise <CSN> }
123
+ inferred:{ csn (o?:_options) : Promise <CSN> }
124
+ csn (o?:_options) : Promise <CSN>
122
125
  yml (o?:_options) : Promise <YAML>
123
126
  yaml (o?:_options) : Promise <YAML>
124
127
  json (o?:_options) : Promise <JSON>
@@ -138,18 +141,18 @@ declare class cds {
138
141
  * Essentially a shortcut for `cds.compile.to.csn(files)`
139
142
  * @param {string} files - filenames of models or if folder containing models
140
143
  */
141
- get(files: '*' | filename | filename[], o?:_options) : Promise<csn>
144
+ get(files: '*' | filename | filename[], o?:_options) : Promise<CSN>
142
145
 
143
146
  /**
144
147
  * Shortcut for `cds.get(files, 'inferred')`
145
148
  * @param {string} files - filenames of models or if folder containing models
146
149
  */
147
- load(files: '*' | filename | filename[], o?:_options) : Promise<csn>
150
+ load(files: '*' | filename | filename[], o?:_options) : Promise<CSN>
148
151
 
149
152
  /**
150
153
  * Emitted whenever a model is loaded using cds.load().
151
154
  */
152
- on (event : 'loaded', listener : (model : csn) => void) : this
155
+ on (event : 'loaded', listener : (model : CSN) => void) : this
153
156
 
154
157
 
155
158
  /**
@@ -162,4 +165,16 @@ declare class cds {
162
165
  */
163
166
  resolve (files: '*' | filename | filename[]) : filename[] | undefined
164
167
 
168
+ /**
169
+ * Turns the given plain CSN model into a linked model
170
+ * @see [capire](https://cap.cloud.sap/docs/node.js/cds-reflect)
171
+ */
172
+ linked(model: CSN): LinkedCSN
173
+
174
+ /**
175
+ * Turns the given plain CSN model into a reflected model
176
+ * @see [capire](https://cap.cloud.sap/docs/node.js/cds-reflect)
177
+ */
178
+ reflect(model: CSN): LinkedCSN
179
+
165
180
  }
package/apis/ql.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { Definition } from "./csn"
1
+ import { CSN, Definition, EntityElements } from "./csn"
2
2
  import * as CQN from "./cqn"
3
3
  import { Constructable, ArrayConstructable, SingularType } from "./internal/inference"
4
+ import { LinkedEntity } from "./linked"
4
5
 
5
- export type CQNQuery = CQN.CQNQuery
6
6
  export type Query = CQN.Query
7
7
 
8
8
  export class ConstructedQuery {
@@ -146,7 +146,7 @@ export class SELECT<T> extends ConstructedQuery {
146
146
  static one : SELECT_one & { from: SELECT_one }
147
147
  static distinct : typeof SELECT
148
148
  static from : SELECT_from
149
- from: TaggedTemplateQueryPart<this>
149
+ from: SELECT_from & TaggedTemplateQueryPart<this>
150
150
  & ((entity: Definition | string, primaryKey? : PK, projection? : Projection<unknown>) => this)
151
151
  byKey (primaryKey? : PK) : this
152
152
  columns: TaggedTemplateQueryPart<this>
@@ -172,8 +172,10 @@ export class SELECT<T> extends ConstructedQuery {
172
172
  forUpdate ({wait}? : {wait?: number}) : this
173
173
  alias (as: string) : this
174
174
 
175
+ elements: EntityElements
175
176
 
176
- // Not yet public
177
+
178
+ // Not yet public
177
179
  // fullJoin (other: string, as: string) : this
178
180
  // leftJoin (other: string, as: string) : this
179
181
  // rightJoin (other: string, as: string) : this
@@ -183,7 +185,12 @@ export class SELECT<T> extends ConstructedQuery {
183
185
  // & ((...expr : string[]) => this)
184
186
  // & ((predicate:object) => this)
185
187
 
186
- SELECT : CQN.SELECT["SELECT"]
188
+ SELECT : CQN.SELECT["SELECT"] & {
189
+ forUpdate?: { wait: number }
190
+ forShareLock?: { wait: number }
191
+ search?: CQN.predicate
192
+ count?: boolean
193
+ }
187
194
  }
188
195
 
189
196
 
@@ -200,6 +207,7 @@ TaggedTemplateQueryPart<Awaitable<SELECT<unknown>, InstanceType<any>>>
200
207
  => Awaitable<SELECT<SingularType<T>>, SingularType<T>>)
201
208
 
202
209
  & ((entity: Definition | string, primaryKey? : PK, projection? : Projection<unknown>) => SELECT<any>)
210
+ & ((entity: LinkedEntity | string, primaryKey? : PK, projection? : Projection<unknown>) => SELECT<any>)
203
211
  & (<T> (entity: T[], projection? : Projection<T>) => Awaitable<SELECT<T>, T>)
204
212
  & (<T> (entity: T[], primaryKey : PK, projection? : Projection<T>) => Awaitable<SELECT<T>, T>)
205
213
  & (<T> (entity: {new():T}, projection? : Projection<T>) => Awaitable<SELECT<T>, T>)
@@ -219,6 +227,7 @@ type SELECT_from =
219
227
  => Awaitable<SELECT<SingularType<T>>, InstanceType<SingularType<T>>>) // when specifying a key, we expect a single element as result
220
228
  // calling with definition
221
229
  & ((entity: Definition | string, primaryKey? : PK, projection? : Projection<unknown>) => SELECT<any>)
230
+ & ((entity: LinkedEntity | string, primaryKey? : PK, projection? : Projection<unknown>) => SELECT<any>)
222
231
  // calling with concrete list
223
232
  & (<T> (entity: T[], projection? : Projection<T>) => SELECT<T> & Promise<T[]>)
224
233
  & (<T> (entity: T[], primaryKey : PK, projection? : Projection<T>) => Awaitable<SELECT<T>, T>)
@@ -228,6 +237,7 @@ export class INSERT<T> extends ConstructedQuery {
228
237
  static into : (<T extends ArrayConstructable<any>> (entity:T, entries? : object | object[]) => INSERT<SingularType<T>>)
229
238
  & (TaggedTemplateQueryPart<INSERT<unknown>>)
230
239
  & ((entity : Definition | string, entries? : object | object[]) => INSERT<any>)
240
+ & ((entity : LinkedEntity | string, entries? : object | object[]) => INSERT<any>)
231
241
  & (<T> (entity:Constructable<T>, entries? : object | object[]) => INSERT<T>)
232
242
  & (<T> (entity:T, entries? : T | object | object[]) => INSERT<T>)
233
243
 
@@ -249,6 +259,7 @@ export class UPSERT<T> extends ConstructedQuery {
249
259
  static into : (<T extends ArrayConstructable<any>> (entity:T, entries? : object | object[]) => UPSERT<SingularType<T>>)
250
260
  & (TaggedTemplateQueryPart<UPSERT<unknown>>)
251
261
  & ((entity : Definition | string, entries? : object | object[]) => UPSERT<any>)
262
+ & ((entity : LinkedEntity | string, entries? : object | object[]) => UPSERT<any>)
252
263
  & (<T> (entity:Constructable<T>, entries? : object | object[]) => UPSERT<T>)
253
264
  & (<T> (entity:T, entries? : T | object | object[]) => UPSERT<T>)
254
265
 
@@ -283,6 +294,7 @@ export class UPDATE<T> extends ConstructedQuery {
283
294
  static entity <T extends ArrayConstructable<any>> (entity:T, primaryKey? : PK) : UPDATE<SingularType<T>>
284
295
 
285
296
  static entity (entity : Definition | string, primaryKey? : PK) : UPDATE<any>
297
+ static entity (entity : LinkedEntity | string, primaryKey? : PK) : UPDATE<any>
286
298
  static entity <T> (entity:Constructable<T>, primaryKey? : PK) : UPDATE<T>
287
299
  static entity <T> (entity:T, primaryKey? : PK) : UPDATE<T>
288
300
  byKey (primaryKey? : PK) : this
@@ -301,10 +313,12 @@ export class UPDATE<T> extends ConstructedQuery {
301
313
 
302
314
  export class CREATE<T> extends ConstructedQuery {
303
315
  static entity (entity : Definition | string) : CREATE<any>
316
+ static entity (entity : LinkedEntity | string) : CREATE<any>
304
317
  CREATE : CQN.CREATE["CREATE"]
305
318
  }
306
319
 
307
320
  export class DROP<T> extends ConstructedQuery {
308
321
  static entity (entity : Definition | string) : DROP<any>
322
+ static entity (entity : LinkedEntity | string) : DROP<any>
309
323
  DROP : CQN.DROP["DROP"]
310
324
  }
@@ -1,41 +1,50 @@
1
1
  import { Service, ServiceImpl } from "./services"
2
- import { LinkedDefinition } from "./reflect"
3
- import { csn } from "./csn"
2
+ import { CSN } from "./csn"
4
3
  import * as http from "http"
5
4
  import { Application } from "express"
6
5
 
7
- // export const Service : _Service
6
+ export default class cds {
8
7
 
9
- interface _fluent {
10
- from (model : string | csn) : this
11
- to (protocol: string) : this
12
- at (path: string) : this
13
- in (app: Application) : this
14
- with (impl: ServiceImpl | string) : this
15
- // (req,res) : void
16
- }
8
+ connect: {
9
+ /**
10
+ * Connects to a specific datasource.
11
+ * @see [capire](https://cap.cloud.sap/docs/node.js/cds-connect#cds-connect-to)
12
+ */
13
+ to(datasource: string, options?: cds_connect_options): Promise<Service>
17
14
 
18
- // these are temporary types until the API has been properly typed.
19
- interface service_options {
20
- service?: string | unknown,
21
- from?: '*' | 'all' | string | unknown,
22
- [key: string]: unknown
23
- }
15
+ /**
16
+ * Connects to a specific datasource via options.
17
+ * @see [capire](https://cap.cloud.sap/docs/node.js/cds-connect#cds-connect-to)
18
+ */
19
+ to(options: cds_connect_options): Promise<Service>
24
20
 
25
- export default cds_serve
26
- declare class cds_serve {
21
+ /**
22
+ * Connects the primary datasource.
23
+ * @see [capire](https://cap.cloud.sap/docs/node.js/cds-connect)
24
+ */
25
+ (options?: string | cds_connect_options): Promise<typeof cds> //> cds.connect(<options>)
26
+ }
27
+
28
+ /**
29
+ * The default bootstrap function as loaded from server.js
30
+ */
31
+ server: Function
27
32
 
28
33
  /**
29
34
  * Constructs service providers from respective service definitions
30
35
  * @see [capire](https://cap.cloud.sap/docs/node.js/cds-serve)
31
36
  */
32
- serve (service : string, options?: service_options) : _fluent & Promise<cds_services>
37
+ serve (service : string, options?: {
38
+ service?: string,
39
+ from?: '*' | 'all' | string,
40
+ [key: string]: unknown
41
+ }) : Promise<cds_services> & cds_serve_fluent
42
+
33
43
 
34
44
  /**
35
- * The default bootstrap function as loaded from server.js
45
+ * Emitted whenever a specific service is connected for the first time.
36
46
  */
37
- server: cds_server
38
-
47
+ on(event: 'connect', listener: (srv: Service) => void): this
39
48
 
40
49
 
41
50
  /**
@@ -83,27 +92,44 @@ declare class cds_serve {
83
92
  */
84
93
  service : service
85
94
 
86
- /**
87
- * The effective CDS model loaded during bootstrapping, which contains all service and entity definitions,
88
- * including required services.
89
- */
90
- model?: csn
95
+ /**
96
+ * Provides a graceful shutdown for running servers, by first emitting `cds.emit('shutdown')`.
97
+ * @see [capire](https://cap.cloud.sap/docs/node.js/cds-facade#cds-exit)
98
+ */
99
+ exit(): void
91
100
 
92
101
  }
93
102
 
94
- export type service = LinkedDefinition & {
103
+ export type service = {
95
104
  /**
96
105
  * Dummy wrapper for service implementation functions.
97
106
  * Use that in modules to get IntelliSense.
98
107
  */
99
108
  impl (impl: ServiceImpl) : typeof impl
100
- impl <T> (srv:T, impl: ( this: T, srv: (T) ) => any) : typeof impl
109
+ // impl <T> (srv:T, impl: ( this: T, srv: (T) ) => any) : typeof impl
110
+
101
111
  /**
102
112
  * Array of all services constructed.
103
113
  */
104
- providers : Service
114
+ providers : Service[]
105
115
  }
106
116
 
107
117
 
108
- declare type cds_services = { [name:string]: Service }
109
- declare type cds_server = Function
118
+ type cds_services = { [name:string]: Service }
119
+
120
+ interface cds_serve_fluent {
121
+ from (model : string | CSN) : this
122
+ to (protocol: string) : this
123
+ at (path: string) : this
124
+ in (app: Application) : this
125
+ with (impl: ServiceImpl | string) : this
126
+ // (req,res) : void
127
+ }
128
+
129
+ interface cds_connect_options {
130
+ impl?: string,
131
+ service?: string,
132
+ kind?: string,
133
+ model?: string,
134
+ credentials?: object
135
+ }