Skip to content

Commit

Permalink
Fix hal-types 2 build issue
Browse files Browse the repository at this point in the history
  • Loading branch information
evert committed Feb 26, 2025
1 parent 4b4f4fb commit 554e0c2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ ChangeLog
this was important to you, so we can add this back with a more modern stack.
* Removed mocha from the test suite, and now using the Node.js test runner.
Mocha is painful to use with a modern Node / Typescript stack.
* Updated to hal-types 2, which updates to the latest link-hints draft, and is
a bit looser with what it requires from a HAL document.


8.0.0-alpha.3 (2023-06-11)
Expand Down
12 changes: 4 additions & 8 deletions src/state/hal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,9 @@ function parseHalLinks(context: string, body: hal.HalResource): Link[] {
// eslint-disable-next-line prefer-const
for (let [rel, innerBodies] of Object.entries(body._embedded)) {

if (!Array.isArray(innerBodies)) {
innerBodies = [innerBodies];
}

for(const innerBody of innerBodies) {
for(const innerBody of Array.isArray(innerBodies) ? innerBodies : [innerBodies]) {

const href:string = innerBody?._links?.self?.href;
const href:string = (innerBody?._links?.self as hal.HalLink)?.href;
if (!href) {
continue;
}
Expand Down Expand Up @@ -222,13 +218,13 @@ function parseHalEmbedded(client: Client, context: string, body: hal.HalResource
}
for (const embeddedItem of embeddedList) {

if (embeddedItem._links?.self?.href === undefined) {
if ((embeddedItem._links?.self as hal.HalLink)?.href === undefined) {
// eslint-disable-next-line no-console
console.warn('An item in _embedded was ignored. Each item must have a single "self" link');
continue;
}

const embeddedSelf = resolve(context, embeddedItem._links.self.href);
const embeddedSelf = resolve(context, (embeddedItem._links?.self as hal.HalLink)?.href);

// Remove _links and _embedded from body
const {
Expand Down

0 comments on commit 554e0c2

Please sign in to comment.