New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@cap-js/cds-typer

Package Overview
Dependencies
Maintainers
2
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cap-js/cds-typer - npm Package Compare versions

Comparing version 0.15.0 to 0.16.0

11

CHANGELOG.md

@@ -7,4 +7,13 @@ # Change Log

## Version 0.16.0 - TBD
## Version 0.17.0 - TBD
## Version 0.16.0 - 2024-02-01
### Changed
- Changed default log level from `NONE` to `ERROR`. See the doc to manually pass in another log level for cds-typer runs
- Name collisions between automatically generated foreign key fields (`.…_ID`, `.…_code`, etc.) with explicitly named fields will now raise an error
- 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
### Fixed
- Externally defined enums can now be used as parameter types in actions
## Version 0.15.0 - 2023-12-21

@@ -11,0 +20,0 @@ ### Added

4

lib/cli.js

@@ -26,3 +26,3 @@ #!/usr/bin/env node

allowed: Object.keys(Levels),
default: Object.keys(Levels).at(-1),
default: Levels.ERROR,
},

@@ -94,3 +94,3 @@ jsConfigPath: {

outputDirectory: [args.named.outputDirectory, args.named.rootDir].find(d => d !== './') ?? './',
logLevel: Levels[args.named.logLevel],
logLevel: Levels[args.named.logLevel] ?? args.named.logLevel,
jsConfigPath: args.named.jsConfigPath,

@@ -97,0 +97,0 @@ inlineDeclarations: args.named.inlineDeclarations,

@@ -62,3 +62,3 @@ const { normalise } = require('./identifier')

// in case of strings, wrap in quotes and fallback to key to make sure values are attached for every key
const enumVal = (key, value, enumType) => enumType === 'cds.String' ? JSON.stringify(`${value ?? key}`) : value
const enumVal = (key, value, enumType) => enumType === 'cds.String' ? JSON.stringify(`${value ?? key}`) : value

@@ -65,0 +65,0 @@ /**

@@ -376,3 +376,11 @@ 'use strict'

// If it is missing then we are dealing with an inline parameter type of an action.
if (element.parent) {
// Edge case: element.parent is set, but no .name property is attached. This happens
// for inline enums inside types:
// ```cds
// type T {
// x : String enum { ... }; // no element.name for x
// }
// ```
// In that case, we currently resolve to the more general type (cds.String, here)
if (element.parent?.name) {
result.isInlineDeclaration = true

@@ -379,0 +387,0 @@ // we use the singular as the initial declaration of these enums takes place

@@ -192,4 +192,9 @@ 'use strict'

if (this.resolver.getMaxCardinality(element) === 1) {
kelement.isRefNotNull = !!element.notNull || !!element.key
this.visitElement(`${ename}_${kname}`, kelement, file, buffer)
const foreignKey = `${ename}_${kname}`
if (Object.hasOwn(entity.elements, foreignKey)) {
this.logger.error(`Attempting to generate a foreign key reference called '${foreignKey}' in type definition for entity ${name}. But a property of that name is already defined explicitly. Consider renaming that property.`)
} else {
kelement.isRefNotNull = !!element.notNull || !!element.key
this.visitElement(foreignKey, kelement, file, buffer)
}
}

@@ -284,3 +289,3 @@ }

this.logger.error(
`Derived singular '${singular}' for your entity '${name}', already exists. The resulting types will be erronous. Please consider using '@singular:'/ '@plural:' annotations in your model to resolve this collision.`
`Derived singular '${singular}' for your entity '${name}', already exists. The resulting types will be erronous. Consider using '@singular:'/ '@plural:' annotations in your model or move the offending declarations into different namespaces to resolve this collision.`
)

@@ -343,3 +348,5 @@ }

#stringifyFunctionParamType(type, file) {
return type.enum
// if type.type is not 'cds.String', 'cds.Integer', ..., then we are actually looking
// at a named enum type. In that case also resolve that type name
return type.enum && type.type.startsWith('cds.')
? stringifyEnumType(csnToEnumPairs(type))

@@ -445,8 +452,12 @@ : this.inlineDeclarationResolver.getPropertyDatatype(this.resolver.resolveAndRequire(type, file))

break
case 'type':
this.#printType(name, entity)
break
case 'aspect':
this.#printAspect(name, entity)
break
case 'type': {
// types like inline definitions can be used very similarly to entities.
// They can be extended, contain inline enums, etc., so we treat them as entities.
const handler = entity.elements ? this.#printEntity : this.#printType
handler.bind(this)(name, entity)
break
}
case 'event':

@@ -459,3 +470,3 @@ this.#printEvent(name, entity)

default:
this.logger.error(`Unhandled entity kind '${entity.kind}'.`)
this.logger.debug(`Unhandled entity kind '${entity.kind}'.`)
}

@@ -462,0 +473,0 @@ }

{
"name": "@cap-js/cds-typer",
"version": "0.15.0",
"version": "0.16.0",
"description": "Generates .ts files for a CDS model to receive code completion in VS Code",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc