@cap-js/cds-typer 0.32.1 → 0.33.1

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/cds-plugin.js CHANGED
@@ -4,10 +4,10 @@ const cds = require('@sap/cds')
4
4
  const util = require('util')
5
5
  const exec = util.promisify(require('child_process').exec)
6
6
  const typer = require('./lib/compile')
7
-
8
7
  const { fs, path } = cds.utils
9
8
  const DEBUG = cds.debug('cli|build')
10
9
  const BUILD_CONFIG = 'tsconfig.cdsbuild.json'
10
+ const { configuration } = require('./lib/config')
11
11
 
12
12
  /**
13
13
  * Check if the project is a TypeScript project by looking for a dependency on TypeScript.
@@ -52,93 +52,103 @@ const rmFiles = async (dir, exts) => fs.existsSync(dir)
52
52
  )
53
53
  : undefined
54
54
 
55
- // FIXME: remove once cds7 has been phased out
56
- if (!cds?.version || cds.version < '8.0.0') {
57
- DEBUG?.('typescript build task requires @sap/cds-dk version >= 8.0.0, skipping registration')
58
- return
59
- }
60
-
61
- // requires @sap/cds-dk version >= 7.5.0
62
- cds.build?.register?.('typescript', class extends cds.build.Plugin {
63
- static taskDefaults = { src: '.' }
64
- static hasTask() { return isTypeScriptProject() }
65
-
66
- // lower priority than the nodejs task
67
- get priority() { return -1 }
68
-
69
- get #appFolder () { return cds?.env?.folders?.app ?? 'app' }
70
-
71
- /**
72
- * cds.env > tsconfig.compilerOptions.paths > '@cds-models' (default)
73
- */
74
- get #modelDirectoryName () {
75
- const outputDirectory = cds.env.typer?.outputDirectory
76
- if (outputDirectory) return outputDirectory
77
- try {
78
- // expected format: { '#cds-models/*': [ './@cds-models/*' ] }
79
- // ^^^^^^^^^^^
80
- // relevant part - may be changed by user
81
- const config = JSON.parse(fs.readFileSync ('tsconfig.json', 'utf8'))
82
- const alias = config.compilerOptions.paths['#cds-models/*'][0]
83
- const directory = alias.match(/(?:\.\/)?(.*)\/\*/)[1]
84
- return normalize(directory) // could contain forward slashes in tsconfig.json
85
- } catch {
86
- DEBUG?.('tsconfig.json not found, not parsable, or inconclusive. Using default model directory name')
87
- }
88
- return '@cds-models'
55
+ // IIFE to be able to return early
56
+ ;(() => {
57
+ // FIXME: remove once cds7 has been phased out
58
+ if (!cds?.version || cds.version < '8.0.0') {
59
+ DEBUG?.('typescript build task requires @sap/cds-dk version >= 8.0.0, skipping registration')
60
+ return
89
61
  }
90
62
 
91
- init() {
92
- this.task.dest = path.join(cds.root, cds.env.build.target, cds.env.folders.srv)
63
+ // by checking configuration instead of cds.env, we make sure the user can set
64
+ // this configuration in both camelCase and snake_case.
65
+ if (configuration.buildTask === false) { // unset is considered true
66
+ DEBUG?.('skipping typescript build task registration based on configuration option')
67
+ return
93
68
  }
94
69
 
95
- async #runCdsTyper () {
96
- DEBUG?.('running cds-typer')
97
- cds.env.typer ??= {}
98
- cds.env.typer.outputDirectory ??= this.#modelDirectoryName
99
- await typer.compileFromFile('*')
100
- }
70
+ // requires @sap/cds-dk version >= 7.5.0
71
+ cds.build?.register?.('typescript', class extends cds.build.Plugin {
72
+ static taskDefaults = { src: '.' }
73
+ static hasTask() { return isTypeScriptProject() }
74
+
75
+ // lower priority than the nodejs task
76
+ get priority() { return -1 }
77
+
78
+ get #appFolder () { return cds?.env?.folders?.app ?? 'app' }
79
+
80
+ /**
81
+ * cds.env > tsconfig.compilerOptions.paths > '@cds-models' (default)
82
+ */
83
+ get #modelDirectoryName () {
84
+ const outputDirectory = cds.env.typer?.outputDirectory
85
+ if (outputDirectory) return outputDirectory
86
+ try {
87
+ // expected format: { '#cds-models/*': [ './@cds-models/*' ] }
88
+ // ^^^^^^^^^^^
89
+ // relevant part - may be changed by user
90
+ const config = JSON.parse(fs.readFileSync ('tsconfig.json', 'utf8'))
91
+ const alias = config.compilerOptions.paths['#cds-models/*'][0]
92
+ const directory = alias.match(/(?:\.\/)?(.*)\/\*/)[1]
93
+ return normalize(directory) // could contain forward slashes in tsconfig.json
94
+ } catch {
95
+ DEBUG?.('tsconfig.json not found, not parsable, or inconclusive. Using default model directory name')
96
+ }
97
+ return '@cds-models'
98
+ }
101
99
 
102
- async #buildWithConfig () {
103
- // possibly referencing their tsconfig.json via "extends", specifying the "compilerOptions.outDir" and
104
- // manually adding irrelevant folders (read: gen/ and app/) to the "exclude" array.
105
- DEBUG?.(`building with config ${BUILD_CONFIG}`)
106
- return exec(`npx tsc --project ${BUILD_CONFIG}`)
107
- }
100
+ init() {
101
+ this.task.dest = path.join(cds.root, cds.env.build.target, cds.env.folders.srv)
102
+ }
108
103
 
109
- async #buildWithoutConfig () {
110
- DEBUG?.('building without config')
111
- // this will include gen/ that was created by the nodejs task
112
- // _within_ the project directory. So we need to remove it afterwards.
113
- await exec(`npx tsc --outDir "${this.task.dest.replace(/\\/g, '/')}"`) // see https://github.com/cap-js/cds-typer/issues/374
114
- rmDirIfExists(path.join(this.task.dest, cds.env.build.target))
115
- rmDirIfExists(path.join(this.task.dest, this.#appFolder))
116
- }
104
+ async #runCdsTyper () {
105
+ DEBUG?.('running cds-typer')
106
+ cds.env.typer ??= {}
107
+ cds.env.typer.outputDirectory ??= this.#modelDirectoryName
108
+ await typer.compileFromFile('*')
109
+ }
117
110
 
118
- async #copyCleanModel (buildDirCdsModels) {
119
- // copy models again, to revert transpilation thereof.
120
- // We only need the index.js files in un-transpiled form.
121
- await this.copy(this.#modelDirectoryName).to(buildDirCdsModels)
122
- await rmFiles(buildDirCdsModels, ['.ts'])
123
- }
111
+ async #buildWithConfig () {
112
+ // possibly referencing their tsconfig.json via "extends", specifying the "compilerOptions.outDir" and
113
+ // manually adding irrelevant folders (read: gen/ and app/) to the "exclude" array.
114
+ DEBUG?.(`building with config ${BUILD_CONFIG}`)
115
+ return exec(`npx tsc --project ${BUILD_CONFIG}`)
116
+ }
124
117
 
125
- async build() {
126
- await this.#runCdsTyper()
127
- const buildDirCdsModels = path.join(this.task.dest, this.#modelDirectoryName)
128
- // remove the js files generated by the nodejs buildtask,
129
- // leaving only json, cds, and other static files
130
- await rmFiles(this.task.dest, ['.js', '.ts'])
131
-
132
- try {
133
- await (buildConfigExists()
134
- ? this.#buildWithConfig()
135
- : this.#buildWithoutConfig()
136
- )
137
- } catch (error) {
138
- throw error.stdout
139
- ? new Error(error.stdout)
140
- : error
118
+ async #buildWithoutConfig () {
119
+ DEBUG?.('building without config')
120
+ // this will include gen/ that was created by the nodejs task
121
+ // _within_ the project directory. So we need to remove it afterwards.
122
+ await exec(`npx tsc --outDir "${this.task.dest.replace(/\\/g, '/')}"`) // see https://github.com/cap-js/cds-typer/issues/374
123
+ rmDirIfExists(path.join(this.task.dest, cds.env.build.target))
124
+ rmDirIfExists(path.join(this.task.dest, this.#appFolder))
141
125
  }
142
- this.#copyCleanModel(buildDirCdsModels)
143
- }
144
- })
126
+
127
+ async #copyCleanModel (buildDirCdsModels) {
128
+ // copy models again, to revert transpilation thereof.
129
+ // We only need the index.js files in un-transpiled form.
130
+ await this.copy(this.#modelDirectoryName).to(buildDirCdsModels)
131
+ await rmFiles(buildDirCdsModels, ['.ts'])
132
+ }
133
+
134
+ async build() {
135
+ await this.#runCdsTyper()
136
+ const buildDirCdsModels = path.join(this.task.dest, this.#modelDirectoryName)
137
+ // remove the js files generated by the nodejs buildtask,
138
+ // leaving only json, cds, and other static files
139
+ await rmFiles(this.task.dest, ['.js', '.ts'])
140
+
141
+ try {
142
+ await (buildConfigExists()
143
+ ? this.#buildWithConfig()
144
+ : this.#buildWithoutConfig()
145
+ )
146
+ } catch (error) {
147
+ throw error.stdout
148
+ ? new Error(error.stdout)
149
+ : error
150
+ }
151
+ this.#copyCleanModel(buildDirCdsModels)
152
+ }
153
+ })
154
+ })()
package/lib/cli.js CHANGED
@@ -192,11 +192,19 @@ const flags = enrichFlagSchema({
192
192
  desc: `If set to true, floating point properties are generated${EOL}as IEEE754 compatible '(number | string)' instead of 'number'.`,
193
193
  default: 'false'
194
194
  }),
195
+ legacyBinaryTypes: parameterTypes.boolean({
196
+ desc: `If set to true, Binary and LargeBinary are generated${EOL}as strings.`,
197
+ default: 'false'
198
+ }),
195
199
  targetModuleType: {
196
200
  desc: `Output format for generated .js files.${EOL}Setting it to auto tries to derive the module type from${EOL}the package.json and falls back to CJS.`,
197
201
  allowed: ['esm', 'cjs', 'auto'],
198
202
  default: 'auto'
199
- }
203
+ },
204
+ buildTask: parameterTypes.boolean({
205
+ desc: `If set to true, the typescript build task will not be registered/ executed.${EOL}This value must be set in your project configuration.${EOL}Passing it as parameter to the cds-typer CLI has no effect.`,
206
+ default: 'true'
207
+ })
200
208
  })
201
209
 
202
210
  const hint = () => 'Missing or invalid parameter(s). Call with --help for more details.'
@@ -81,6 +81,8 @@ export type CdsTime = ${timeRegex};
81
81
  * @see {@link CdsDate}
82
82
  */
83
83
  export type CdsTimestamp = string;
84
+
85
+ export type CdsMap = { [key: string]: unknown };
84
86
  `)
85
87
 
86
88
  module.exports = { baseDefinitions }
@@ -122,9 +122,13 @@ const isInlineEnumType = (element, csn) => element.enum
122
122
  * ```
123
123
  * @param {string} name - the enum name
124
124
  * @param {[string, string][]} kvs - a list of key-value pairs. Values that are falsey are replaced by
125
+ * @param {import('../printers/javascript').Printer} jsp - the printer to use
125
126
  */
126
127
  // ??= for inline enums. If there is some static property of that name, we don't want to override it (for example: ".actions"
127
- const stringifyEnumImplementation = (name, kvs) => `module.exports.${name} ??= { ${kvs.map(([k,v]) => `${normalise(k)}: ${v}`).join(', ')} }`
128
+ const stringifyEnumImplementation = (name, kvs, jsp) => jsp.printExport(
129
+ name,
130
+ `{ ${kvs.map(([k,v]) => `${normalise(k)}: ${v}`).join(', ')} }`,
131
+ { coalesce: true })
128
132
 
129
133
 
130
134
  module.exports = {
package/lib/file.js CHANGED
@@ -577,7 +577,7 @@ class SourceFile extends File {
577
577
  .concat(jsp.printSingleLineComment('actions'))
578
578
  .concat(this.operations.names.map(name => jsp.printExport(name, stringIdent(name))))
579
579
  .concat(jsp.printSingleLineComment('enums'))
580
- .concat(this.enums.data.map(({name, kvs}) => stringifyEnumImplementation(name, kvs)))
580
+ .concat(this.enums.data.map(({name, kvs}) => stringifyEnumImplementation(name, kvs, jsp)))
581
581
  .join('\n') + '\n'
582
582
  }
583
583
  }
@@ -48,10 +48,11 @@ class JavaScriptPrinter {
48
48
  * @abstract
49
49
  * @param {string} name - name the export should be known as
50
50
  * @param {string} value - the value of the export
51
+ * @param {{coalesce?: boolean}} [options] - additional options
51
52
  * @returns {string}
52
53
  */
53
54
  // eslint-disable-next-line no-unused-vars
54
- printExport (name, value) {
55
+ printExport (name, value, options = {}) {
55
56
  throw Error('not implemented')
56
57
  }
57
58
 
@@ -88,9 +89,12 @@ class ESMPrinter extends JavaScriptPrinter {
88
89
  }
89
90
 
90
91
  /** @type {JavaScriptPrinter['printExport']} */
91
- printExport (name, value) {
92
+ printExport (name, value, options) {
93
+ const op = options?.coalesce
94
+ ? '??='
95
+ : '='
92
96
  return name.includes('.')
93
- ? `${name} = ${value}`
97
+ ? `${name} ${op} ${value}`
94
98
  : `export const ${name} = ${value}`
95
99
  }
96
100
 
@@ -117,8 +121,11 @@ class CJSPrinter extends JavaScriptPrinter {
117
121
  }
118
122
 
119
123
  /** @type {JavaScriptPrinter['printExport']} */
120
- printExport (name, value) {
121
- return `module.exports.${name} = ${value}`
124
+ printExport (name, value, options) {
125
+ const op = options?.coalesce
126
+ ? '??='
127
+ : '='
128
+ return `module.exports.${name} ${op} ${value}`
122
129
  }
123
130
 
124
131
  /** @type {JavaScriptPrinter['printDefaultExport']} */
@@ -6,9 +6,9 @@ class BuiltinResolver {
6
6
  #builtins = {
7
7
  UUID: 'string',
8
8
  String: 'string',
9
- Binary: 'string',
9
+ Binary: 'Buffer',
10
10
  LargeString: 'string',
11
- LargeBinary: 'Buffer | string | {value: import("stream").Readable, $mediaContentType: string, $mediaContentDispositionFilename?: string, $mediaContentDispositionType?: string}',
11
+ LargeBinary: 'import("stream").Readable',
12
12
  Vector: 'string',
13
13
  Integer: 'number',
14
14
  UInt8: 'number',
@@ -21,6 +21,7 @@ class BuiltinResolver {
21
21
  Float: 'number',
22
22
  Double: 'number',
23
23
  Boolean: 'boolean',
24
+ Map: '__.CdsMap',
24
25
  // note: the date-related types are strings on purpose, which reflects their runtime behaviour
25
26
  Date: '__.CdsDate', // yyyy-mm-dd
26
27
  DateTime: '__.CdsDateTime', // yyyy-mm-dd + time + TZ (precision: seconds)
@@ -34,14 +35,19 @@ class BuiltinResolver {
34
35
  /**
35
36
  * @param {object} options - additional resolution options
36
37
  * @param {boolean} [options.IEEE754Compatible] - if true, the Decimal, DecimalFloat, Float, and Double types are also allowed to be strings
38
+ * @param {boolean} [options.legacyBinaryTypes] - if true, the Binary and LargeBinary types are strings
37
39
  */
38
- constructor ({ IEEE754Compatible } = {}) {
40
+ constructor ({ IEEE754Compatible, legacyBinaryTypes } = {}) {
39
41
  if (IEEE754Compatible) {
40
42
  this.#builtins.Decimal = '(number | string)'
41
43
  this.#builtins.DecimalFloat = '(number | string)'
42
44
  this.#builtins.Float = '(number | string)'
43
45
  this.#builtins.Double = '(number | string)'
44
46
  }
47
+ if (legacyBinaryTypes) {
48
+ this.#builtins.Binary = 'string'
49
+ this.#builtins.LargeBinary = 'Buffer | string | {value: import("stream").Readable, $mediaContentType: string, $mediaContentDispositionFilename?: string, $mediaContentDispositionType?: string}'
50
+ }
45
51
  this.#builtins = Object.freeze(this.#builtins)
46
52
  }
47
53
 
@@ -32,7 +32,7 @@ class Resolver {
32
32
  this.visitor = visitor
33
33
 
34
34
  /** @type {BuiltinResolver} */
35
- this.builtinResolver = new BuiltinResolver({ IEEE754Compatible: configuration.IEEE754Compatible })
35
+ this.builtinResolver = new BuiltinResolver({ IEEE754Compatible: configuration.IEEE754Compatible, legacyBinaryTypes: configuration.legacyBinaryTypes })
36
36
 
37
37
  /** @type {Library[]} */
38
38
  this.libraries = [new Library(require.resolve('../../library/cds.hana.ts'))]
package/lib/typedefs.d.ts CHANGED
@@ -206,6 +206,10 @@ export module config {
206
206
  */
207
207
  IEEE754Compatible: boolean
208
208
  targetModuleType: 'cjs' | 'esm' | 'auto'
209
+ /**
210
+ * `legacyBinaryTypes = true` -> Binary and LargeBinary are generated as `string` and a union type respectively
211
+ */
212
+ legacyBinaryTypes: boolean
209
213
  }
210
214
  }
211
215
 
package/lib/visitor.js CHANGED
@@ -531,7 +531,6 @@ class Visitor {
531
531
  const { namespace } = this.entityRepository.getByFqOrThrow(fq)
532
532
  const file = this.fileRepository.getNamespaceFile(namespace)
533
533
  const buffer = file.services.buffer
534
- const serviceNameSimple = service.name.split('.').pop()
535
534
 
536
535
  docify(service.doc).forEach(d => { buffer.add(d) })
537
536
  // file.addImport(new Path(['cds'], '')) TODO make sap/cds import work
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cap-js/cds-typer",
3
- "version": "0.32.1",
3
+ "version": "0.33.1",
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",
@@ -11,12 +11,12 @@
11
11
  "CLI"
12
12
  ],
13
13
  "author": "SAP SE (https://www.sap.com)",
14
- "license": "SEE LICENSE IN LICENSE",
14
+ "license": "Apache-2.0",
15
15
  "scripts": {
16
- "test:unit": "jest --projects test/unit.jest.config.js",
17
- "test:integration": "jest --projects test/int.jest.config.js",
18
- "test:smoke": "jest --projects test/smoke.jest.config.js",
19
- "test:all": "jest",
16
+ "test:unit": "node test/testRunner.js ./test/unit ./test/unit/setup.mjs",
17
+ "test:integration": "node test/testRunner.js ./test/integration ./test/integration/setup.mjs",
18
+ "test:smoke": "node test/testRunner.js ./test/smoke ./test/smoke/setup.mjs",
19
+ "test:all": "npm run test:smoke && npm run test:unit",
20
20
  "test": "npm run test:smoke && npm run test:unit",
21
21
  "lint": "npx eslint .",
22
22
  "lint:fix": "npx eslint . --fix",
@@ -31,9 +31,7 @@
31
31
  "files": [
32
32
  "lib/",
33
33
  "library",
34
- "CHANGELOG.md",
35
34
  "index.js",
36
- "LICENSE",
37
35
  "README.md",
38
36
  "cds-plugin.js"
39
37
  ],
@@ -48,27 +46,20 @@
48
46
  "devDependencies": {
49
47
  "@cap-js/cds-types": "^0",
50
48
  "@sap/cds": "^8",
51
- "@stylistic/eslint-plugin-js": "^2.7.2",
49
+ "@stylistic/eslint-plugin-js": "^4.2.0",
52
50
  "acorn": "^8.10.0",
53
51
  "eslint": "^9",
54
52
  "eslint-plugin-jsdoc": "^50.2.2",
55
- "globals": "^15.0.0",
56
- "jest": "^29",
57
53
  "typescript": ">=4.6.4"
58
54
  },
59
- "jest": {
60
- "projects": [
61
- "test/smoke.jest.config.js",
62
- "test/unit.jest.config.js"
63
- ]
64
- },
65
55
  "cds": {
66
56
  "typer": {
67
57
  "output_directory": "@cds-models",
68
58
  "inline_declarations": "flat",
69
59
  "target_module_type": "auto",
70
60
  "properties_optional": true,
71
- "use_entities_proxy": false
61
+ "use_entities_proxy": false,
62
+ "build_task": true
72
63
  },
73
64
  "schema": {
74
65
  "buildTaskType": {
@@ -119,7 +110,7 @@
119
110
  "flat",
120
111
  "structured"
121
112
  ],
122
- "default": "structured"
113
+ "default": "flat"
123
114
  },
124
115
  "properties_optional": {
125
116
  "type": "boolean",
@@ -131,6 +122,11 @@
131
122
  "description": "If set to true, floating point properties are generated\nas IEEE754 compatible '(number | string)' instead of 'number'.",
132
123
  "default": false
133
124
  },
125
+ "legacy_binary_types": {
126
+ "type": "boolean",
127
+ "description": "If set to true, Binary and LargeBinary are generated\nas strings.",
128
+ "default": false
129
+ },
134
130
  "target_module_type": {
135
131
  "type": "string",
136
132
  "description": "Output format for generated .js files.\nSetting it to auto tries to derive the module type from\nthe package.json and falls back to CJS.",
@@ -140,6 +136,11 @@
140
136
  "auto"
141
137
  ],
142
138
  "default": "auto"
139
+ },
140
+ "build_task": {
141
+ "type": "boolean",
142
+ "description": "If set to true, the typescript build task will not be registered/ executed.\nThis value must be set in your project configuration.\nPassing it as parameter to the cds-typer CLI has no effect.",
143
+ "default": true
143
144
  }
144
145
  }
145
146
  }
package/CHANGELOG.md DELETED
@@ -1,395 +0,0 @@
1
- # Changelog
2
-
3
- All notable changes to this project will be documented in this file.
4
-
5
- ## [Unreleased]
6
-
7
- ### Added
8
- ### Changed
9
- ### Deprecated
10
- ### Removed
11
- ### Fixed
12
- ### Security
13
-
14
- ## [0.32.1] - 2025-01-20
15
-
16
- ### Added
17
- ### Changed
18
- ### Deprecated
19
- ### Removed
20
- ### Fixed
21
- - default value for `inline_declarations` in help command
22
- - entity scope and namespace are now added in the correct order to inflected type names
23
- ### Security
24
-
25
- ## [0.32.0] - 2025-01-14
26
-
27
- ### Added
28
- - dedicated classes for inline compositions
29
- - dedicated text-classes for entities with `localized` elements
30
-
31
- ### Changed
32
- - prefixed builtin types like `Promise` and `Record` with `globalThis.`, to allow using names of builtin types for entities without collisions
33
- - default export class representing the service itself is now exported without name
34
- - bumped peer-dependency to `@cap-js/cds-types` to `>=0.9`
35
-
36
- ### Deprecated
37
- ### Removed
38
- ### Fixed
39
- - referencing another entity's property of type `cds.String` in an enum will now properly quote the generated values
40
- ### Security
41
-
42
- ## [0.31.0] - 2024-12-16
43
- ### Fixed
44
- - type-referencing a property that is a key no longer breaks the referring property
45
- - when targeting ESM, all imports within the generated types now add a `/index.js`-suffix to conform to modern module resolution mechanisms
46
- - leaving `target_module_type` at `'auto'` now properly acts on a detected `"type":"module"`
47
-
48
- ### Added
49
- - cds aspects now generate a synthetic plural type too, to be used in `composition of many`
50
-
51
- ## [0.30.0] - 2024-12-02
52
-
53
- ### Changed
54
- - [breaking] when running cds-typer in a CAP project, the default for the `outputDirectory` option will be `./@cds-models` instead of `./`. This default takes the lowest precedence after setting it in the project's `cds.env`, or explicitly as CLI argument.
55
-
56
- ### Fixed
57
- - cds-typer no longer ignores the selected `outputDirectory`, which would also cause an issue during build
58
-
59
- ## [0.29.0] - 2024-11-20
60
- ### Added
61
- - [breaking] cds-typer now tries to automatically detect whether it has to generate ESM or CommonJS in the emitted _index.js_ files. This behaviour can be overridden via the `--targetModuleType` option. _If you rely on these generated index.js files to be CJS despite your project being of ESM type, you need to manually tell cds-typer to generate CJS files!_
62
-
63
- ### Fixed
64
- - The static `.keys` property now properly reels in key types from inherited classes.
65
-
66
- ## [0.28.1] - 2024-11-07
67
- ### Fixed
68
- - `cds build` no longer fails on Windows with an `EINVAL` error.
69
- - `cds build` also supports custom model paths in `tsconfig.json` that do not end with `/index.ts`. This is the case for projects running with `tsx`.
70
-
71
- ## [0.28.0] - 24-10-24
72
- ### Added
73
- - Schema definition for `cds.typer` options in `package.json` and `.cdsrc-*.json` files
74
- - Added a static `elements` property to all entities, which allows access to the `LinkedDefinitions` instance of an entity's elements
75
- - Schema definition for `typescript` cds build task.
76
- - `.drafts` property of any entity `E` is now of type `DraftOf<E>`, or `DraftsOf<E>` for plurals, respectively. This type exposes dditional properties that are available on drafts during runtime.
77
-
78
- ### Fixed
79
- - Entity elements of named structured types are flattened when using the option `--inlineDeclarations flat`
80
- - `override` modifier on `.kind` property is now only generated if the property is actually inherited, satisfying strict `tsconfig.json`s
81
- - Properly support mandatory (`not null`) action parameters with `array of` types
82
- - Static property `.drafts` is only create for entity classes that are actually draft enabled
83
-
84
- ## [0.27.0] - 2024-10-02
85
- ### Changed
86
- - Any configuration variable (via CLI or `cds.env`) can now be passed in snake_case in addition to camelCase
87
- - Action parameters are now generated as optional by default, which is how the runtime treats them. Mandatory parameters have to be marked as `not null` in CDS/CDL, or `notNull` in CSN.
88
-
89
- ### Fixed
90
- - Fix build task for projects with spaces
91
- - Fix a bug where cds-typer would produce redundant type declarations when the model contains an associations to another entity's property
92
- - Reintroduce default value `'.'` for `--outputDirectory`
93
-
94
- ## [0.26.0] - 2024-09-11
95
- ### Added
96
- - Added a static `.keys` property in all entities. That property is dictionary which holds all properties as keys that are marked as `key` in CDS
97
- - Added a CLI option `--useEntitiesProxy`. When set to `true`, all entities are wrapped into `Proxy` objects during runtime, allowing top level imports of entity types.
98
- - Added a static `.kind` property for entities and types, which contains `'entity'` or `'type'` respectively
99
- - Apps need to provide `@sap/cds` version `8.2` or higher.
100
- - Apps need to provide `@cap-js/cds-types` version `0.6.4` or higher.
101
- - Typed methods are now generated for calls of unbound actions. Named and positional call styles are supported, e.g. `service.action({one, two})` and `service.action(one, two)`.
102
- - Action parameters can be optional in the named call style (`service.action({one:1, ...})`).
103
- - Actions for ABAP RFC modules cannot be called with positional parameters, but only with named ones. They have 'parameter categories' (import/export/changing/tables) that cannot be called in a flat order.
104
- - Services now have their own export (named like the service itself). The current default export is not usable in some scenarios from CommonJS modules.
105
- - Enums and operation parameters can have doc comments
106
-
107
- ## [0.25.0] - 2024-08-13
108
- ### Added
109
- - Declaring a type alias on an enum in cds now also exports it on value level in the resulting type
110
-
111
- ### Fixed
112
- - Classes representing views and projections will no longer carry ancestry to avoid clashes thereof with aliases fields
113
-
114
- ### Changed
115
- - All properties are now preceeded with the `declare` modifier to pass strict tsconfigs using `useDefineForClassFields` or `noImplicitOverride`
116
- - The static `actions` property of generated classes now includes the types from all inherited classes to also suggest actions defined in a base entity/aspect/type.
117
-
118
- ## [0.24.0] - 2024-07-18
119
- ### Fixed
120
- - Suppressed an error that would incorrectly point out naming clashes when an entity was named in singular inflection in the model
121
- - CDS aspects now also generate a aspect-function in singular inflection, similar to how entities do
122
-
123
- ### Changed
124
- - Aspects generate named classes again so that tooltips will show more meaningful provenance for properties
125
- - 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`
126
-
127
- ## [0.23.0] - 2024-07-04
128
-
129
- ### Fixed
130
- - Plurals no longer have `is_singular` attached in the resulting .js files
131
- - Properties are properly propagated beyond just one level of inheritance
132
-
133
- ## [0.22.0] - 2024-06-20
134
-
135
- ### Fixed
136
- - Fixed a bug where keys would sometimes inconsistently become nullable
137
-
138
- ### Changed
139
- - Logging now internally uses `cds.log` and pipes output into the `cds-typer` logger, which can be configured via `cds.env` in addition to explicitly passing a `--logLevel` parameter to CLI. Users now have to use the levels defined in [`cds.log.levels`](https://cap.cloud.sap/docs/node.js/cds-log#log-levels). The formerly valid levels `WARNING`, `CRITICAL`, and `NONE` are now deprecated and automatically mapped to valid levels for now.
140
-
141
- ## [0.21.2] - 2024-06-06
142
- ### Fixed
143
- - The typescript build task will no longer attempt to run unless at least cds 8 is installed
144
-
145
- ## [0.21.1] - 2024-06-03
146
- ### Fixed
147
- - Added missing _cds-plugin.js_ to exported files to properly enable calling `cds build --for typescript`
148
-
149
- ## [0.21.0] - 2024-05-31
150
- ### Added
151
- - Added `IEEE754Compatible` flag which, when set to `true`, generates decimal fields as `(number | string)` instead of `number`. This flag will be removed in the long run
152
- - Added plugin to `cds build` TypeScript projects. Can be explicitly called using `cds build --for typescript`
153
-
154
- ### Changed
155
- - Types representing CDS events are now only `declare`d to avoid having to make their properties optional
156
- - Singular forms in generated _index.js_ files now contain a `.is_singular` property as marker for distinguished handling of singular and plural in the runtime
157
- - Parameters passed to the CLI now take precedence over configuration contained in the `typer` section of `cds.env`
158
-
159
- ### Fixed
160
- - Entities ending with an "s" are no longer incorrectly truncated within `extends`-clauses
161
- - Entity names prefixed with their own namespace (e.g. `Name.Name`, `Name.NameAttachments`) are not stripped of their name prefix
162
-
163
- ## [0.20.2] - 2024-04-29
164
- ### Fixed
165
- - Referring to a property's type in a function/ action parameter no longer refers to the enclosing entity
166
-
167
- ## [0.20.1] - 2024-04-24
168
- ### Fixed
169
- - Void actions no longer crash the type generation process
170
-
171
- ## [0.20.0] - 2024-04-23
172
- ### Added
173
- - Types for actions and functions now expose a `.kind` property which holds the string `'function'` or `'action'` respectively
174
- - Added the `CdsDate`, `CdsDateTime`, `CdsTime`, `CdsTimestamp` types, which are each represented as a `string`.
175
- - Plural types can now also contain an optional numeric `$count` property
176
-
177
- ### Changed
178
- - Empty `.actions` properties and operations without parameters are now typed as `Record<never, never>` to make it clear they contain nothing and also to satisfy overzealous linters
179
-
180
- ### Fixed
181
- - Composition of aspects now properly resolve implicit `typeof` references in their properties
182
- - Importing an enum into a service will now generate an alias to the original enum, instead of incorrectly duplicating the definition
183
- - Returning entities from actions/ functions and using them as parameters will now properly use the singular inflection instead of returning an array thereof
184
- - Aspects are now consistently named and called in their singular form
185
- - Only detect inflection clash if singular and plural share the same namespace. This also no longer reports `sap.common` as erroneous during type creation
186
-
187
- ## [0.19.0] - 2024-03-28
188
- ### Added
189
- - Support for `cds.Vector`, which will be represented as `string`
190
-
191
- ## [0.18.2] - 2024-03-21
192
- ### Fixed
193
- - Resolving `@sap/cds` will now look in the CWD first to ensure a consistent use the same CDS version across different setups
194
- - Types of function parameters starting with `cds.` are not automatically considered builtin anymore and receive a more thorough check against an allow-list
195
-
196
-
197
- ## [0.18.1] - 2024-03-13
198
- ### Fix
199
- - Remove faulty plural for CDS `type` definitions from the generated _index.js_ files
200
-
201
- ## [0.18.0] - 2024-03-12
202
- ### Added
203
- - Improved support for projections, including projections on inline definitions, and on views, as well as support for explicit exclusion and selection of properties
204
-
205
- ### Changed
206
- - [breaking] CDS `type` definitions will not be inflected. Whatever inflection you define them in will be assumed treated as a singular form and will not receive a plural form anymore
207
-
208
- ## [0.17.0] - 2024-03-05
209
- ### Fixed
210
- - Fixed a bug where refering to an externally defined enum via the `typeof` syntax would crash the type generation
211
-
212
- ## [0.16.0] - 2024-02-01
213
- ### Changed
214
- - Changed default log level from `NONE` to `ERROR`. See the doc to manually pass in another log level for cds-typer runs
215
- - Name collisions between automatically generated foreign key fields (`.…_ID`, `.…_code`, etc.) with explicitly named fields will now raise an error
216
- - Generate CDS types that are actually structured types as if they were entities. This allows the correct representation of mixing aspects and types in CDS inheritance, and also fixes issues with inline enums in such types
217
-
218
- ### Fixed
219
- - Externally defined enums can now be used as parameter types in actions
220
-
221
- ## [0.15.0] - 2023-12-21
222
- ### Added
223
- - Support for [scoped entities](https://cap.cloud.sap/docs/cds/cdl#scoped-names)
224
- - Support for [delimited identifiers](https://cap.cloud.sap/docs/cds/cdl#delimited-identifiers)
225
-
226
- ### Fixed
227
- - Inline enums are now available during runtime as well
228
- - Inline enums can now be used as action parameter types as well. These enums will not have a runtime representation, but will only assert type safety!
229
- - Arrays of inline enum values can now be used as action parameters too. But they will only be represented by their enclosing type for now, i.e. `string`, `number`, etc.
230
- - Foreign keys of projection entities are now propagated as well
231
-
232
- ## [0.14.0] - 2023-12-13
233
- ### Added
234
- - Entities that are database views now also receive typings
235
-
236
- ## [0.13.0] - 2023-12-06
237
- ### Changed
238
- - Enums are now generated ecplicitly in the respective _index.js_ files and don't have to extract their values from the model at runtime anymore
239
-
240
- ### Added
241
- - The `excluding` clause in projections now actually excludes the specified properties in the generated types
242
-
243
- ## [0.12.0] - 2023-11-23
244
-
245
- ### Changed
246
- - Generate `cds.LargeBinary` as string, buffer, _or readable_ in the case of media content
247
-
248
- ### Added
249
- - Added support for the `not null` modifier
250
-
251
- ### Fixed
252
- - Now using names of enum values in generated _index.js_ files if no explicit value is present
253
-
254
- ## [0.11.1] - 2023-10-12
255
-
256
- ### Changed
257
-
258
- ### Added
259
- ### Fixed
260
- - Fixed how service names are exported as default export
261
-
262
- ## [0.11.0] - 2023-10-10
263
-
264
- ### Changed
265
-
266
- ### Added
267
- - Autoexposed entities in services are now also generated
268
- - Each generated class now contains their original fully qualified name in a static `.name` property
269
- - Inline enums that are defined as literal type of properties are now supported as well (note: this feature is experimental. The location to which enums are generated might change in the future!)
270
-
271
- ### Fixed
272
- - Fixed an error when an entity uses `type of` on a property they have inherited from another entity
273
- - Fixed an error during draftability propagation when defining compositions on types that are declared inline
274
-
275
- ### Removed
276
- - `compileFromCSN` is no longer part of the package's API
277
-
278
- ## [0.10.0] - 2023-09-21
279
-
280
- ### Changed
281
- - Actions and functions are now attached to a static `.actions` property of each generated class. This reflects the runtime behaviour better than the former way of generating instance methods
282
-
283
- ### Added
284
-
285
- ### Fixed
286
-
287
- ## [0.9.0] - 2023-09-08
288
-
289
- ### Changed
290
-
291
- ### Added
292
- - Support for drafts via `@odata.draft.enabled` annotation
293
-
294
- ### Fixed
295
- - Foreign keys are now propagated more than one level (think: `x_ID_ID_ID`)
296
-
297
- ## [0.8.0] - 2023-09-05
298
-
299
- ### Changed
300
-
301
- ### Added
302
-
303
- ### Fixed
304
- - Foreign keys that are inherited via aspects are now also generated in addition to the resolved property (see 0.7.0)
305
- - Explicitly annotated `@singular` and `@plural` names are now properly used in generated _index.js_ files
306
-
307
- ## [0.7.0] - 2023-08-22
308
-
309
- ### Changed
310
-
311
- ### Added
312
- - Support for `[many] $self` syntax in bound action parameters
313
- - Foreign keys are now present in the generated types in addition to the resolved property
314
-
315
- ### Fixed
316
- ## [0.6.1] - 2023-08-10
317
-
318
- ### Changed
319
-
320
- ### Added
321
-
322
- ### Fixed
323
- - Removed a warning about circular imports
324
-
325
- ## [0.6.0] - 2023-08-07
326
-
327
- ### Added
328
- - Support for `event` syntax
329
-
330
- ### Fixed
331
- - Initialise bound actions with stubs to support `"strict":true` in _tsconfig.json_
332
- - Add leading underscore to appease `noUnusedParameters` in strict tsconfigs
333
- - No longer inflect `type` definitions when they are referenced within entities or other type definitions
334
-
335
- ## [0.5.0] - 2023-07-25
336
-
337
- ### Changed
338
- - Facilitate strict property checks. Note: `checkJs: true` must be present in the project's _jsconfig.json_ or _tsconfig.json_ respectively for this feature to become effective
339
-
340
- ### Added
341
- - Support for `array of` syntax
342
-
343
- ### Fixed
344
- - Generate `string` type for date-related types in CDS definitions
345
- - Generate `Buffer | string` type for the CDS type `LargeBinary`
346
-
347
- ## [0.4.0] - 2023-07-06
348
- ### Added
349
- - Support for enums when they are defined separately (not inline in the property type of an entity)
350
-
351
- ## [0.3.0] - 2023-06-26
352
- ### Added
353
- - Support `function` definitions (apart from `action`s)
354
- ### Changed
355
- - Bump version to next minor
356
-
357
- ### Fixed
358
- - Properly import CDS `type` definitions when they are referenced elsewhere
359
-
360
- ## [0.2.5-beta.1] - 2023-06-13
361
-
362
- ### Changed
363
- - Bump version
364
-
365
- ## [0.2.4] - 2023-06-12
366
- - Enable use of annotated singular/ plural names in associations/ compositions
367
- - Rename package from `@sap/cds-dts-generator` to `@cap-js/cds-typer`
368
-
369
- ## [0.2.3] - 2023-05-17
370
- - Add missing library files
371
-
372
- ## [0.2.2] - 2023-05-17
373
- - Make class hierarchy flatter
374
-
375
- ## [0.2.1] - 2023-05-16
376
- - Add missing files
377
-
378
- ## [0.2.0] - 2023-05-15
379
- - use native Typescript AST in unit tests
380
- - add `propertiesOptional` flag
381
- - support flat, as well as nested inline declarations
382
- - support `typeof` syntax
383
- - read rudimentary configuration from cds.env
384
- - export bound and unbound actions
385
- - allow inline type definitions within compositions
386
- - enable use of additional type libraries (HANA types available as first library)
387
- - provide proper JSDoc for all modules
388
- - export entity types for singular variants alongside plural types
389
-
390
- ## [0.1.1] - 2023-01-26
391
- - add TL;DR section to README
392
- - allow multiple positional arguments
393
-
394
- ## [0.1.0] - 2023-01-01
395
- - initial code base