Comparing version 2.0.0 to 2.0.1
# Changelog | ||
## 2.0.1 | ||
### Patch Changes | ||
- e46dffa: Parse JSON responses as JSON-LD when there is a context `Link` header | ||
## 2.0.0 | ||
@@ -4,0 +10,0 @@ |
@@ -8,3 +8,5 @@ export declare const Headers: { | ||
canonical: string; | ||
context: string; | ||
apiDocumentation: "http://www.w3.org/ns/hydra/core#apiDocumentation"; | ||
}; | ||
//# sourceMappingURL=Constants.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.LinkRelations = exports.Headers = void 0; | ||
const rdf_ns_builders_1 = require("@tpluscode/rdf-ns-builders"); | ||
exports.Headers = { | ||
@@ -11,2 +12,4 @@ Link: 'Link', | ||
canonical: 'canonical', | ||
context: 'http://www.w3.org/ns/json-ld#context', | ||
apiDocumentation: rdf_ns_builders_1.hydra.apiDocumentation.value, | ||
}; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -6,4 +25,6 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const parse_link_header_1 = __importDefault(require("parse-link-header")); | ||
const ResponseWrapper_1 = __importDefault(require("./ResponseWrapper")); | ||
const MergeHeaders_1 = require("./helpers/MergeHeaders"); | ||
const Constants = __importStar(require("./Constants")); | ||
function requestAcceptHeaders(sinkMap) { | ||
@@ -25,3 +46,9 @@ return [...sinkMap.keys()].join(', '); | ||
const res = await _fetch(effectiveUri, requestInit); | ||
return new ResponseWrapper_1.default(effectiveUri, res, parsers); | ||
const linkHeaders = res.headers.get(Constants.Headers.Link); | ||
const links = parse_link_header_1.default(linkHeaders) || {}; | ||
let jsonLdContext; | ||
if (links[Constants.LinkRelations.context]) { | ||
jsonLdContext = await _fetch(links[Constants.LinkRelations.context].url).then(res => res.json()); | ||
} | ||
return new ResponseWrapper_1.default(effectiveUri, res, parsers, jsonLdContext); | ||
} | ||
@@ -28,0 +55,0 @@ function resource(uri, requestInit) { |
{ | ||
"name": "alcaeus", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Hydra Core hypermedia-aware client library", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -41,7 +41,9 @@ /// <reference types="node" /> | ||
readonly xhr: Response; | ||
private parsers; | ||
constructor(requestedUri: string, res: Response, parsers: SinkMap<EventEmitter, Stream>); | ||
private readonly parsers; | ||
private readonly jsonLdContext?; | ||
constructor(requestedUri: string, xhr: Response, parsers: SinkMap<EventEmitter, Stream>, jsonLdContext?: unknown); | ||
quadStream(): Stream | null; | ||
get status(): number; | ||
get apiDocumentationLink(): string | null; | ||
get links(): any; | ||
get mediaType(): string; | ||
@@ -48,0 +50,0 @@ get redirectUrl(): string | null; |
@@ -26,6 +26,4 @@ "use strict"; | ||
const parse_link_header_1 = __importDefault(require("parse-link-header")); | ||
const rdf_ns_builders_1 = require("@tpluscode/rdf-ns-builders"); | ||
const Constants = __importStar(require("./Constants")); | ||
const fetchToStream_1 = require("./helpers/fetchToStream"); | ||
const apiDocumentationRel = rdf_ns_builders_1.hydra.apiDocumentation.value; | ||
function stripContentTypeParameters(mediaType) { | ||
@@ -35,9 +33,10 @@ return mediaType.split(';').shift() || ''; | ||
class default_1 { | ||
constructor(requestedUri, res, parsers) { | ||
this.xhr = res; | ||
constructor(requestedUri, xhr, parsers, jsonLdContext) { | ||
this.requestedUri = requestedUri; | ||
this.xhr = xhr; | ||
this.parsers = parsers; | ||
this.jsonLdContext = jsonLdContext; | ||
} | ||
quadStream() { | ||
const quadStream = this.parsers.import(stripContentTypeParameters(this.mediaType), fetchToStream_1.patchResponseBody(this.xhr), { baseIRI: this.effectiveUri }); | ||
const quadStream = this.parsers.import(stripContentTypeParameters(this.mediaType), fetchToStream_1.patchResponseBody(this.xhr), { baseIRI: this.effectiveUri, context: this.jsonLdContext }); | ||
if (quadStream == null) { | ||
@@ -53,6 +52,4 @@ return null; | ||
if (this.xhr.headers.has(Constants.Headers.Link)) { | ||
const linkHeaders = this.xhr.headers.get(Constants.Headers.Link); | ||
const links = parse_link_header_1.default(linkHeaders); | ||
if (links[apiDocumentationRel]) { | ||
const linkUrl = links[apiDocumentationRel].url; | ||
if (this.links[Constants.LinkRelations.apiDocumentation]) { | ||
const linkUrl = this.links[Constants.LinkRelations.apiDocumentation].url; | ||
return this.resolveUri(linkUrl); | ||
@@ -63,3 +60,10 @@ } | ||
} | ||
get links() { | ||
const linkHeaders = this.xhr.headers.get(Constants.Headers.Link); | ||
return parse_link_header_1.default(linkHeaders) || {}; | ||
} | ||
get mediaType() { | ||
if (this.links[Constants.LinkRelations.context]) { | ||
return 'application/ld+json'; | ||
} | ||
return this.xhr.headers.get(Constants.Headers.ContentType) || ''; | ||
@@ -87,6 +91,4 @@ } | ||
get canonicalUri() { | ||
const linkHeaders = this.xhr.headers.get(Constants.Headers.Link); | ||
const links = parse_link_header_1.default(linkHeaders); | ||
if (links && links[Constants.LinkRelations.canonical]) { | ||
return this.resolveUri(links[Constants.LinkRelations.canonical].url); | ||
if (this.links[Constants.LinkRelations.canonical]) { | ||
return this.resolveUri(this.links[Constants.LinkRelations.canonical].url); | ||
} | ||
@@ -93,0 +95,0 @@ return undefined; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
389423
4653