@cap-js/cds-typer 0.18.1 → 0.18.2
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 +5 -0
- package/lib/compile.js +1 -1
- package/lib/components/resolver.js +22 -8
- package/lib/visitor.js +2 -2
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
|
|
|
6
6
|
|
|
7
7
|
## Version 0.19.0 - TBD
|
|
8
8
|
|
|
9
|
+
## Version 0.18.2 - 2024-03-21
|
|
10
|
+
### Fix
|
|
11
|
+
- Resolving `@sap/cds` will now look in the CWD first to ensure a consistent use the same CDS version across different setups
|
|
12
|
+
- Types of function parameters starting with `cds.` are not automatically considered builtin anymore and receive a more thorough check against an allow-list
|
|
13
|
+
|
|
9
14
|
|
|
10
15
|
## Version 0.18.1 - 2024-03-13
|
|
11
16
|
### Fix
|
package/lib/compile.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require('fs')
|
|
4
4
|
const { normalize } = require('path')
|
|
5
|
-
const cds = require('@sap/cds')
|
|
5
|
+
const cds = require(require.resolve('@sap/cds', { paths: [process.cwd(), __dirname] }))
|
|
6
6
|
const util = require('./util')
|
|
7
7
|
const { writeout } = require('./file')
|
|
8
8
|
const { Logger } = require('./logging')
|
|
@@ -66,6 +66,19 @@ const Builtins = {
|
|
|
66
66
|
Association: 'Array'
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
/**
|
|
70
|
+
* @param {string | string[]} type name or parts of the type name split on dots
|
|
71
|
+
* @returns {string | undefined | false} if t refers to a builtin, the name of the corresponding TS type is returned.
|
|
72
|
+
* If t _looks like_ a builtin (`cds.X`), undefined is returned.
|
|
73
|
+
* If t is obviously not a builtin, false is returned.
|
|
74
|
+
*/
|
|
75
|
+
function resolveBuiltin (t) {
|
|
76
|
+
const path = Array.isArray(t) ? t : t.split('.')
|
|
77
|
+
return path.length === 2 && path[0] === 'cds'
|
|
78
|
+
? Builtins[path[1]]
|
|
79
|
+
: false
|
|
80
|
+
}
|
|
81
|
+
|
|
69
82
|
class Resolver {
|
|
70
83
|
|
|
71
84
|
#caches = {
|
|
@@ -550,13 +563,13 @@ class Resolver {
|
|
|
550
563
|
#resolveTypeName(t, into) {
|
|
551
564
|
const result = into || {}
|
|
552
565
|
const path = t.split('.')
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
result.type =
|
|
566
|
+
const builtin = resolveBuiltin(path)
|
|
567
|
+
if (builtin === undefined) {
|
|
568
|
+
// looks like builtin, but isn't
|
|
569
|
+
throw new Error(`Can not resolve apparent builtin type '${t}' to any CDS type.`)
|
|
570
|
+
} else if (builtin !== false) {
|
|
571
|
+
// builtin
|
|
572
|
+
result.type = builtin
|
|
560
573
|
result.isBuiltin = true
|
|
561
574
|
} else if (t in this.csn.definitions) {
|
|
562
575
|
// user-defined type
|
|
@@ -607,5 +620,6 @@ class Resolver {
|
|
|
607
620
|
}
|
|
608
621
|
|
|
609
622
|
module.exports = {
|
|
610
|
-
Resolver
|
|
623
|
+
Resolver,
|
|
624
|
+
resolveBuiltin
|
|
611
625
|
}
|
package/lib/visitor.js
CHANGED
|
@@ -6,7 +6,7 @@ const { amendCSN, isView, isUnresolved, propagateForeignKeys, isDraftEnabled, is
|
|
|
6
6
|
// eslint-disable-next-line no-unused-vars
|
|
7
7
|
const { SourceFile, FileRepository, baseDefinitions, Buffer } = require('./file')
|
|
8
8
|
const { FlatInlineDeclarationResolver, StructuredInlineDeclarationResolver } = require('./components/inline')
|
|
9
|
-
const { Resolver } = require('./components/resolver')
|
|
9
|
+
const { Resolver, resolveBuiltin } = require('./components/resolver')
|
|
10
10
|
const { Logger } = require('./logging')
|
|
11
11
|
const { docify } = require('./components/wrappers')
|
|
12
12
|
const { csnToEnumPairs, propertyToInlineEnumName, isInlineEnumType, stringifyEnumType } = require('./components/enum')
|
|
@@ -338,7 +338,7 @@ class Visitor {
|
|
|
338
338
|
#stringifyFunctionParamType(type, file) {
|
|
339
339
|
// if type.type is not 'cds.String', 'cds.Integer', ..., then we are actually looking
|
|
340
340
|
// at a named enum type. In that case also resolve that type name
|
|
341
|
-
return type.enum && type.type
|
|
341
|
+
return type.enum && resolveBuiltin(type.type)
|
|
342
342
|
? stringifyEnumType(csnToEnumPairs(type))
|
|
343
343
|
: this.inlineDeclarationResolver.getPropertyDatatype(this.resolver.resolveAndRequire(type, file))
|
|
344
344
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cap-js/cds-typer",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.2",
|
|
4
4
|
"description": "Generates .ts files for a CDS model to receive code completion in VS Code",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": "github:cap-js/cds-typer",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"cds-typer": "./lib/cli.js"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@sap/cds": ">=
|
|
40
|
+
"@sap/cds": ">=7.7"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@babel/eslint-parser": "^7.23.3",
|