Skip to content

Commit

Permalink
Handle compositions on inline types during draft propagation (#80)
Browse files Browse the repository at this point in the history
* Handle compositions on inline types during draft propagation

* Remove faulty addition of final false literal
  • Loading branch information
daogrady authored Sep 29, 2023
1 parent 010ef40 commit d2228b3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).

### Fixed
- Fixed an error when an entity uses `type of` on a property they have inherited from another entity
- Fixed an error during draftability propagation when defining compositions on types that are declared inline

## Version 0.10.0 - 2023-09-21

Expand Down
15 changes: 10 additions & 5 deletions lib/csn.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class DraftUnroller {
*/
#setDraftable(entity, value) {
if (typeof entity === 'string') entity = this.#getDefinition(entity)
if (!entity) return // inline definition -- not found in definitions
entity[annotation] = value
this.#draftable[entity.name] = value
if (value) {
Expand All @@ -41,9 +42,13 @@ class DraftUnroller {
* @param entity {object | string} - entity to look draftability up for.
* @returns {boolean}
*/
#getDraftable(entity) {
if (typeof entity === 'string') entity = this.#getDefinition(entity)
return this.#draftable[entity.name] ??= this.#propagateInheritance(entity)
#getDraftable(entityOrName) {
const entity = (typeof entityOrName === 'string')
? this.#getDefinition(entityOrName)
: entityOrName
// assert(typeof entity !== 'string')
const name = entity?.name ?? entityOrName
return this.#draftable[name] ??= this.#propagateInheritance(entity)
}

/**
Expand All @@ -59,8 +64,8 @@ class DraftUnroller {
* @param entity {object} - entity to pull draftability from its parents.
*/
#propagateInheritance(entity) {
const annotations = (entity.includes ?? []).map(parent => this.#getDraftable(parent))
annotations.push(entity[annotation])
const annotations = (entity?.includes ?? []).map(parent => this.#getDraftable(parent))
annotations.push(entity?.[annotation])
this.#setDraftable(entity, annotations.filter(a => a !== undefined).at(-1) ?? false)
}

Expand Down

0 comments on commit d2228b3

Please sign in to comment.