Skip to content

Commit 2d51436

Browse files
authored
Merge pull request #31 from dunglas/deprecated
Add support for owl:deprecated annotations
2 parents a0a2c37 + 864d649 commit 2d51436

13 files changed

+963
-578
lines changed

.eslintrc.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
module.exports = {
2-
'env': {
2+
env: {
33
'browser': true,
44
'commonjs': true,
55
'es6': true,
66
'jest': true,
77
'node': true,
88
},
9-
'parser': 'babel-eslint',
10-
'parserOptions': {
9+
parser: 'babel-eslint',
10+
parserOptions: {
1111
ecmaVersion: 7,
1212
sourceType: 'module'
1313
},
14-
'plugins': ['import'],
15-
'extends': 'eslint:recommended',
14+
plugins: ['import', 'flowtype', 'prettier'],
15+
16+
extends: [
17+
"plugin:prettier/recommended",
18+
],
19+
20+
rules: {
21+
"prettier/prettier": "error"
22+
},
23+
1624
};

.flowconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[ignore]
2+
.*/node_modules/.*
23

34
[include]
45

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@
2424
"babel-preset-es2015": "^6.24.0",
2525
"babel-preset-stage-0": "^6.22.0",
2626
"eslint": "^3.18.0",
27+
"eslint-config-prettier": "^2.9.0",
28+
"eslint-plugin-flowtype": "^2.47.1",
2729
"eslint-plugin-import": "^2.2.0",
30+
"eslint-plugin-prettier": "^2.6.0",
2831
"flow-bin": "^0.42.0",
2932
"jest": "^20.0.0",
30-
"jest-fetch-mock": "^1.0.8"
33+
"jest-fetch-mock": "^1.0.8",
34+
"prettier": "^1.12.1"
3135
},
3236
"dependencies": {
3337
"babel-runtime": "^6.23.0",
@@ -37,6 +41,8 @@
3741
"scripts": {
3842
"test": "jest",
3943
"lint": "eslint src && flow check",
44+
"fix": "eslint --fix src",
45+
"eslint-check": "eslint --print-config .eslintrc.js | eslint-config-prettier-check",
4046
"build": "babel src -d lib --ignore '*.test.js'"
4147
},
4248
"jest": {

src/Api.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// @flow
22

3-
import Resource from './Resource';
3+
import Resource from "./Resource";
44

55
type ApiOptions = {
66
title?: string,
7-
resources?: Map<string, Resource>,
8-
}
7+
resources?: Map<string, Resource>
8+
};
99

1010
/**
1111
* @property {string} entrypoint - The URL of the API's entrypoint
@@ -20,12 +20,12 @@ export default class Api {
2020
constructor(entrypoint: string, options: ApiOptions = {}) {
2121
this.entrypoint = entrypoint;
2222

23-
Object.keys(options).forEach((key) => {
23+
Object.keys(options).forEach(key => {
2424
Object.defineProperty(this, key, {
2525
readable: true,
2626
writable: true,
2727
enumerable: true,
28-
value: options[key],
28+
value: options[key]
2929
});
3030
});
3131
}

src/Field.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ type FieldOptions = {
77
required?: boolean,
88
description?: string,
99
maxCardinality?: number,
10-
}
10+
deprecated?: boolean
11+
};
1112

1213
/**
1314
* @property {string} name - The name of this field
@@ -22,12 +23,12 @@ export default class Field {
2223
constructor(name: string, options: FieldOptions = {}) {
2324
this.name = name;
2425

25-
Object.keys(options).forEach((key) => {
26+
Object.keys(options).forEach(key => {
2627
Object.defineProperty(this, key, {
2728
readable: true,
2829
writable: true,
2930
enumerable: true,
30-
value: options[key],
31+
value: options[key]
3132
});
3233
});
3334
}

src/Operation.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ type OperationOptions = {
44
method?: string,
55
returns?: string,
66
types?: Array<string>,
7-
}
7+
deprecated?: boolean
8+
};
89

910
/**
1011
* @property {string} name - The name of this operation
@@ -19,12 +20,12 @@ export default class Operation {
1920
constructor(name: string, options: OperationOptions = {}) {
2021
this.name = name;
2122

22-
Object.keys(options).forEach((key) => {
23+
Object.keys(options).forEach(key => {
2324
Object.defineProperty(this, key, {
2425
readable: true,
2526
writable: true,
2627
enumerable: true,
27-
value: options[key],
28+
value: options[key]
2829
});
2930
});
3031
}

src/Resource.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
// @flow
22

3-
import Field from './Field';
4-
import Operation from './Operation';
3+
import Field from "./Field";
4+
import Operation from "./Operation";
55

66
type ResourceOptions = {
77
id?: string,
88
title?: string,
9+
deprecated?: boolean,
910
readableFields?: Field[],
1011
writableFields?: Field[],
11-
operations?: Operation[],
12+
operations?: Operation[]
1213
};
1314

1415
/**
@@ -28,12 +29,12 @@ export default class Resource {
2829
this.name = name;
2930
this.url = url;
3031

31-
Object.keys(options).forEach((key) => {
32+
Object.keys(options).forEach(key => {
3233
Object.defineProperty(this, key, {
3334
readable: true,
3435
writable: true,
3536
enumerable: true,
36-
value: options[key],
37+
value: options[key]
3738
});
3839
});
3940
}

src/hydra/fetchJsonLd.js

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,39 @@
66
* @return {Promise.<object>} An object with a response key (the original HTTP response) and an optional body key (the parsed JSON-LD body)
77
*/
88
export default function fetchJsonLd(url, options = {}) {
9-
const jsonLdMimeType = 'application/ld+json';
9+
const jsonLdMimeType = "application/ld+json";
1010

11-
if ('undefined' === typeof options.headers) {
11+
if ("undefined" === typeof options.headers) {
1212
options.headers = new Headers();
1313
}
1414

15-
if (null === options.headers.get('Accept')) {
16-
options.headers.set('Accept', jsonLdMimeType);
15+
if (null === options.headers.get("Accept")) {
16+
options.headers.set("Accept", jsonLdMimeType);
1717
}
1818

19-
if ('undefined' !== options.body && !(typeof FormData !== 'undefined' && options.body instanceof FormData) && null === options.headers.get('Content-Type')) {
20-
options.headers.set('Content-Type', jsonLdMimeType);
19+
if (
20+
"undefined" !== options.body &&
21+
!(typeof FormData !== "undefined" && options.body instanceof FormData) &&
22+
null === options.headers.get("Content-Type")
23+
) {
24+
options.headers.set("Content-Type", jsonLdMimeType);
2125
}
2226

23-
return fetch(url, options)
24-
.then(response => {
25-
const { headers, status } = response;
26-
if (204 === status) {
27-
return Promise.resolve({ response });
28-
}
29-
if (500 <= status || !headers.has('Content-Type') || !headers.get('Content-Type').includes(jsonLdMimeType)) {
30-
return Promise.reject({ response });
31-
}
27+
return fetch(url, options).then(response => {
28+
const { headers, status } = response;
29+
if (204 === status) {
30+
return Promise.resolve({ response });
31+
}
32+
if (
33+
500 <= status ||
34+
!headers.has("Content-Type") ||
35+
!headers.get("Content-Type").includes(jsonLdMimeType)
36+
) {
37+
return Promise.reject({ response });
38+
}
3239

33-
return Promise.resolve(response.json().then(body => ({ response, body, document: body })));
34-
});
40+
return Promise.resolve(
41+
response.json().then(body => ({ response, body, document: body }))
42+
);
43+
});
3544
}

src/hydra/fetchJsonLd.test.js

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,72 @@
1-
import fetchJsonLd from './fetchJsonLd';
1+
import fetchJsonLd from "./fetchJsonLd";
22

3-
test('fetch a JSON-LD document', () => {
4-
fetch.mockResponseOnce(`{
3+
test("fetch a JSON-LD document", () => {
4+
fetch.mockResponseOnce(
5+
`{
56
"@context": "http://json-ld.org/contexts/person.jsonld",
67
"@id": "http://dbpedia.org/resource/John_Lennon",
78
"name": "John Lennon",
89
"born": "1940-10-09",
910
"spouse": "http://dbpedia.org/resource/Cynthia_Lennon"
10-
}`, {status: 200, statusText: 'OK', headers: new Headers({'Content-Type': 'application/ld+json'})});
11-
12-
return fetchJsonLd('/foo.jsonld').then(data => {
13-
expect(data.response.ok).toBe(true);
14-
expect(data.body.name).toBe('John Lennon');
11+
}`,
12+
{
13+
status: 200,
14+
statusText: "OK",
15+
headers: new Headers({ "Content-Type": "application/ld+json" })
1516
}
1617
);
18+
19+
return fetchJsonLd("/foo.jsonld").then(data => {
20+
expect(data.response.ok).toBe(true);
21+
expect(data.body.name).toBe("John Lennon");
22+
});
1723
});
1824

19-
test('fetch a non JSON-LD document', () => {
20-
fetch.mockResponseOnce(`<body>Hello</body>`, {status: 200, statusText: 'OK', headers: new Headers({'Content-Type': 'text/html'})});
25+
test("fetch a non JSON-LD document", () => {
26+
fetch.mockResponseOnce(`<body>Hello</body>`, {
27+
status: 200,
28+
statusText: "OK",
29+
headers: new Headers({ "Content-Type": "text/html" })
30+
});
2131

22-
return fetchJsonLd('/foo.jsonld').catch(data => {
23-
expect(data.response.ok).toBe(true);
24-
expect(typeof data.body).toBe('undefined');
25-
}
26-
);
32+
return fetchJsonLd("/foo.jsonld").catch(data => {
33+
expect(data.response.ok).toBe(true);
34+
expect(typeof data.body).toBe("undefined");
35+
});
2736
});
2837

29-
test('fetch an error', () => {
30-
fetch.mockResponseOnce(`{
38+
test("fetch an error", () => {
39+
fetch.mockResponseOnce(
40+
`{
3141
"@context": "http://json-ld.org/contexts/person.jsonld",
3242
"@id": "http://dbpedia.org/resource/John_Lennon",
3343
"name": "John Lennon",
3444
"born": "1940-10-09",
3545
"spouse": "http://dbpedia.org/resource/Cynthia_Lennon"
36-
}`, {status: 400, statusText: 'Bad Request', headers: new Headers({'Content-Type': 'application/ld+json'})});
46+
}`,
47+
{
48+
status: 400,
49+
statusText: "Bad Request",
50+
headers: new Headers({ "Content-Type": "application/ld+json" })
51+
}
52+
);
3753

38-
return fetchJsonLd('/foo.jsonld').catch(({response}) => {
54+
return fetchJsonLd("/foo.jsonld").catch(({ response }) => {
3955
response.json().then(body => {
4056
expect(response.ok).toBe(false);
41-
expect(body.born).toBe('1940-10-09');
57+
expect(body.born).toBe("1940-10-09");
4258
});
4359
});
4460
});
4561

46-
test('fetch an empty document', () => {
47-
fetch.mockResponseOnce('', {status: 204, statusText: 'No Content', headers: new Headers({'Content-Type': 'text/html'})});
62+
test("fetch an empty document", () => {
63+
fetch.mockResponseOnce("", {
64+
status: 204,
65+
statusText: "No Content",
66+
headers: new Headers({ "Content-Type": "text/html" })
67+
});
4868

49-
return fetchJsonLd('/foo.jsonld').then(data => {
69+
return fetchJsonLd("/foo.jsonld").then(data => {
5070
expect(data.response.ok).toBe(true);
5171
expect(data.body).toBe(undefined);
5272
});

src/hydra/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
export fetchJsonLd from './fetchJsonLd';
2-
export parseHydraDocumentation, { getDocumentationUrlFromHeaders } from './parseHydraDocumentation';
1+
export fetchJsonLd from "./fetchJsonLd";
2+
export parseHydraDocumentation, {
3+
getDocumentationUrlFromHeaders
4+
} from "./parseHydraDocumentation";

0 commit comments

Comments
 (0)