Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Nicer zsh trees
Browse files Browse the repository at this point in the history
swaldmann committed Oct 19, 2023
1 parent 232c90a commit 44faea9
Showing 1 changed file with 22 additions and 25 deletions.
47 changes: 22 additions & 25 deletions tools/cds-typer.md
Original file line number Diff line number Diff line change
@@ -392,13 +392,13 @@ _tsconfig.json_, as we do not want to interfere with your configuration.
The emitted types are bundled into a directory which contains a nested directory structure that mimics the namespaces of your CDS model. For the sake of brevity, we will assume them to be in a directory called _@cds-models_ in your project's root in the following sections.
For example, the sample model contains a namespace `sap.capire.bookshop`. You will therefore find the following file structure after the type generation has finished:
```txt
@cds-models
└──sap
└──capire
└──bookshop
index.js
index.ts
```zsh
@cds-models/
└── sap/
└── capire/
└── bookshop/
├── index.js
└── index.ts
```
Each _index.ts_ file will contain type information for one namespace. For each entity belonging to that namespace, you will find two exports, a singular and a plural form:
@@ -417,27 +417,24 @@ The plural form exists as a convenience to refer to a collection of multiple ent
You could import these types by using absolute paths, but there is a more convenient way for doing so which will be described in the next section.
## Subpath Imports
Adding type support via `cds add typer` includes adding [subpath imports](https://nodejs.org/api/packages.html#subpath-imports). Per default, the facet adds a mapping of `#cds-models/` to the default path your model's types are assumed to be generated to (_\<project root\>/@cds-models/_). If you are generating your types to another path and want to use subpath imports, you will have to adjust this setting in your _package.json_ **and** _jsconfig.json_/ _tsconfig.json_ accordingly.
Adding type support via `cds add typer` includes configuring [subpath imports](https://nodejs.org/api/packages.html#subpath-imports). The facet adds a mapping of `#cds-models/` to the default path your model's types are assumed to be generated to (_\<project root\>/@cds-models/_). If you are generating your types to another path and want to use subpath imports, you will have to adjust this setting in your _package.json_ **and** _jsconfig.json_/ _tsconfig.json_ accordingly.
Consider [the bookshop sample](https://github.com/SAP-samples/cloud-cap-samples/tree/main/bookshop) with the following structure with types already generated into _@cds-models_:
```txt
bookstore
package.json
└───@cds-models
│ └───<described in the previous section>
└───db
schema.cds
│ …
└───srv
│ cat-service.cds
│ cat-service.js
│ …
└─── …
```zsh
bookstore/
├── package.json
├── @cds-models/
│ └── ‹described in the previous section›
├── db/
│ ├── schema.cds
│ └── ...
├── srv/
│ ├── cat-service.cds
│ ├── cat-service.js
│ └── ...
└── ...
```
The following two (equally valid) statements would amount to the same import [from within the catalog service](https://github.com/SAP-samples/cloud-cap-samples/blob/main/bookshop/srv/cat-service.js):

0 comments on commit 44faea9

Please sign in to comment.