Skip to content

Commit

Permalink
Fix fetchContainers if only one resource in container
Browse files Browse the repository at this point in the history
  • Loading branch information
srosset81 committed Jun 10, 2024
1 parent 7d5d9e2 commit f31a426
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 5 deletions.
15 changes: 14 additions & 1 deletion src/frontend/packages/semantic-data-provider/dist/index.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion src/frontend/packages/semantic-data-provider/dist/index.es.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const arrayOf = value => {
// If the field is null-ish, we suppose there are no values.
if (!value) {
return [];
}
// Return as is.
if (Array.isArray(value)) {
return value;
}
// Single value is made an array.
return [value];
};

export default arrayOf;
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import jsonld from 'jsonld';
import isobject from 'isobject';
import arrayOf from './arrayOf';

export const isType = (type, resource) => {
const resourceType = resource.type || resource['@type'];
Expand Down Expand Up @@ -30,7 +31,7 @@ const fetchContainers = async (containers, resourceId, params, config) => {
})
.then(json => {
if (isType('ldp:Container', json)) {
return json['ldp:contains'].map(resource => ({ '@context': json['@context'], ...resource }));
return arrayOf(json['ldp:contains']).map(resource => ({ '@context': json['@context'], ...resource }));
}
throw new Error(`${containerUri} is not a LDP container`);
})
Expand Down

0 comments on commit f31a426

Please sign in to comment.