@cap-js/cds-typer 0.23.0 → 0.24.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/CHANGELOG.md +10 -1
- package/cds-plugin.js +8 -3
- package/lib/visitor.js +6 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,7 +4,16 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
|
5
5
|
The format is based on [Keep a Changelog](http://keepachangelog.com/).
|
|
6
6
|
|
|
7
|
-
## Version 0.
|
|
7
|
+
## Version 0.25.0 - TBD
|
|
8
|
+
|
|
9
|
+
## Version 0.24.0 - 2024-07-18
|
|
10
|
+
### Fixed
|
|
11
|
+
- Suppressed an error that would incorrectly point out naming clashes when an entity was named in singular inflection in the model
|
|
12
|
+
- CDS aspects now also generate a aspect-function in singular inflection, similar to how entities do
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
- Aspects generate named classes again so that tooltips will show more meaningful provenance for properties
|
|
16
|
+
- The TypeScript task for `cds build` no longer looks for tsconfig.json to determine if the project has TS nature and instead checks the dependencies in the project's package.json for an occurrence of `typescript`
|
|
8
17
|
|
|
9
18
|
## Version 0.23.0 - 2024-07-04
|
|
10
19
|
### Fixed
|
package/cds-plugin.js
CHANGED
|
@@ -10,9 +10,14 @@ const DEBUG = cds.debug('cli|build')
|
|
|
10
10
|
const BUILD_CONFIG = 'tsconfig.cdsbuild.json'
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* Check if a
|
|
13
|
+
* Check if the project is a TypeScript project by looking for a dependency on TypeScript.
|
|
14
|
+
* @returns {boolean}
|
|
14
15
|
*/
|
|
15
|
-
const
|
|
16
|
+
const isTypeScriptProject = () => {
|
|
17
|
+
if (!fs.existsSync('package.json')) return false
|
|
18
|
+
const pkg = require(path.resolve('package.json'))
|
|
19
|
+
return Boolean(pkg.devDependencies?.typescript || pkg.dependencies?.typescript)
|
|
20
|
+
}
|
|
16
21
|
|
|
17
22
|
/**
|
|
18
23
|
* Check if separate tsconfig file that is used for building the project.
|
|
@@ -56,7 +61,7 @@ if (!cds?.version || cds.version < '8.0.0') {
|
|
|
56
61
|
// requires @sap/cds-dk version >= 7.5.0
|
|
57
62
|
cds.build?.register?.('typescript', class extends cds.build.Plugin {
|
|
58
63
|
static taskDefaults = { src: '.' }
|
|
59
|
-
static hasTask() { return
|
|
64
|
+
static hasTask() { return isTypeScriptProject() }
|
|
60
65
|
|
|
61
66
|
// lower priority than the nodejs task
|
|
62
67
|
get priority() { return -1 }
|
package/lib/visitor.js
CHANGED
|
@@ -166,7 +166,7 @@ class Visitor {
|
|
|
166
166
|
|
|
167
167
|
// CLASS ASPECT
|
|
168
168
|
buffer.addIndentedBlock(`export function ${identAspect(clean)}<TBase extends new (...args: any[]) => object>(Base: TBase) {`, () => {
|
|
169
|
-
buffer.addIndentedBlock(`return class extends ${ancestors} {`, () => {
|
|
169
|
+
buffer.addIndentedBlock(`return class ${clean} extends ${ancestors} {`, () => {
|
|
170
170
|
const enums = []
|
|
171
171
|
for (let [ename, element] of Object.entries(entity.elements ?? {})) {
|
|
172
172
|
if (element.target && /\.texts?/.test(element.target)) {
|
|
@@ -250,7 +250,9 @@ class Visitor {
|
|
|
250
250
|
}
|
|
251
251
|
|
|
252
252
|
// as types are not inflected, their singular will always clash and there is also no plural for them anyway -> skip
|
|
253
|
-
if
|
|
253
|
+
// if the user defined their entities in singular form we would also have a false positive here -> skip
|
|
254
|
+
const namespacedSingular = `${ns.asNamespace()}.${singular}`
|
|
255
|
+
if (!isType(entity) && namespacedSingular !== fq && namespacedSingular in this.csn.xtended.definitions) {
|
|
254
256
|
LOG.error(
|
|
255
257
|
`Derived singular '${singular}' for your entity '${fq}', already exists. The resulting types will be erronous. Consider using '@singular:'/ '@plural:' annotations in your model or move the offending declarations into different namespaces to resolve this collision.`
|
|
256
258
|
)
|
|
@@ -372,14 +374,14 @@ class Visitor {
|
|
|
372
374
|
|
|
373
375
|
#printAspect(fq, aspect) {
|
|
374
376
|
LOG.debug(`Printing aspect ${fq}`)
|
|
375
|
-
const { namespace, entityName } = this.entityRepository.getByFq(fq)
|
|
377
|
+
const { namespace, entityName, inflection } = this.entityRepository.getByFq(fq)
|
|
376
378
|
const file = this.fileRepository.getNamespaceFile(namespace)
|
|
377
379
|
// aspects are technically classes and can therefore be added to the list of defined classes.
|
|
378
380
|
// Still, when using them as mixins for a class, they need to already be defined.
|
|
379
381
|
// So we separate them into another buffer which is printed before the classes.
|
|
380
382
|
file.addClass(entityName, fq)
|
|
381
383
|
file.aspects.add(`// the following represents the CDS aspect '${entityName}'`)
|
|
382
|
-
this.#aspectify(fq, aspect, file.aspects, { cleanName:
|
|
384
|
+
this.#aspectify(fq, aspect, file.aspects, { cleanName: inflection.singular })
|
|
383
385
|
}
|
|
384
386
|
|
|
385
387
|
#printEvent(fq, event) {
|