This repository has been archived by the owner on Feb 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathhydra-core.js
64 lines (48 loc) · 1.53 KB
/
hydra-core.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
var
hydra = require('./lib/core'),
utils = require('./lib/utils');
require('./lib/http-client');
require('./lib/model');
require('./lib/validation');
hydra.loadApi = function (url) {
return hydra.httpClient.request('GET', url)
.then(function (response) {
return hydra.api(response.body, url);
})
.then(function (api) {
api.iri = url;
return api;
});
};
hydra.documentFromResponse = function (response) {
return hydra.httpClient.apiLink(response.headers, response.request.url)
.then(function (apiUrl) {
return hydra.loadApi(apiUrl);
})
.then(function (api) {
return hydra.document(api, response.body, response.request.url);
})
.then(function (document) {
return hydra.httpClient.contentLocation(response.headers, response.request.url)
.then(function (contentLocation) {
document.iri = contentLocation || response.request.url;
return document;
});
});
};
hydra.loadDocument = function (url) {
return hydra.httpClient.request('GET', url)
.then(function (response) {
return hydra.documentFromResponse(response, url);
});
};
// export utils
hydra.utils = utils;
// set defaults
hydra.defaults = {};
hydra.defaults.invokeOperation = hydra.httpClient.jsonLdInvoke;
hydra.defaults.validateClass = hydra.simpleValidateClass;
hydra.defaults.model = {};
hydra.defaults.model.createInvoke = hydra.model.createHttpJsonLdInvoke;
hydra.defaults.model.invokeOperation = hydra.httpClient.rawJsonLdInvoke;
module.exports = hydra;