Skip to content

Commit

Permalink
Do not allow bundle MISSING_BOOK and MISMATCHED_SLUG overlap
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerZeroMaster committed Jul 1, 2024
1 parent 3c360fe commit e37144f
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions server/src/model/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,26 +114,30 @@ export class Bundle extends Fileish implements Bundleish {
{
message: BundleValidationKind.MISMATCHED_SLUG,
nodesToLoad: this.books,
fn: () => booksXMLBooks
.filter(
({ v: bx, range: xr }) => books.filter(
({ v: b, range: br }) =>
xr.start === br.start &&
xr.end === br.end &&
b.isValidXML &&
b.exists &&
b.slug === bx.slug
).size === 0
)
.map(bx => bx.range)
fn: () => {
return booksXMLBooks
.filter(({ v: bx, range: rx }) => {
const maybeBookNode = books.find(
({ range: r }) => r.start === rx.start && r.end === rx.end
)
if (maybeBookNode !== undefined) {
const { v: book } = maybeBookNode
if (book.isValidXML && book.exists) {
return book.slug !== bx.slug
}
}
return false
})
.map(({ range }) => range)
}
}
]
}
}

export class BundleValidationKind extends ValidationKind {
// openstax/enki/bakery-src/scripts/link_single.py#L59
static MISMATCHED_SLUG = new BundleValidationKind('Slug does not match any defined in a book')
static MISMATCHED_SLUG = new BundleValidationKind('Slug does not match the one defined in the book')
static MISSING_BOOK = new BundleValidationKind('Missing book')
static NO_BOOKS = new BundleValidationKind('No books defined')
}
Expand Down

0 comments on commit e37144f

Please sign in to comment.