@cap-js/cds-typer 0.18.1 → 0.19.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/lib/compile.js +1 -1
- package/lib/components/resolver.js +23 -8
- package/lib/visitor.js +2 -2
- package/package.json +2 -2
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.20.0 - TBD
|
|
8
|
+
|
|
9
|
+
## Version 0.19.0 - 2024-03-28
|
|
10
|
+
### Added
|
|
11
|
+
- Support for `cds.Vector`, which will be represented as `string`
|
|
12
|
+
|
|
13
|
+
## Version 0.18.2 - 2024-03-21
|
|
14
|
+
### Fix
|
|
15
|
+
- Resolving `@sap/cds` will now look in the CWD first to ensure a consistent use the same CDS version across different setups
|
|
16
|
+
- Types of function parameters starting with `cds.` are not automatically considered builtin anymore and receive a more thorough check against an allow-list
|
|
8
17
|
|
|
9
18
|
|
|
10
19
|
## Version 0.18.1 - 2024-03-13
|
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')
|
|
@@ -45,6 +45,7 @@ const Builtins = {
|
|
|
45
45
|
Binary: 'string',
|
|
46
46
|
LargeString: 'string',
|
|
47
47
|
LargeBinary: 'Buffer | string | {value: import("stream").Readable, $mediaContentType: string, $mediaContentDispositionFilename?: string, $mediaContentDispositionType?: string}',
|
|
48
|
+
Vector: 'string',
|
|
48
49
|
Integer: 'number',
|
|
49
50
|
UInt8: 'number',
|
|
50
51
|
Int16: 'number',
|
|
@@ -66,6 +67,19 @@ const Builtins = {
|
|
|
66
67
|
Association: 'Array'
|
|
67
68
|
}
|
|
68
69
|
|
|
70
|
+
/**
|
|
71
|
+
* @param {string | string[]} type name or parts of the type name split on dots
|
|
72
|
+
* @returns {string | undefined | false} if t refers to a builtin, the name of the corresponding TS type is returned.
|
|
73
|
+
* If t _looks like_ a builtin (`cds.X`), undefined is returned.
|
|
74
|
+
* If t is obviously not a builtin, false is returned.
|
|
75
|
+
*/
|
|
76
|
+
function resolveBuiltin (t) {
|
|
77
|
+
const path = Array.isArray(t) ? t : t.split('.')
|
|
78
|
+
return path.length === 2 && path[0] === 'cds'
|
|
79
|
+
? Builtins[path[1]]
|
|
80
|
+
: false
|
|
81
|
+
}
|
|
82
|
+
|
|
69
83
|
class Resolver {
|
|
70
84
|
|
|
71
85
|
#caches = {
|
|
@@ -550,13 +564,13 @@ class Resolver {
|
|
|
550
564
|
#resolveTypeName(t, into) {
|
|
551
565
|
const result = into || {}
|
|
552
566
|
const path = t.split('.')
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
result.type =
|
|
567
|
+
const builtin = resolveBuiltin(path)
|
|
568
|
+
if (builtin === undefined) {
|
|
569
|
+
// looks like builtin, but isn't
|
|
570
|
+
throw new Error(`Can not resolve apparent builtin type '${t}' to any CDS type.`)
|
|
571
|
+
} else if (builtin !== false) {
|
|
572
|
+
// builtin
|
|
573
|
+
result.type = builtin
|
|
560
574
|
result.isBuiltin = true
|
|
561
575
|
} else if (t in this.csn.definitions) {
|
|
562
576
|
// user-defined type
|
|
@@ -607,5 +621,6 @@ class Resolver {
|
|
|
607
621
|
}
|
|
608
622
|
|
|
609
623
|
module.exports = {
|
|
610
|
-
Resolver
|
|
624
|
+
Resolver,
|
|
625
|
+
resolveBuiltin
|
|
611
626
|
}
|
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.
|
|
3
|
+
"version": "0.19.0",
|
|
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",
|