-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
JF
committed
Jun 21, 2018
1 parent
0c999c9
commit 9df485a
Showing
7 changed files
with
388 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// @flow | ||
|
||
/** | ||
* @property {string} variable - The variable of this field | ||
*/ | ||
export default class Filter { | ||
property: string; | ||
variable: string; | ||
|
||
/** | ||
* @param {string} property | ||
* @param {string} variable | ||
*/ | ||
constructor(property: string, variable: string) { | ||
this.property = property; | ||
this.variable = variable; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import Filter from "../Filter"; | ||
import fetchResource from "./fetchResource"; | ||
|
||
export default api => { | ||
const promises = []; | ||
|
||
for (const resource of api.resources) { | ||
let promise = fetchResource(resource.url).then(response => { | ||
if (!response.filters) { | ||
return []; | ||
} | ||
|
||
const resourceFilters = []; | ||
|
||
for (const filter of response.filters) { | ||
let property = filter.property; | ||
|
||
if (property === null) { | ||
continue; | ||
} | ||
|
||
resourceFilters.push(new Filter(property, filter.variable)); | ||
} | ||
|
||
return resourceFilters; | ||
}); | ||
|
||
promises.push(promise); | ||
} | ||
|
||
return Promise.all(promises).then(values => { | ||
api.resources.map((resource, index) => { | ||
resource.filters = values[index]; | ||
}); | ||
|
||
return api; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import fetchJsonLd from "./fetchJsonLd"; | ||
import get from "lodash.get"; | ||
|
||
export default async entrypointUrl => { | ||
return await fetchJsonLd(entrypointUrl, { itemsPerPage: 0 }).then( | ||
d => ({ | ||
filters: get(d, "body.hydra:search.hydra:mapping") | ||
}), | ||
() => { | ||
throw new Error("Unreachable resource"); | ||
} | ||
); | ||
}; |
Oops, something went wrong.