Skip to content

Commit

Permalink
Print Type for Arrays of Enum Values in Action Parameter Types (#133)
Browse files Browse the repository at this point in the history
* Single out case where arrays of enums are used as action params

* Use encapsulating type

* Lint

* Lint
  • Loading branch information
daogrady committed Dec 21, 2023
1 parent 1fe5d9b commit 133273d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
### Fixed
- Inline enums are now available during runtime as well
- 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!
- 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.
- Foreign keys of projection entities are now propagated as well

## Version 0.14.0 - 2023-12-13
Expand Down
1 change: 0 additions & 1 deletion lib/components/inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const { docify } = require('./wrappers')
* their resolution mechanism.
*/
class InlineDeclarationResolver {

/**
* @param {string} name
* @param {import('./resolver').TypeResolveInfo} type
Expand Down
27 changes: 20 additions & 7 deletions lib/components/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,13 +371,26 @@ class Resolver {
result.isInlineDeclaration = true
} else {
if (isInlineEnumType(element, this.csn)) {
// we use the singular as the initial declaration of these enums takes place
// while defining the singular class. Which therefore uses the singular over the plural name.
const cleanEntityName = util.singular4(element.parent, true)
const enumName = propertyToInlineEnumName(cleanEntityName, element.name)
result.type = enumName
result.plainName = enumName
result.isInlineDeclaration = true
// element.parent is only set if the enum is attached to an entity's property.
// If it is missing then we are dealing with an inline parameter type of an action.
if (element.parent) {
result.isInlineDeclaration = true
// we use the singular as the initial declaration of these enums takes place
// while defining the singular class. Which therefore uses the singular over the plural name.
const cleanEntityName = util.singular4(element.parent, true)
const enumName = propertyToInlineEnumName(cleanEntityName, element.name)
result.type = enumName
result.plainName = enumName
} else {
// FIXME: this is the case where users have arrays of enums as action parameter type.
// Instead of building the proper type (e.g. `'A' | 'B' | ...`, we are instead building
// the encasing type (e.g. `string` here)
// We should instead aim for a proper type, i.e.
// this.#resolveInlineDeclarationType(element.enum, result, file)
// or
// stringifyEnumType(csnToEnumPairs(element))
this.#resolveTypeName(element.type, result)
}
} else {
this.resolvePotentialReferenceType(element.type, result, file)
}
Expand Down

0 comments on commit 133273d

Please sign in to comment.