@cap-js/cds-typer 0.2.5-beta.1 → 0.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.
package/CHANGELOG.md CHANGED
@@ -4,11 +4,24 @@ 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.4.1 - TBD
7
8
 
8
- ## Version 0.2.5-beta.1 - 2023-06-13
9
+ ## Version 0.4.0 - 2023-07-06
10
+ ### Added
11
+ - Support for enums when they are defined separately (not inline in the property type of an entity)
9
12
 
13
+ ## Version 0.3.0 - 2023-06-26
14
+ ### Added
15
+ - Support `function` definitions (apart from `action`s)
10
16
  ### Changed
17
+ - Bump version to next minor
18
+
19
+ ### Fixed
20
+ - Properly import CDS `type` definitions when they are referenced elsewhere
11
21
 
22
+ ## Version 0.2.5-beta.1 - 2023-06-13
23
+
24
+ ### Changed
12
25
  - Bump version
13
26
 
14
27
  ## Version 0.2.4 - 2023-06-12
package/README.md CHANGED
@@ -6,16 +6,12 @@ Generates `.ts` files for a CDS model to receive code completion in VS Code.
6
6
 
7
7
 
8
8
  ## Requirements and Setup
9
-
10
-
11
- ### Building the Project Yourself
12
- Clone the repository and install the dependencies running `npm i` from the project's root directory.
13
-
9
+ This project is [available as `@cap-js/cds-typer`](https://www.npmjs.com/package/@cap-js/cds-typer) as NPM package.
14
10
 
15
11
  ### Usage
16
- The type generator is currently meant as a standalone tool and can be installed and used independently of other CDS environments (sans its dependency to the cds compiler).
12
+ The type generator can either be used as a standalone tool, or as part of of the [CDS VSCode-Extension](https://www.npmjs.com/package/@sap/vscode-cds).
17
13
 
18
- #### Quickstart
14
+ #### Standalone CLI
19
15
  Assuming you have the following CDS project structure:
20
16
 
21
17
  ```
@@ -30,38 +26,31 @@ Assuming you have the following CDS project structure:
30
26
  a typical workflow to generate types for your CDS project could look something like this:
31
27
 
32
28
  ```sh
33
- git clone https://this/repo cds-js-type-generator
34
- cd cds-js-type-generator
35
- npm i
36
- node ./index.js \
37
- --rootDir /home/mybookshop/@types \
38
- --jsConfigPath /home/mybookshop \
39
- /home/mybookshop/srv/schema.cds
29
+ npx @cap-js/cds-typer /home/mybookshop/db/schema.cds --outputDirectory /home/mybookshop/@types
40
30
  ```
41
31
 
42
- You would then end up with a `jsconfig.json` file in the project's root and a directory `@types`, which contains your entities and their accompanying types in a directory structure. The directory structure directly reflects the namespaces you have defined your entities in. They have to be imported in any JavaScript-based service handlers you want to have type support in and can replace calls to `cds.entities(...)`:
32
+ You would then end up with a directory `@types`, which contains your entities and their accompanying types in a directory structure. The directory structure directly reflects the namespaces you have defined your entities in. They have to be imported in any JavaScript-based service handlers you want to have type support in and can replace calls to `cds.entities(...)`:
43
33
 
44
34
  ```js
45
35
  // srv/service.js
46
36
  const { Books } = require('my.bookshop')
47
-
48
37
  ```
49
38
 
50
39
  becomes
51
40
 
52
41
  ```js
53
42
  // srv/service.js
54
-
55
43
  const { Books } = require('../@types/mybookshop')
56
44
  ```
57
45
 
58
46
  From that point on you should receive code completion from the type system for `Books`.
59
47
 
60
- #### CLI
48
+ _Note:_ the above command generates types for the model contained within the mentioned `schema.cds` file. If you have multiple `.cds` files that are included via `using` statements by `schema.cds`, then those files will also be included in the type generation process. If you have `.cds` files that are _not_ in some way included in `schema.cds`, you have to explicitly pass those as positional argument as well, if you want types for them.
49
+
61
50
  _cds-typer_ comes with rudimentary CLI support and a few command line options:
62
51
 
63
52
  - `--help`: prints all available parameters.
64
- - `--rootDir`: specifies the root directory where all generated files should be put. Defaults to the CWD.
53
+ - `--outputDirectory`: specifies the root directory where all generated files should be put. Defaults to the CWD.
65
54
  - `--jsConfigPath`: specifies the path to the `jsconfig.json` file to generate. Usually your project's root directory. If specified, a config file is created that restricts the usage of types even further:
66
55
 
67
56
  ```js
@@ -93,11 +82,13 @@ NONE
93
82
  The utility expects (at least) one path to a `.cds` file as positional parameter which serves as entry point to the model in question, e.g.:
94
83
 
95
84
  ```sh
96
- cds-typer ./path/to/my/model/model.cds --rootDir /tmp/
85
+ npx @cap-js/cds-typer ./path/to/my/model/model.cds --outputDirectory /tmp/
97
86
  ```
98
87
 
99
88
  Note that you can also pass multiple paths or `"*"` as glob pattern (with quotes to circumvent expansion by the shell). This passes the pattern on to the compiler where the [regular resolve strategy](https://cap.cloud.sap/docs/node.js/cds-compile?q=compiler#cds-resolve) is used.
100
89
 
90
+ #### From VSCode
91
+ Installing the [CDS VSCode Extension](https://www.npmjs.com/package/@sap/vscode-cds) also adds support for generating types for your model from within VSCode. Adding the appropriate facet to your project via `cds add typer` (and installing the added dependencies thereafter) allows you to simply hit save on any `.cds` file that is part of your model to trigger the generation process.
101
92
  #### Programmatically
102
93
  The main API for using _cds-typer_ within another project is contained in [`compile.js`](https://github.tools.sap/cap/cds-typer/blob/master/lib/compile.js), specifically:
103
94
 
@@ -181,7 +172,7 @@ _cds-typer_ tries to keep its dependency footprint as small as possible. Librari
181
172
 
182
173
  ## Support, Feedback, Contributing
183
174
 
184
- This project is open to feature requests/suggestions, bug reports etc. via [GitHub issues](https://github.com/SAP/cds-dts-generator/issues). Contribution and feedback are encouraged and always welcome. For more information about how to contribute, the project structure, as well as additional contribution information, see our [Contribution Guidelines](CONTRIBUTING.md).
175
+ This project is open to feature requests/suggestions, bug reports etc. via [GitHub issues](https://github.com/cap-js/cds-typer/issues). Contribution and feedback are encouraged and always welcome. For more information about how to contribute, the project structure, as well as additional contribution information, see our [Contribution Guidelines](CONTRIBUTING.md).
185
176
 
186
177
  ## Code of Conduct
187
178