@sap/cds 7.3.0 → 7.4.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.
Files changed (109) hide show
  1. package/CHANGELOG.md +65 -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 +124 -0
  9. package/apis/{reflect.d.ts → linked.d.ts} +27 -38
  10. package/apis/models.d.ts +60 -45
  11. package/apis/ql.d.ts +11 -5
  12. package/apis/{serve.d.ts → server.d.ts} +57 -31
  13. package/apis/services.d.ts +74 -145
  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/for/lean_drafts.js +1 -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 +8 -5
  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/cds-utils.js +9 -2
  41. package/lib/utils/data.js +3 -0
  42. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/error.js +12 -0
  43. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/metadata.js +26 -8
  44. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/batch/BatchProcessor.js +1 -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 +20 -1
  51. package/libx/{common → _runtime/common}/utils/ucsn.js +19 -11
  52. package/libx/_runtime/db/expand/expandCQNToJoin.js +2 -2
  53. package/libx/_runtime/db/sql-builder/InsertBuilder.js +6 -1
  54. package/libx/_runtime/db/sql-builder/UpdateBuilder.js +6 -1
  55. package/libx/_runtime/db/sql-builder/dollar.js +7 -7
  56. package/libx/_runtime/fiori/generic/activate.js +2 -2
  57. package/libx/_runtime/fiori/generic/edit.js +25 -45
  58. package/libx/_runtime/fiori/generic/read.js +3 -5
  59. package/libx/_runtime/fiori/lean-draft.js +142 -64
  60. package/libx/_runtime/fiori/utils/delete.js +7 -1
  61. package/libx/_runtime/fiori/utils/handler.js +4 -6
  62. package/libx/_runtime/fiori/utils/lockInfo.js +27 -0
  63. package/libx/_runtime/fiori/utils/where.js +20 -1
  64. package/libx/_runtime/messaging/AMQPWebhookMessaging.js +3 -2
  65. package/libx/_runtime/messaging/Outbox.js +12 -47
  66. package/libx/_runtime/messaging/common-utils/AMQPClient.js +1 -3
  67. package/libx/_runtime/messaging/common-utils/authorizedRequest.js +3 -0
  68. package/libx/_runtime/messaging/common-utils/connections.js +1 -1
  69. package/libx/_runtime/messaging/enterprise-messaging.js +12 -13
  70. package/libx/_runtime/messaging/file-based.js +7 -5
  71. package/libx/_runtime/messaging/redis-messaging.js +10 -11
  72. package/libx/_runtime/messaging/service.js +12 -26
  73. package/libx/_runtime/remote/Service.js +52 -36
  74. package/libx/_runtime/remote/utils/client.js +22 -123
  75. package/libx/odata/afterburner.js +14 -5
  76. package/libx/odata/grammar.peggy +26 -7
  77. package/libx/odata/metadata.js +18 -1
  78. package/libx/odata/parser.js +1 -1
  79. package/libx/odata/service-document.js +0 -1
  80. package/libx/odata/utils.js +19 -3
  81. package/libx/{_runtime/messaging/outbox/utils.js → outbox/index.js} +94 -24
  82. package/libx/rest/middleware/parse.js +1 -1
  83. package/package.json +2 -2
  84. package/apis/connect.d.ts +0 -39
  85. package/bin/utils/modules.js +0 -7
  86. package/bin/utils/term.js +0 -56
  87. package/lib/env/schema.js +0 -9
  88. package/lib/linked/queries.js +0 -41
  89. package/lib/srv/protocols/odata-v2-proxy.js +0 -3699
  90. package/libx/common/asserts.js +0 -0
  91. package/libx/common/crud.js +0 -0
  92. package/libx/common/etag.js +0 -0
  93. package/libx/common/localized.js +0 -0
  94. package/libx/common/managed.js +0 -0
  95. package/libx/common/paging.js +0 -0
  96. package/libx/common/readme.md +0 -4
  97. package/libx/common/sorting.js +0 -0
  98. package/libx/common/temporal.js +0 -0
  99. package/libx/connect/auth.js +0 -0
  100. package/libx/connect/perf.js +0 -0
  101. package/libx/connect/readme.md +0 -3
  102. package/libx/fiori/draft/readme.md +0 -1
  103. package/libx/fiori/readme.md +0 -1
  104. package/libx/hana/readme.md +0 -1
  105. package/libx/msg/readme.md +0 -3
  106. package/libx/readme.md +0 -1
  107. package/libx/sqlite/readme.md +0 -1
  108. /package/libx/_runtime/{messaging/common-utils → common/utils}/waitingTime.js +0 -0
  109. /package/libx/{_runtime/messaging/outbox → outbox}/OutboxRunner.js +0 -0
@@ -0,0 +1,124 @@
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
+ http?: {req: express.Request, res: express.Response}
38
+ tenant: string
39
+ user: User
40
+ id: string
41
+ locale: `${string}_${string}`
42
+ timestamp: Date
43
+ }
44
+
45
+ /**
46
+ * @see [capire docs](https://cap.cloud.sap/docs/node.js/events)
47
+ */
48
+ export class Event extends EventContext {
49
+ event: string
50
+ data: any
51
+ headers: {}
52
+ }
53
+
54
+ /**
55
+ * @see [capire docs](https://cap.cloud.sap/docs/node.js/events)
56
+ */
57
+ export class Request extends Event {
58
+ params: (string | {})[]
59
+ method: string
60
+ path: string
61
+ target: LinkedDefinition
62
+ /**
63
+ * Shortcut to {@link target.name}
64
+ * @see https://cap.cloud.sap/docs/node.js/events#req-entity
65
+ */
66
+ entity: string
67
+ query: Query
68
+ subject: ref
69
+
70
+ reply(results: any): void
71
+
72
+ notify(code: number, message: string, target?: string, args?: any[]): Error
73
+ info(code: number, message: string, target?: string, args?: any[]): Error
74
+ warn(code: number, message: string, target?: string, args?: any[]): Error
75
+ error(code: number, message: string, target?: string, args?: any[]): Error
76
+ reject(code: number, message: string, target?: string, args?: any[]): Error
77
+
78
+ notify(code: number, message: string, args?: any[]): Error
79
+ info(code: number, message: string, args?: any[]): Error
80
+ warn(code: number, message: string, args?: any[]): Error
81
+ error(code: number, message: string, args?: any[]): Error
82
+ reject(code: number, message: string, args?: any[]): Error
83
+
84
+ notify(message: string, target?: string, args?: any[]): Error
85
+ info(message: string, target?: string, args?: any[]): Error
86
+ warn(message: string, target?: string, args?: any[]): Error
87
+ error(message: string, target?: string, args?: any[]): Error
88
+ reject(message: string, target?: string, args?: any[]): Error
89
+
90
+ notify(message: { code?: number | string; message: string; target?: string; args?: any[] }): Error
91
+ info(message: { code?: number | string; message: string; target?: string; args?: any[] }): Error
92
+ warn(message: { code?: number | string; message: string; target?: string; args?: any[] }): Error
93
+ error(message: { code?: number | string; message: string; target?: string; args?: any[], status?: number }): Error
94
+ reject(message: { code?: number | string; message: string; target?: string; args?: any[], status?: number }): Error
95
+ }
96
+
97
+
98
+ export class User {
99
+ constructor(obj?: string | { id: string; attr: Record<string, string>; roles: Record<string, string> } | User)
100
+ id: string
101
+
102
+ /**
103
+ * @deprecated Use https://cap.cloud.sap/docs/node.js/events#locale instead
104
+ */
105
+ locale: string
106
+
107
+ /**
108
+ * @deprecated Use https://cap.cloud.sap/docs/node.js/events#tenant instead
109
+ */
110
+ tenant: string | undefined
111
+
112
+ attr: Record<string, string>
113
+ roles: Array<string> | Record<string, string>
114
+ static Privileged: typeof Privileged
115
+ is(role: string): boolean
116
+ }
117
+
118
+ /**
119
+ * Subclass for executing code with superuser privileges.
120
+ */
121
+ declare class Privileged extends User {
122
+ constructor()
123
+ is(): boolean
124
+ }
@@ -1,39 +1,23 @@
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
+ keys: Definitions
26
13
  }
27
14
 
28
- interface entity extends LinkedDefinition, ParsedEntity {
29
- keys : Definitions
15
+ interface LinkedAssociation extends linked, Association {
16
+ is2one: boolean
17
+ is2many: boolean
30
18
  }
31
19
 
32
-
33
- export interface LinkedModel extends ReflectedModel {}
34
-
35
-
36
- export interface ReflectedModel extends ParsedModel {
20
+ export interface LinkedCSN extends CSN {
37
21
 
38
22
  /**
39
23
  * Fetches definitions matching the given filter, returning an iterator on them.
@@ -43,13 +27,13 @@ export interface ReflectedModel extends ParsedModel {
43
27
  * let entities = [...m.each('entity')] //> capture all
44
28
  * let entities = m.all('entity') //> equivalent shortcut
45
29
  */
46
- each (x:Filter, defs?: Definitions) : IterableIterator<LinkedDefinition>
30
+ each(x: Filter, defs?: Definitions): IterableIterator<any>
47
31
 
48
32
  /**
49
33
  * Fetches definitions matching the given filter, returning them in an array.
50
34
  * Convenience shortcut for `[...reflect.each('entity')]`
51
35
  */
52
- all (x:Filter, defs?: Definitions) : LinkedDefinition[]
36
+ all(x: Filter, defs?: Definitions): any[]
53
37
 
54
38
  /**
55
39
  * Fetches definitions matching the given filter, returning the first match, if any.
@@ -58,19 +42,21 @@ export interface ReflectedModel extends ParsedModel {
58
42
  * @param {Filter} [x] the filter
59
43
  * @param {Definitions} [defs] the definitions to fetch in, default: `this.definitions`
60
44
  */
61
- find (x:Filter, defs?: Definitions) : LinkedDefinition
45
+ find(x: Filter, defs?: Definitions): any
62
46
 
63
47
  /**
64
48
  * Calls the visitor for each definition matching the given filter.
65
49
  * @see [capire](https://github.wdf.sap.corp/pages/cap/node.js/api#cds-reflect-foreach)
66
50
  */
67
- foreach (x?:Filter, visitor?:Visitor, defs?: Definitions) : this
51
+ foreach(x: Filter, visitor: Visitor, defs?: Definitions): this
52
+ foreach(visitor: Visitor, defs?: Definitions): this
68
53
 
69
54
  /**
70
55
  * Same as foreach but recursively visits each element definition
71
56
  * @see [capire](https://github.wdf.sap.corp/pages/cap/node.js/api#cds-reflect-foreach)
72
57
  */
73
- forall (x?:Filter, visitor?:Visitor, defs?: Definitions) : this
58
+ forall(x: Filter, visitor: Visitor, defs?: Definitions): this
59
+ forall(visitor: Visitor, defs?: Definitions): this
74
60
 
75
61
  /**
76
62
  * Fetches definitions declared as children of a given parent context or service.
@@ -82,7 +68,7 @@ export interface ReflectedModel extends ParsedModel {
82
68
  * @param parent either the parent itself or its fully-qualified name
83
69
  * @param filter an optional filter to apply before picking a child
84
70
  */
85
- childrenOf (parent:LinkedDefinition|string, filter?:((def:Definition)=>boolean)) : Definitions
71
+ childrenOf(parent: any | string, filter?: ((def: LinkedDefinition) => boolean)): Definitions
86
72
 
87
73
  /**
88
74
  * Provides convenient access to the model's top-level definitions.
@@ -98,9 +84,12 @@ export interface ReflectedModel extends ParsedModel {
98
84
  * const {Books,Authors} = model.exports
99
85
  * SELECT.from (Books) .where ({ID:11})
100
86
  */
101
- exports : Definitions & ((namespace: string) => Definitions)
102
- entities : Definitions & ((namespace: string) => Definitions)
103
- services : Definitions & ((namespace: string) => Definitions)
104
- definitions : Definitions
87
+ exports: Definitions & ((namespace: string) => Definitions)
88
+ entities: Definitions & ((namespace: string) => Definitions)
89
+ services: Definitions & ((namespace: string) => Definitions)
90
+ definitions: Definitions
105
91
 
106
92
  }
93
+
94
+ type Visitor = (def: LinkedDefinition, name: string, parent: LinkedDefinition, defs: Definitions) => void
95
+ 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,7 @@
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
4
 
5
- export type CQNQuery = CQN.CQNQuery
6
5
  export type Query = CQN.Query
7
6
 
8
7
  export class ConstructedQuery {
@@ -146,7 +145,7 @@ export class SELECT<T> extends ConstructedQuery {
146
145
  static one : SELECT_one & { from: SELECT_one }
147
146
  static distinct : typeof SELECT
148
147
  static from : SELECT_from
149
- from: TaggedTemplateQueryPart<this>
148
+ from: SELECT_from & TaggedTemplateQueryPart<this>
150
149
  & ((entity: Definition | string, primaryKey? : PK, projection? : Projection<unknown>) => this)
151
150
  byKey (primaryKey? : PK) : this
152
151
  columns: TaggedTemplateQueryPart<this>
@@ -172,8 +171,10 @@ export class SELECT<T> extends ConstructedQuery {
172
171
  forUpdate ({wait}? : {wait?: number}) : this
173
172
  alias (as: string) : this
174
173
 
174
+ elements: EntityElements
175
175
 
176
- // Not yet public
176
+
177
+ // Not yet public
177
178
  // fullJoin (other: string, as: string) : this
178
179
  // leftJoin (other: string, as: string) : this
179
180
  // rightJoin (other: string, as: string) : this
@@ -183,7 +184,12 @@ export class SELECT<T> extends ConstructedQuery {
183
184
  // & ((...expr : string[]) => this)
184
185
  // & ((predicate:object) => this)
185
186
 
186
- SELECT : CQN.SELECT["SELECT"]
187
+ SELECT : CQN.SELECT["SELECT"] & {
188
+ forUpdate?: { wait: number }
189
+ forShareLock?: { wait: number }
190
+ search?: CQN.predicate
191
+ count?: boolean
192
+ }
187
193
  }
188
194
 
189
195
 
@@ -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,21 +92,22 @@ 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 = any & {
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
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
  */
@@ -105,5 +115,21 @@ export type service = LinkedDefinition & {
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
+ }