Skip to content

Commit

Permalink
Lookup _unresolved entities from inferred csn too
Browse files Browse the repository at this point in the history
  • Loading branch information
daogrady committed Dec 13, 2023
1 parent 2114c50 commit 69392ae
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
14 changes: 13 additions & 1 deletion lib/csn.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,18 @@ function amendCSN(csn) {
propagateForeignKeys(csn)
}

/**
* FIXME: this is pretty handwavey: we are looking for view-entities,
* i.e. ones that have a query, but are not a cds level projection.
* Those are still not expanded and we have to retrieve their definition
* with all properties from the inferred model.
*/
const isView = entity => entity.query && !entity.projection

module.exports = { amendCSN, isView }
/**
* @see isView
* Unresolved entities have to be looked up from inferred csn.
*/
const isUnresolved = entity => entity._unresolved === true

module.exports = { amendCSN, isView, isUnresolved }
15 changes: 5 additions & 10 deletions lib/visitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const util = require('./util')

const { amendCSN, isView } = require('./csn')
const { amendCSN, isView, isUnresolved } = require('./csn')
// eslint-disable-next-line no-unused-vars
const { SourceFile, baseDefinitions, Buffer } = require('./file')
const { FlatInlineDeclarationResolver, StructuredInlineDeclarationResolver } = require('./components/inline')
Expand Down Expand Up @@ -99,15 +99,10 @@ class Visitor {
*/
visitDefinitions() {
for (const [name, entity] of Object.entries(this.csn.xtended.definitions)) {
if (entity._unresolved === true) {
this.logger.warning(`Skipping unresolved entity: ${name}`)
} else {
// FIXME: this is pretty handwavey: we are looking for view-entities,
// i.e. ones that have a query, but are not a cds level projection.
// Those are still not expanded and we have to retrieve their definition
// with all properties from the inferred model.
this.visitEntity(name, isView(entity) ? this.csn.inferred.definitions[name] : entity)
}
const toVisit = isView(entity) || isUnresolved
? this.csn.inferred.definitions[name]
: entity
this.visitEntity(name, toVisit)
}
// FIXME: optimise
// We are currently working with two flavours of CSN:
Expand Down

0 comments on commit 69392ae

Please sign in to comment.