-
-
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.
Showing
7 changed files
with
338 additions
and
202 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,29 @@ | ||
// @flow | ||
|
||
/** | ||
* @property {string} variable - The variable of this field | ||
*/ | ||
export default class Parameter { | ||
variable: string; | ||
range: string; | ||
required: boolean; | ||
description: string; | ||
|
||
/** | ||
* @param {string} variable | ||
* @param {string} range | ||
* @param {boolean} required | ||
* @param {string} description | ||
*/ | ||
constructor( | ||
variable: string, | ||
range: string, | ||
required: boolean, | ||
description: string | ||
) { | ||
this.variable = variable; | ||
this.range = range; | ||
this.required = required; | ||
this.description = description; | ||
} | ||
} |
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,34 @@ | ||
import Parameter from "../Parameter"; | ||
import fetchResource from "./fetchResource"; | ||
|
||
export default api => { | ||
const promises = []; | ||
|
||
for (const resource of api.resources) { | ||
const promise = fetchResource(resource.url).then(({ parameters = {} }) => { | ||
const resourceParameters = []; | ||
parameters.forEach(({ property = null, required, variable }) => { | ||
if (null === property) { | ||
return; | ||
} | ||
|
||
const { range = null } = | ||
resource.fields.find(({ name }) => property === name) || {}; | ||
|
||
resourceParameters.push(new Parameter(variable, range, required, "")); | ||
}); | ||
|
||
return resourceParameters; | ||
}); | ||
|
||
promises.push(promise); | ||
} | ||
|
||
return Promise.all(promises).then(values => { | ||
api.resources.map((resource, index) => { | ||
resource.parameters = 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 resourceUrl => { | ||
return await fetchJsonLd(resourceUrl, { itemsPerPage: 0 }).then( | ||
d => ({ | ||
parameters: get(d, "body.hydra:search.hydra:mapping") | ||
}), | ||
() => { | ||
throw new Error("Unreachable resource"); | ||
} | ||
); | ||
}; |
Oops, something went wrong.