Skip to content

Add support for owl:deprecated annotations #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
module.exports = {
'env': {
env: {
'browser': true,
'commonjs': true,
'es6': true,
'jest': true,
'node': true,
},
'parser': 'babel-eslint',
'parserOptions': {
parser: 'babel-eslint',
parserOptions: {
ecmaVersion: 7,
sourceType: 'module'
},
'plugins': ['import'],
'extends': 'eslint:recommended',
plugins: ['import', 'flowtype', 'prettier'],

extends: [
"plugin:prettier/recommended",
],

rules: {
"prettier/prettier": "error"
},

};
1 change: 1 addition & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[ignore]
.*/node_modules/.*

[include]

Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@
"babel-preset-es2015": "^6.24.0",
"babel-preset-stage-0": "^6.22.0",
"eslint": "^3.18.0",
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-flowtype": "^2.47.1",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-prettier": "^2.6.0",
"flow-bin": "^0.42.0",
"jest": "^20.0.0",
"jest-fetch-mock": "^1.0.8"
"jest-fetch-mock": "^1.0.8",
"prettier": "^1.12.1"
},
"dependencies": {
"babel-runtime": "^6.23.0",
Expand All @@ -37,6 +41,8 @@
"scripts": {
"test": "jest",
"lint": "eslint src && flow check",
"fix": "eslint --fix src",
"eslint-check": "eslint --print-config .eslintrc.js | eslint-config-prettier-check",
"build": "babel src -d lib --ignore '*.test.js'"
},
"jest": {
Expand Down
10 changes: 5 additions & 5 deletions src/Api.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// @flow

import Resource from './Resource';
import Resource from "./Resource";

type ApiOptions = {
title?: string,
resources?: Map<string, Resource>,
}
resources?: Map<string, Resource>
};

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

Object.keys(options).forEach((key) => {
Object.keys(options).forEach(key => {
Object.defineProperty(this, key, {
readable: true,
writable: true,
enumerable: true,
value: options[key],
value: options[key]
});
});
}
Expand Down
7 changes: 4 additions & 3 deletions src/Field.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ type FieldOptions = {
required?: boolean,
description?: string,
maxCardinality?: number,
}
deprecated?: boolean
};

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

Object.keys(options).forEach((key) => {
Object.keys(options).forEach(key => {
Object.defineProperty(this, key, {
readable: true,
writable: true,
enumerable: true,
value: options[key],
value: options[key]
});
});
}
Expand Down
7 changes: 4 additions & 3 deletions src/Operation.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ type OperationOptions = {
method?: string,
returns?: string,
types?: Array<string>,
}
deprecated?: boolean
};

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

Object.keys(options).forEach((key) => {
Object.keys(options).forEach(key => {
Object.defineProperty(this, key, {
readable: true,
writable: true,
enumerable: true,
value: options[key],
value: options[key]
});
});
}
Expand Down
11 changes: 6 additions & 5 deletions src/Resource.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// @flow

import Field from './Field';
import Operation from './Operation';
import Field from "./Field";
import Operation from "./Operation";

type ResourceOptions = {
id?: string,
title?: string,
deprecated?: boolean,
readableFields?: Field[],
writableFields?: Field[],
operations?: Operation[],
operations?: Operation[]
};

/**
Expand All @@ -28,12 +29,12 @@ export default class Resource {
this.name = name;
this.url = url;

Object.keys(options).forEach((key) => {
Object.keys(options).forEach(key => {
Object.defineProperty(this, key, {
readable: true,
writable: true,
enumerable: true,
value: options[key],
value: options[key]
});
});
}
Expand Down
43 changes: 26 additions & 17 deletions src/hydra/fetchJsonLd.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,39 @@
* @return {Promise.<object>} An object with a response key (the original HTTP response) and an optional body key (the parsed JSON-LD body)
*/
export default function fetchJsonLd(url, options = {}) {
const jsonLdMimeType = 'application/ld+json';
const jsonLdMimeType = "application/ld+json";

if ('undefined' === typeof options.headers) {
if ("undefined" === typeof options.headers) {
options.headers = new Headers();
}

if (null === options.headers.get('Accept')) {
options.headers.set('Accept', jsonLdMimeType);
if (null === options.headers.get("Accept")) {
options.headers.set("Accept", jsonLdMimeType);
}

if ('undefined' !== options.body && !(typeof FormData !== 'undefined' && options.body instanceof FormData) && null === options.headers.get('Content-Type')) {
options.headers.set('Content-Type', jsonLdMimeType);
if (
"undefined" !== options.body &&
!(typeof FormData !== "undefined" && options.body instanceof FormData) &&
null === options.headers.get("Content-Type")
) {
options.headers.set("Content-Type", jsonLdMimeType);
}

return fetch(url, options)
.then(response => {
const { headers, status } = response;
if (204 === status) {
return Promise.resolve({ response });
}
if (500 <= status || !headers.has('Content-Type') || !headers.get('Content-Type').includes(jsonLdMimeType)) {
return Promise.reject({ response });
}
return fetch(url, options).then(response => {
const { headers, status } = response;
if (204 === status) {
return Promise.resolve({ response });
}
if (
500 <= status ||
!headers.has("Content-Type") ||
!headers.get("Content-Type").includes(jsonLdMimeType)
) {
return Promise.reject({ response });
}

return Promise.resolve(response.json().then(body => ({ response, body, document: body })));
});
return Promise.resolve(
response.json().then(body => ({ response, body, document: body }))
);
});
}
66 changes: 43 additions & 23 deletions src/hydra/fetchJsonLd.test.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,72 @@
import fetchJsonLd from './fetchJsonLd';
import fetchJsonLd from "./fetchJsonLd";

test('fetch a JSON-LD document', () => {
fetch.mockResponseOnce(`{
test("fetch a JSON-LD document", () => {
fetch.mockResponseOnce(
`{
"@context": "http://json-ld.org/contexts/person.jsonld",
"@id": "http://dbpedia.org/resource/John_Lennon",
"name": "John Lennon",
"born": "1940-10-09",
"spouse": "http://dbpedia.org/resource/Cynthia_Lennon"
}`, {status: 200, statusText: 'OK', headers: new Headers({'Content-Type': 'application/ld+json'})});

return fetchJsonLd('/foo.jsonld').then(data => {
expect(data.response.ok).toBe(true);
expect(data.body.name).toBe('John Lennon');
}`,
{
status: 200,
statusText: "OK",
headers: new Headers({ "Content-Type": "application/ld+json" })
}
);

return fetchJsonLd("/foo.jsonld").then(data => {
expect(data.response.ok).toBe(true);
expect(data.body.name).toBe("John Lennon");
});
});

test('fetch a non JSON-LD document', () => {
fetch.mockResponseOnce(`<body>Hello</body>`, {status: 200, statusText: 'OK', headers: new Headers({'Content-Type': 'text/html'})});
test("fetch a non JSON-LD document", () => {
fetch.mockResponseOnce(`<body>Hello</body>`, {
status: 200,
statusText: "OK",
headers: new Headers({ "Content-Type": "text/html" })
});

return fetchJsonLd('/foo.jsonld').catch(data => {
expect(data.response.ok).toBe(true);
expect(typeof data.body).toBe('undefined');
}
);
return fetchJsonLd("/foo.jsonld").catch(data => {
expect(data.response.ok).toBe(true);
expect(typeof data.body).toBe("undefined");
});
});

test('fetch an error', () => {
fetch.mockResponseOnce(`{
test("fetch an error", () => {
fetch.mockResponseOnce(
`{
"@context": "http://json-ld.org/contexts/person.jsonld",
"@id": "http://dbpedia.org/resource/John_Lennon",
"name": "John Lennon",
"born": "1940-10-09",
"spouse": "http://dbpedia.org/resource/Cynthia_Lennon"
}`, {status: 400, statusText: 'Bad Request', headers: new Headers({'Content-Type': 'application/ld+json'})});
}`,
{
status: 400,
statusText: "Bad Request",
headers: new Headers({ "Content-Type": "application/ld+json" })
}
);

return fetchJsonLd('/foo.jsonld').catch(({response}) => {
return fetchJsonLd("/foo.jsonld").catch(({ response }) => {
response.json().then(body => {
expect(response.ok).toBe(false);
expect(body.born).toBe('1940-10-09');
expect(body.born).toBe("1940-10-09");
});
});
});

test('fetch an empty document', () => {
fetch.mockResponseOnce('', {status: 204, statusText: 'No Content', headers: new Headers({'Content-Type': 'text/html'})});
test("fetch an empty document", () => {
fetch.mockResponseOnce("", {
status: 204,
statusText: "No Content",
headers: new Headers({ "Content-Type": "text/html" })
});

return fetchJsonLd('/foo.jsonld').then(data => {
return fetchJsonLd("/foo.jsonld").then(data => {
expect(data.response.ok).toBe(true);
expect(data.body).toBe(undefined);
});
Expand Down
6 changes: 4 additions & 2 deletions src/hydra/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export fetchJsonLd from './fetchJsonLd';
export parseHydraDocumentation, { getDocumentationUrlFromHeaders } from './parseHydraDocumentation';
export fetchJsonLd from "./fetchJsonLd";
export parseHydraDocumentation, {
getDocumentationUrlFromHeaders
} from "./parseHydraDocumentation";
Loading