Skip to content

Commit

Permalink
Merge branch 'main' into feat/structured-types-always-flat
Browse files Browse the repository at this point in the history
  • Loading branch information
daogrady committed Nov 13, 2024
2 parents e351110 + fac7c7c commit 4b563c6
Show file tree
Hide file tree
Showing 24 changed files with 365 additions and 365 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
node-version: 22
- name: Run Linter
run: |
npm ci
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: '20'
node-version: 22

- name: Install dependencies
run: npm install
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
runs-on: ubuntu-latest
environment: npm
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
node-version: 22
registry-url: https://registry.npmjs.org/

- name: Run Unit Tests
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
node-version: 22

- name: Run Smoke Tests
run: |
Expand All @@ -26,13 +26,13 @@ jobs:
needs: smoke-tests # to avoid writing over each others output
strategy:
matrix:
version: [20, 18]
version: [22, 18]
platform: [ macos-latest, ubuntu-latest, windows-latest ]
runs-on: ${{ matrix.platform }}

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.version }}

Expand Down
18 changes: 16 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,31 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
The format is based on [Keep a Changelog](http://keepachangelog.com/).

## Version 0.28.0 - TBD
## Version 0.29.0 - tbd
### Added

### Changed

### Fixed
- Referencing a structured type in an entity will now always flatten and unroll the type, instead of creating a reference

## Version 0.28.1 - 2024-11-07
### Fixed
- `cds build` no longer fails on Windows with an `EINVAL` error.
- `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`.

## Version 0.28.0 - 24-10-24
### Added
- Schema definition for `cds.typer` options in `package.json` and `.cdsrc-*.json` files
- Added a static `elements` property to all entities, which allows access to the `LinkedDefinitions` instance of an entity's elements
- Schema definition for `typescript` cds build task.
- `.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.

### Fixed
- Entity elements of named structured types are flattened when using the option `--inlineDeclarations flat`
- `override` modifier on `.kind` property is now only generated if the property is actually inherited, satisfying strict `tsconfig.json`s
- Properly support mandatory (`not null`) action parameters with `array of` types
- Referencing a structured type in an entity will now always flatten and unroll the type, instead of creating a reference
- Static property `.drafts` is only create for entity classes that are actually draft enabled

## Version 0.27.0 - 2024-10-02
### Changed
Expand Down
6 changes: 3 additions & 3 deletions cds-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ cds.build?.register?.('typescript', class extends cds.build.Plugin {
const outputDirectory = cds.env.typer?.outputDirectory
if (outputDirectory) return outputDirectory
try {
// expected format: { '#cds-models/*': [ './@cds-models/*/index.ts' ] }
// expected format: { '#cds-models/*': [ './@cds-models/*' ] }
// ^^^^^^^^^^^
// relevant part - may be changed by user
const config = JSON.parse(fs.readFileSync ('tsconfig.json', 'utf8'))
const alias = config.compilerOptions.paths['#cds-models/*'][0]
const directory = alias.match(/(?:\.\/)?(.*)\/\*\/index\.ts/)[1]
const directory = alias.match(/(?:\.\/)?(.*)\/\*/)[1]
return normalize(directory) // could contain forward slashes in tsconfig.json
} catch {
DEBUG?.('tsconfig.json not found, not parsable, or inconclusive. Using default model directory name')
Expand Down Expand Up @@ -110,7 +110,7 @@ cds.build?.register?.('typescript', class extends cds.build.Plugin {
DEBUG?.('building without config')
// this will include gen/ that was created by the nodejs task
// _within_ the project directory. So we need to remove it afterwards.
await exec(`npx tsc --outDir "${this.task.dest}"`)
await exec(`npx tsc --outDir "${this.task.dest.replace(/\\/g, '/')}"`) // see https://github.com/cap-js/cds-typer/issues/374
rmDirIfExists(path.join(this.task.dest, cds.env.build.target))
rmDirIfExists(path.join(this.task.dest, this.#appFolder))
}
Expand Down
3 changes: 2 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ module.exports = [
ecmaVersion: 'latest',
sourceType: 'commonjs',
globals: {
...require('globals').node
...require('globals').node,
jest: true
}
},
files: ['**/*.js'],
Expand Down
10 changes: 10 additions & 0 deletions lib/components/basedefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ export type EntitySet<T> = T[] & {
data (input:object) : T
};
export type DraftEntity<T> = T & {
IsActiveEntity?: boolean | null
HasActiveEntity?: boolean | null
HasDraftEntity?: boolean | null
DraftAdministrativeData_DraftUUID?: string | null
}
export type DraftOf<T> = { new(...args: any[]): DraftEntity<T> }
export type DraftsOf<T> = typeof Array<DraftEntity<T>>
export type DeepRequired<T> = {
[K in keyof T]: DeepRequired<T[K]>
} & Exclude<Required<T>, null>;
Expand Down
16 changes: 16 additions & 0 deletions lib/components/wrappers.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ const createKey = t => `${base}.Key<${t}>`
*/
const createKeysOf = t => `${base}.KeysOf<${t}>`

/**
* Wraps type into DraftOf type.
* @param {string} t - the type name.
* @returns {string}
*/
const createDraftOf = t => `${base}.DraftOf<${t}>`

/**
* Wraps type into DraftsOf type.
* @param {string} t - the type name.
* @returns {string}
*/
const createDraftsOf = t => `${base}.DraftsOf<${t}>`

/**
* Wraps type into ElementsOf type.
* @param {string} t - the type name.
Expand Down Expand Up @@ -114,6 +128,8 @@ const stringIdent = s => `'${s}'`

module.exports = {
createArrayOf,
createDraftOf,
createDraftsOf,
createKey,
createKeysOf,
createElementsOf,
Expand Down
Loading

0 comments on commit 4b563c6

Please sign in to comment.