@sap/cds 7.3.1 → 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 (107) hide show
  1. package/CHANGELOG.md +58 -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/to/edm.js +8 -3
  18. package/lib/compile/to/gql.js +4 -0
  19. package/lib/dbs/cds-deploy.js +52 -4
  20. package/lib/env/cds-requires.js +27 -15
  21. package/lib/env/defaults.js +1 -0
  22. package/lib/env/schemas/index.js +10 -0
  23. package/lib/index.js +7 -4
  24. package/lib/linked/models.js +8 -5
  25. package/lib/ql/CREATE.js +2 -0
  26. package/lib/ql/DELETE.js +1 -0
  27. package/lib/ql/DROP.js +2 -0
  28. package/lib/ql/INSERT.js +2 -22
  29. package/lib/ql/Query.js +59 -22
  30. package/lib/ql/SELECT.js +5 -0
  31. package/lib/ql/STREAM.js +2 -0
  32. package/lib/ql/UPDATE.js +2 -0
  33. package/lib/ql/UPSERT.js +3 -1
  34. package/lib/ql/cds-ql.js +21 -5
  35. package/lib/ql/infer.js +129 -0
  36. package/lib/req/cds-context.js +8 -5
  37. package/lib/srv/cds-connect.js +3 -1
  38. package/lib/utils/axios.js +4 -2
  39. package/lib/utils/data.js +3 -0
  40. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/error.js +12 -0
  41. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/metadata.js +26 -8
  42. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/batch/BatchProcessor.js +1 -1
  43. package/libx/_runtime/cds-services/adapter/odata-v4/utils/data.js +11 -8
  44. package/libx/_runtime/common/code-ext/worker.js +5 -16
  45. package/libx/_runtime/common/generic/auth/capabilities.js +11 -2
  46. package/libx/_runtime/common/i18n/messages.properties +1 -0
  47. package/libx/_runtime/common/utils/postProcessing.js +1 -1
  48. package/libx/_runtime/common/utils/resolveView.js +20 -1
  49. package/libx/{common → _runtime/common}/utils/ucsn.js +19 -11
  50. package/libx/_runtime/db/expand/expandCQNToJoin.js +2 -2
  51. package/libx/_runtime/db/sql-builder/InsertBuilder.js +6 -1
  52. package/libx/_runtime/db/sql-builder/UpdateBuilder.js +6 -1
  53. package/libx/_runtime/db/sql-builder/dollar.js +7 -7
  54. package/libx/_runtime/fiori/generic/activate.js +2 -2
  55. package/libx/_runtime/fiori/generic/edit.js +25 -45
  56. package/libx/_runtime/fiori/generic/read.js +3 -5
  57. package/libx/_runtime/fiori/lean-draft.js +142 -64
  58. package/libx/_runtime/fiori/utils/delete.js +7 -1
  59. package/libx/_runtime/fiori/utils/handler.js +4 -6
  60. package/libx/_runtime/fiori/utils/lockInfo.js +27 -0
  61. package/libx/_runtime/fiori/utils/where.js +20 -1
  62. package/libx/_runtime/messaging/AMQPWebhookMessaging.js +3 -2
  63. package/libx/_runtime/messaging/Outbox.js +12 -47
  64. package/libx/_runtime/messaging/common-utils/AMQPClient.js +1 -3
  65. package/libx/_runtime/messaging/common-utils/authorizedRequest.js +3 -0
  66. package/libx/_runtime/messaging/common-utils/connections.js +1 -1
  67. package/libx/_runtime/messaging/enterprise-messaging.js +12 -13
  68. package/libx/_runtime/messaging/file-based.js +7 -5
  69. package/libx/_runtime/messaging/redis-messaging.js +10 -11
  70. package/libx/_runtime/messaging/service.js +12 -26
  71. package/libx/_runtime/remote/Service.js +52 -36
  72. package/libx/_runtime/remote/utils/client.js +22 -123
  73. package/libx/odata/afterburner.js +14 -5
  74. package/libx/odata/grammar.peggy +26 -7
  75. package/libx/odata/metadata.js +18 -1
  76. package/libx/odata/parser.js +1 -1
  77. package/libx/odata/service-document.js +0 -1
  78. package/libx/odata/utils.js +19 -3
  79. package/libx/{_runtime/messaging/outbox/utils.js → outbox/index.js} +94 -24
  80. package/libx/rest/middleware/parse.js +1 -1
  81. package/package.json +2 -2
  82. package/apis/connect.d.ts +0 -39
  83. package/bin/utils/modules.js +0 -7
  84. package/bin/utils/term.js +0 -56
  85. package/lib/env/schema.js +0 -9
  86. package/lib/linked/queries.js +0 -41
  87. package/lib/srv/protocols/odata-v2-proxy.js +0 -3699
  88. package/libx/common/asserts.js +0 -0
  89. package/libx/common/crud.js +0 -0
  90. package/libx/common/etag.js +0 -0
  91. package/libx/common/localized.js +0 -0
  92. package/libx/common/managed.js +0 -0
  93. package/libx/common/paging.js +0 -0
  94. package/libx/common/readme.md +0 -4
  95. package/libx/common/sorting.js +0 -0
  96. package/libx/common/temporal.js +0 -0
  97. package/libx/connect/auth.js +0 -0
  98. package/libx/connect/perf.js +0 -0
  99. package/libx/connect/readme.md +0 -3
  100. package/libx/fiori/draft/readme.md +0 -1
  101. package/libx/fiori/readme.md +0 -1
  102. package/libx/hana/readme.md +0 -1
  103. package/libx/msg/readme.md +0 -3
  104. package/libx/readme.md +0 -1
  105. package/libx/sqlite/readme.md +0 -1
  106. /package/libx/_runtime/{messaging/common-utils → common/utils}/waitingTime.js +0 -0
  107. /package/libx/{_runtime/messaging/outbox → outbox}/OutboxRunner.js +0 -0
package/CHANGELOG.md CHANGED
@@ -4,6 +4,61 @@
4
4
  - The format is based on [Keep a Changelog](http://keepachangelog.com/).
5
5
  - This project adheres to [Semantic Versioning](http://semver.org/).
6
6
 
7
+ ## Version 7.4.0 - 2023-11-13
8
+
9
+ ### Added
10
+
11
+ - Any service is outboxable via `srv = cds.outboxed(srv)`
12
+ - Draft: support `HasActiveEntity eq false` by read
13
+ - Check if OData function/action params exist for complex types
14
+ - Remote services: destination option `jwt` set to `null` instructs that an incoming request's JWT shall not be passed to SAP Cloud SDK, e.g., when it shall use a fresh client credentials flow token
15
+ + Example:
16
+ ```json
17
+ "requires": {
18
+ "API_BUSINESS_PARTNER": {
19
+ [...]
20
+ "destinationOptions": {
21
+ "jwt": null
22
+ }
23
+ }
24
+ }
25
+ ```
26
+ - Alpha feature flag `cds.env.fiori.wrap_multiple_errors` to toggle the following behaviour for OData errors meant to be consumed by SAP Fiori Elements:
27
+ In cases where multiple errors occur and the flag is set to `false`, the first error is presented as the top-level error (replacing the generic "multiple errors" wrapper).
28
+ The default value is `true`, but `false` will become the default value in cds^8.
29
+ - On CF, the default keep alive timeout of the server is set to 91s (to exceed the 90s of CF's gorouter)
30
+ - `cds deploy` now auto-fills the `ID_texts` field (which get created for entities marked with `@fiori.draft.enabled`) in csv and json data files with a stable UUID. This way, it does not need to be manually added to data files. Also, as the value is stable (a hash of the semantic key fields `ID` and `locale`), it works with `UPSERT` statements.
31
+
32
+ ### Changed
33
+
34
+ - Default outbox configuration (overridable via `cds.env.requires.outbox = { ... }`):
35
+ + `kind` changed to `persistent-outbox` (was `in-memory-outbox`)
36
+ + `parallel` changed to `true` (i.e., messages are not emitted in sequence)
37
+ - Internal class `OutboxService` is deprecated and will be removed
38
+
39
+ ### Fixed
40
+
41
+ - `req.subject` in lean-draft handlers
42
+ - `cds.odata.batch_limit` wasn't taken into account
43
+ - Enterprise-Messaging: Only set tenant information for multitenant apps
44
+ - Enterprise-Messaging: Race condition in `subscribe` event
45
+ - Draft: delete of active entity is forbidden, if draft exist
46
+ - Draft: sorting of draft entities in `list status: all`
47
+ - Draft: invalid delete draft request now rejects with error
48
+ - Draft: Enhance Draft Edit functionality with exclusive record lock
49
+ - Typings for `req.reject/error/info/warn`
50
+ - Deep delete with mixins on new db layer did not work
51
+ - Special strings like `'$now'`, `'$user'` and `'$uuid'` expanded automatically
52
+ - Only services that are served via OData are precompiled during startup
53
+ - Response status of not existing mocks returned 200 instead of 404
54
+ - Calculation of @Capabilities in case of complex $apply
55
+ - `test.data.reset()` did not delete drafts
56
+ - `resolveView` considers `list` for renamed columns
57
+ - `cds.schema` now loads lazily
58
+ - `odata_new_parser`: `$expand=` no longer throws an error with and is simply ignored
59
+ - `odata_new_parser`: Empty custom query params like `Foo?bar` are ignored
60
+ - `odata_new_parser`: generated wrong CQN for queries like `$filter=false or ref eq 5`
61
+
7
62
  ## Version 7.3.1 - 2023-10-23
8
63
 
9
64
  ### Fixed
@@ -18,7 +73,7 @@
18
73
  - `cds.localized` now caches i18n bundles per locale and per model to speed up repeated usages of the same bundle at runtime, for example, in repeated calls to `cds.compile.for.edmx()`.
19
74
  - Based on `cds.localized` with cached bundles, a new operation `cds.localized.lookup(i18n_key, locale)` is provided.
20
75
  - If env variable `CDS_TEST_ENV_CHECK` is set, `cds.test.in()` detects if `cds.env` was loaded before from a different folder.
21
- - `cds.test.log()` allows to capture and analyse any console log output. `cds.test.verbose()` is now deprecated.
76
+ - `cds.test.log()` allows to capture and analyze any console log output. `cds.test.verbose()` is now deprecated.
22
77
  - Typings for `cds.tx`
23
78
  - Add method `cds.schema.default4(schemaId)` to retrieve json schema based on its id
24
79
  - Support for pseudo role `internal-user` with authentication kind `ias`
@@ -26,7 +81,7 @@
26
81
 
27
82
  ### Changed
28
83
 
29
- - If ommitted in the accept header, `ExponentialDecimals` no longer gets defaulted (to `true`), which violated the OData 4.0 specification.
84
+ - If omitted in the accept header, `ExponentialDecimals` no longer gets defaulted (to `true`), which violated the OData 4.0 specification.
30
85
  This change can _temporarily_ be overridden via `cds.env.odata.defaultExponentialDecimals = 'true/false'`.
31
86
  - Make type signature of `extend.with` more general
32
87
  - `cds.test.data.autoReset()` is deprecated in favor of explicit `cds.test.data.reset()` call, like `beforeEach (test.data.reset)`.
@@ -728,7 +783,7 @@ Content-Length: 145
728
783
  - Signatures for QL operations are now more specific
729
784
  - `basic-auth` does not inherit users of `mocked-auth`
730
785
  - `cds.localize` now ignores i18n files defined outside the project scope.
731
- - Allow `@Capabilities.NavigationRestrictions.RestrictedProperties` to be specified in the format `{ InsertRestrictions.Insertable: false }`
786
+ - Allow `@Capabilities.NavigationRestrictions.RestrictedProperties` to be specified in the format `{ InsertRestrictions: { Insertable: false } }`
732
787
  - Bound actions/functions while calling remote service
733
788
  - `$search`: Search on localized projections/views does not always return the localized data
734
789
  - `cds push` now shows better output for failed extension validations
@@ -0,0 +1,110 @@
1
+ #Text Types
2
+ #
3
+ #XACT: Text with explicit importance for accessibility.
4
+ #XBUT: Button
5
+ #XCKL: Checkbox
6
+ #XFLD: Field label
7
+ #XLNK: Hyperlink
8
+ #XMIT: Menu item (Menu item, either top-level like "File" or lower-level like "Save as...")
9
+ #XMSG: Message
10
+ #XRBL: Radio button
11
+ #XSEL: Selection (Values in a drop-down list, or a status. For example: "In Process", "Shipped" or "Open".)
12
+ #XTIT: Title (or heading) of a non-actionable user interface element like a column, wizard, or screen area.
13
+ #XTOL: Explanatory text for an UI element, such as a tooltip, input help.
14
+ #YINS: Instruction for a user, for example, a permanent text on a screen that introduces a group of fields.
15
+ #----------------------------------------------------------------------------------------------------------------------
16
+ #For text elements that are not supposed to be translated, use the text type NOTR
17
+ #----------------------------------------------------------------------------------------------------------------------
18
+ #Recommended pattern
19
+ #
20
+ #<TextType>:<AdditionalContextInformation>
21
+ #If there is a maximum length restriction, please indicate as shown below.
22
+ #<TextType>,<MaximumLength>:<AdditionalContextInformation>
23
+ #----------------------------------------------------------------------------------------------------------------------
24
+ # This is the resource bundle for foundation
25
+ # __ldi.translation.uuid=dd6c5800-b108-11e8-be90-bd1cf6ac87fb
26
+ #----------------------------------------------------------------------------------------------------------------------
27
+
28
+ #XTIT: Created By (Answer to: "Which user has created a certain entity?")
29
+ CreatedBy=Creado por
30
+
31
+ #XTIT: Created On (Answer to: "When has a certain entity been created?")
32
+ CreatedAt=Fecha de creaci\u00F3n
33
+
34
+ #XTIT: Changed By (Answer to: "Which user has changed a certain entity?")
35
+ ChangedBy=Modificado por
36
+
37
+ #XTIT: Changed On (Answer to: "When has a certain entity been changed?")
38
+ ChangedAt=Modificado el
39
+
40
+ #XTIT: Currency
41
+ Currency=Moneda
42
+
43
+ #XTIT: Currency Code
44
+ CurrencyCode=C\u00F3digo de moneda
45
+
46
+ #XTIT: Currency Code Description
47
+ CurrencyCode.Description=C\u00F3digo de moneda seg\u00FAn especificado por ISO 4217
48
+
49
+ #XTIT: Currency Symbol
50
+ CurrencySymbol=S\u00EDmbolo de moneda
51
+
52
+ #XTIT: Currency Minor Unit Fractions (Answer to: "How many fractions has a currency's minor unit?", e.g. "0" or "2")
53
+ CurrencyMinorUnit=Fracciones unidad secundaria de moneda
54
+
55
+ #XTIT: Country/Region
56
+ Country=Pa\u00EDs/Regi\u00F3n
57
+
58
+ #XTIT: Country/Region Code
59
+ CountryCode=C\u00F3digo de pa\u00EDs/regi\u00F3n
60
+
61
+ #XTIT: Country/Region Code Description
62
+ CountryCode.Description=C\u00F3digo de pa\u00EDs/regi\u00F3n seg\u00FAn especificado por ISO 3166-1
63
+
64
+ #XTIT: Language
65
+ Language=Idioma
66
+
67
+ #XTIT: Language Code
68
+ LanguageCode=C\u00F3digo de idioma
69
+
70
+ #XTIT: Language Code Description
71
+ LanguageCode.Description=C\u00F3digo de idioma seg\u00FAn especificado por ISO 639-1
72
+
73
+ #XTIT: User Identifier
74
+ UserID=ID de usuario
75
+
76
+ #XTIT: Any kind of name
77
+ Name=Nombre
78
+
79
+ #XTIT: Any kind of description
80
+ Description=Descripci\u00F3n
81
+
82
+ #XTOL: A user's unique Indentifier
83
+ UserID.Description=ID \u00FAnico de usuario
84
+
85
+ #XTIT: Admin data for a draft document
86
+ Draft_DraftAdministrativeData=Datos administrativos en borrador
87
+
88
+ #XTIT: Technical ID of a draft document
89
+ Draft_DraftUUID=Borrador (ID t\u00E9cnico)
90
+
91
+ #XTIT: Creation time of a draft
92
+ Draft_CreationDateTime=Borrador creado el
93
+
94
+ #XTIT: User created the draft
95
+ Draft_CreatedByUser=Borrador creado por
96
+
97
+ #XTIT: The current user (me) created the draft
98
+ Draft_DraftIsCreatedByMe=Borrador creado por m\u00ED
99
+
100
+ #XTIT: Time a draft was last changed on
101
+ Draft_LastChangeDateTime=Fecha del \u00FAltimo cambio en borrador
102
+
103
+ #XTIT: User that changed the draft last
104
+ Draft_LastChangedByUser=Autor del \u00FAltimo cambio en borrador
105
+
106
+ #XTIT: User that is working on the draft
107
+ Draft_InProcessByUser=Borrador en proceso por
108
+
109
+ #XTIT: The current user (me) is working on the draft
110
+ Draft_DraftIsProcessedByMe=Borrador en proceso por m\u00ED
package/apis/cds.d.ts CHANGED
@@ -1,24 +1,25 @@
1
1
  import * as ql from './ql'
2
2
 
3
- declare const cds : {}
3
+ declare global {
4
+ const cds : cds_facade
5
+ }
6
+
7
+ export = cds
8
+
9
+ type cds_facade = {}
4
10
  & import('./core').default
5
- & import('./models')
6
- & import('./connect')
7
- & import('./serve').default
8
- & import('./ql').cds_ql
9
- & import('./services').default
11
+ & import('./env').default
12
+ & import('./models').default
13
+ & import('./server').default
10
14
  & import('./services').QueryAPI
15
+ & import('./services').default
16
+ & import('./events').default
17
+ & import('./ql').cds_ql
11
18
  & import('./log')
12
19
  & import('./utils')
13
20
  & import('./test')
14
- export default cds
15
-
16
- export * from './core'
17
- export * from './serve'
18
- export * from './services'
19
21
 
20
22
  declare global {
21
-
22
23
  // these provide the functionality from SELECT, INSERT, etc in the global facade
23
24
  const SELECT: typeof cds.ql.SELECT
24
25
  const INSERT: typeof cds.ql.INSERT
package/apis/core.d.ts CHANGED
@@ -1,68 +1,17 @@
1
- // import types from '../lib/core'
2
- import { ReflectedModel, LinkedModel } from './reflect'
3
- import { CSN as csn, Definition } from './csn'
4
-
5
- type UserInput = string | { id: string; attr: Record<string, string>; roles: Record<string, string> } | User
6
- type Intersect<T extends readonly unknown[]> = T extends [infer Head, ...infer Tail]
7
- ? Head & Intersect<Tail>
8
- : unknown
9
-
10
- export type Association = Definition
11
- export type Composition = Association
12
- export type entity = Definition
13
- export type event = Definition
14
- export type type = Definition
15
- export type array = Definition
16
- export type struct = Definition
17
-
18
-
19
- export class User {
20
- constructor(obj?: UserInput)
21
- id: string
22
-
23
- /**
24
- * @deprecated Use https://cap.cloud.sap/docs/node.js/events#locale instead
25
- */
26
- locale: string
27
-
28
- /**
29
- * @deprecated Use https://cap.cloud.sap/docs/node.js/events#tenant instead
30
- */
31
- tenant: string | undefined
32
-
33
- attr: Record<string, string>
34
- roles: Array<string> | Record<string, string>
35
- static Privileged: typeof Privileged
36
- is(role: string): boolean
37
- }
38
-
39
- /**
40
- * Subclass for executing code with superuser privileges.
41
- */
42
- declare class Privileged extends User {
43
- constructor()
44
- is(): boolean
45
- }
46
-
47
- declare class cds {
48
- /**
49
- * Turns the given plain CSN model into a linked model
50
- * @see [capire](https://cap.cloud.sap/docs/node.js/cds-reflect)
51
- */
52
- linked(model: csn): LinkedModel
53
-
54
- /**
55
- * Turns the given plain CSN model into a reflected model
56
- * @see [capire](https://cap.cloud.sap/docs/node.js/cds-reflect)
57
- */
58
- reflect(model: csn): ReflectedModel
59
-
60
- /**
61
- * Represents the user in a given context.
62
- * @see [capire docs](https://cap.cloud.sap/docs/node.js/authentication#cds-user)
63
- */
64
- User: typeof User
65
-
1
+ import { LinkedAssociation, LinkedEntity, linked } from './linked'
2
+ import * as csn from './csn'
3
+ import { service } from './server'
4
+
5
+ // These are classes actually -> using the new() => interface trick
6
+ export type Association = new() => LinkedAssociation
7
+ export type Composition = new() => LinkedAssociation
8
+ export type entity = new() => LinkedEntity
9
+ export type event = new() => linked & csn.struct
10
+ export type type = new() => linked & csn.type
11
+ export type array = new() => linked & csn.type
12
+ export type struct = new() => linked & csn.struct
13
+
14
+ export default class cds {
66
15
  // infer (query : cqn, model : csn) : LinkedDefinition
67
16
 
68
17
  builtin: {
@@ -71,15 +20,14 @@ declare class cds {
71
20
  * @see [capire](https://cap.cloud.sap/docs/node.js/cds-reflect#cds-builtin-classes)
72
21
  */
73
22
  classes: {
74
- Association: Definition
75
- Composition: Definition
76
- context: Definition
77
- service: Definition
78
- type: Definition
79
- array: Definition
80
- struct: Definition
81
- entity: Definition
82
- event: Definition
23
+ Association: Association
24
+ Composition: Composition
25
+ entity: entity
26
+ event: event
27
+ type: type
28
+ array: array
29
+ struct: struct
30
+ service: service
83
31
  }
84
32
  types: {}
85
33
  }
@@ -130,7 +78,7 @@ declare class cds {
130
78
  * The first usage of `facade.sub` will load the sub module
131
79
  * using standard Node.js's `module.require` functions.
132
80
  */
133
- lazify: <T>(target: T) => T
81
+ lazify <T>(target: T) : T
134
82
 
135
83
  /**
136
84
  * Prepare a node module for lazy-loading submodules instead
@@ -144,39 +92,10 @@ declare class cds {
144
92
  * The first usage of `facade.sub` will load the sub module
145
93
  * using standard Node.js's `module.require` functions.
146
94
  */
147
- lazified: <T>(target: T) => T
148
-
149
- /**
150
- * Provides a graceful shutdown for running servers, by first emitting `cds.emit('shutdown')`.
151
- * @see [capire](https://cap.cloud.sap/docs/node.js/cds-facade#cds-exit)
152
- */
153
- exit(): void
154
-
155
-
156
- /**
157
- * Access to the configuration for Node.js runtime and tools.
158
- * The object is the effective result of configuration merged from various sources,
159
- * filtered through the currently active profiles, thus highly dependent on the current working
160
- * directory and process environment.
161
- */
162
- env : {
163
- build: any,
164
- hana: any,
165
- i18n: any,
166
- mtx: any,
167
- requires: any,
168
- folders: any,
169
- odata: any,
170
- query: any,
171
- sql: any
172
- }
173
-
174
- requires: any
175
- version: string
176
- home: string
177
- root: string
95
+ lazified <T>(target: T) : T
178
96
 
179
97
  }
180
98
 
181
- // & typeof import ('../lib/index')
182
- export default cds
99
+ type Intersect<T extends readonly unknown[]> = T extends [infer Head, ...infer Tail]
100
+ ? Head & Intersect<Tail>
101
+ : unknown
package/apis/cqn.d.ts CHANGED
@@ -1,8 +1,7 @@
1
- import { entity } from "./csn"
1
+ import { entity } from "./csn" // cyclic dependency
2
2
 
3
- export type CQNQuery = SELECT & INSERT & UPDATE & DELETE & CREATE & DROP & UPSERT
4
- export type Query = SELECT | INSERT | UPDATE | DELETE | CREATE | DROP | UPSERT
5
- export type ParsedExpr = expr & { _:string }
3
+ // FIXME: a union type would be more appropriate here
4
+ export type Query = Partial<SELECT & INSERT & UPDATE & DELETE & CREATE & DROP & UPSERT>
6
5
 
7
6
  export type SELECT = {SELECT:{
8
7
  distinct?: true
@@ -16,37 +15,33 @@ export type SELECT = {SELECT:{
16
15
  groupBy? : expr[]
17
16
  orderBy? : ordering_term[]
18
17
  limit?: { rows:val, offset:val }
19
- forUpdate?: { wait: number }
20
- forShareLock?: { wait: number }
21
- search?: _xpr
22
- count?: boolean
23
18
  }}
24
19
 
25
20
  export type INSERT = {INSERT:{
26
- into : name | ref
27
- entries : any[]
21
+ into : ref | name
22
+ entries : data[]
28
23
  columns : string[]
29
- values : any[]
30
- rows : any[]
24
+ values : scalar[]
25
+ rows : scalar[][]
31
26
  as : SELECT
32
27
  }}
33
28
 
34
29
  export type UPSERT = {UPSERT:{
35
- into : name | ref
36
- entries : any[]
30
+ into : ref | name
37
31
  columns : string[]
38
- values : any[]
39
- rows : any[]
32
+ entries : data[]
33
+ values : scalar[]
34
+ rows : scalar[][]
40
35
  }}
41
36
 
42
37
  export type UPDATE = {UPDATE:{
43
- entity : name
38
+ entity : ref | name
44
39
  data : { [key:string] : expr }
45
40
  where? : predicate
46
41
  }}
47
42
 
48
43
  export type DELETE = {DELETE:{
49
- from : name
44
+ from : ref | name
50
45
  where? : predicate
51
46
  }}
52
47
 
@@ -61,6 +56,8 @@ export type DROP = {DROP:{
61
56
  view: ref
62
57
  }}
63
58
 
59
+ type scalar = number | string | boolean | null
60
+ type data = Record<string,any>
64
61
  type name = string
65
62
  type source = ( ref | SELECT ) & { as?: name, join?:name, on?:xpr }
66
63
  export type column_expr = expr & { as?: name, cast?:any, expand?: column_expr[], inline?: column_expr[] }
package/apis/csn.d.ts CHANGED
@@ -1,82 +1,117 @@
1
- import { SELECT, expr, predicate, column_expr } from "./cqn"
1
+ import { SELECT, ref, predicate } from './cqn'
2
2
 
3
- export type csn = CSN
4
-
5
- /** A parsed model. */
3
+ /**
4
+ * A parsed CDS model in CSN object notation.
5
+ */
6
6
  export interface CSN {
7
+ /**
8
+ * The assigned namespace. If parsed from multiple sources,
9
+ * this is the topmost model's namespace, if any, not the
10
+ * ones of imported models.
11
+ */
12
+ namespace?: string
7
13
 
8
- /** The assigned namespace. If parsed from multiple sources, this is the topmost model's namespace, if any, not the ones of imported models. */
9
- namespace? : string
10
-
11
- /** The list of usings in this parsed model. Not available after imports have been resolved into a merged model. */
12
- using? : { name: string, as?: string, from?: string }[]
14
+ /**
15
+ * The list of usings in this parsed model. Not available after
16
+ * imports have been resolved into a merged model.
17
+ */
18
+ requires?: string[]
13
19
 
14
- /** All definitions in the model including those from imported models. */
15
- definitions? : Definitions
20
+ /**
21
+ * All definitions in the model including those from imported models.
22
+ */
23
+ definitions?: Record<FQN, Definition>
16
24
 
17
- /** All extensions in the model including those from imported models. Not available after extensions have been applied. */
18
- extensions? : Definition[]
25
+ /**
26
+ * All extensions in the model including those from imported models.
27
+ * Not available after extensions have been applied.
28
+ */
29
+ extensions?: Extension[]
19
30
 
20
- $sources?: string[]
31
+ /**
32
+ * The names of the files from which this model has been loaded.
33
+ */
34
+ $sources?: string[]
21
35
  }
22
36
 
23
- export interface DefinitionRegistry {
24
- type: type,
25
- struct: struct,
26
- entity: entity,
27
- Association: Association
28
- }
29
- export type Definition = DefinitionRegistry[keyof DefinitionRegistry];
37
+ /**
38
+ * The fully-quality name of a definition.
39
+ */
40
+ export type FQN = string
30
41
 
31
- export interface Definitions {
32
- [name:string]: Definition
33
- }
42
+ /**
43
+ * Definitions are the central elements of a CDS model.
44
+ */
45
+ export type Definition = context & service & type & struct & entity & Association
46
+ // NOTE: If we use & instead of | CSN.definitions values would be reduced to <never>
34
47
 
35
- export type kind = 'context' | 'service' | 'type' | 'entity' | 'element' | 'const' | 'annotation'
36
- export type Element = type & struct & Association & {
37
- kind : 'element' | undefined
48
+ /**
49
+ * Extensions capture extend Foo with { ... } directives.
50
+ */
51
+ export type Extension = {
52
+ extend: FQN
53
+ elements?: { [name: string]: Element }
54
+ includes?: FQN[]
38
55
  }
39
56
 
40
- export interface type {
41
- kind? : kind
42
- type? : string
43
- name : string
57
+ export type Element = type & struct & Association
58
+
59
+ export type kinds = 'type' | 'entity' | 'event' | 'service' | 'context' | 'struct'
60
+
61
+ export interface any_ { kind?: kinds }
62
+ export interface context extends any_ { }
63
+ export interface service extends any_ { }
64
+
65
+ export interface type extends any_ {
66
+ type?: FQN
67
+ items?: type
44
68
  }
45
69
 
46
70
  export interface struct extends type {
47
- /** structs have elements which are in turn Definitions */
48
- elements : { [name:string]: Element }
49
- /** References to definitions to be included. Not available after extensions have been applied. */
50
- include? : string[]
71
+ /**
72
+ * References to definitions to be included.
73
+ * Not available after extensions have been applied.
74
+ */
75
+ includes?: FQN[]
76
+ elements: { [name: string]: Element }
51
77
  }
52
78
 
53
- export interface entity extends struct {
54
- kind : 'entity'
55
- /** Entities with a query signify a view */
56
- query?: SELECT & { cql: string }
57
- /** Elements of entities may have additional qualifiers */
58
- elements : {
59
- [name:string]: Element & {
60
- key? : boolean
61
- virtual? : boolean
62
- unique? : boolean
63
- notNull? : boolean
64
- }
65
- }
66
- keys : {
67
- [name:string]: Definition
79
+ export interface entity extends Omit<struct,'elements'> {
80
+ /**
81
+ * Entities with a query signify a view
82
+ */
83
+ query?: SELECT
84
+ /**
85
+ * Elements of entities may have additional qualifiers
86
+ */
87
+ elements : EntityElements
88
+ // REVISIT: following should move to LinkedCSN
89
+ keys: { [name: string]: Definition }
90
+ drafts: entity
91
+ }
92
+
93
+ export type EntityElements = {
94
+ [name:string]: Element & {
95
+ key? : boolean
96
+ virtual? : boolean
97
+ unique? : boolean
98
+ notNull? : boolean
68
99
  }
69
- drafts: entity
70
100
  }
71
101
 
72
102
  export interface Association extends type {
73
- type : 'cds.Association' | 'cds.Composition'
74
- /** The fully-qualified name of the Association's target entity */
75
- target : string
76
- /** The specified cardinality. to-one = {max:1}, to-many = {max:'*'} */
77
- cardinality? : {src?:1,min?:1|0,max?:1|'*'}
78
- /** The parsed on condition in case of unmanaged Associations */
79
- on? : predicate
80
- /** The optionally specified keys in case of managed Associations */
81
- keys? : column_expr[]
103
+ type: 'cds.Association' | 'cds.Composition'
104
+ target: FQN
105
+ /**
106
+ * The specified cardinality. to-one = {max:1}, to-many = {max:'*'}
107
+ */
108
+ cardinality?: { src?: 1; min?: 1 | 0; max?: 1 | '*' }
109
+ /**
110
+ * The parsed on condition in case of unmanaged Associations
111
+ */
112
+ on?: predicate
113
+ /**
114
+ * The optionally specified keys in case of managed Associations
115
+ */
116
+ keys?: (ref & { as: string })[]
82
117
  }
package/apis/env.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ export default class {
2
+ /**
3
+ * Access to the configuration for Node.js runtime and tools.
4
+ * The object is the effective result of configuration merged from various sources,
5
+ * filtered through the currently active profiles, thus highly dependent on the current working
6
+ * directory and process environment.
7
+ */
8
+ env : {
9
+ build: any,
10
+ hana: any,
11
+ i18n: any,
12
+ mtx: any,
13
+ requires: any,
14
+ folders: any,
15
+ odata: any,
16
+ query: any,
17
+ sql: any
18
+ }
19
+
20
+ requires: any
21
+ version: string
22
+ home: string
23
+ root: string
24
+
25
+ }