Comparing version 0.10.6 to 0.10.7
@@ -5,2 +5,9 @@ # Changelog | ||
### [0.10.7](https://github.com/wikibus/alcaeus/compare/v0.10.6...v0.10.7) (2020-03-17) | ||
### Features | ||
* setting base URI to allow relative resource ids ([275664d](https://github.com/wikibus/alcaeus/commit/275664d3cc62709cd00eebbc5f973e5560482069)) | ||
### [0.10.6](https://github.com/wikibus/alcaeus/compare/v0.10.5...v0.10.6) (2020-02-29) | ||
@@ -7,0 +14,0 @@ |
@@ -27,2 +27,3 @@ // tslint:disable no-console | ||
constructor(rootSelectors, mediaTypeProcessors) { | ||
this.baseUri = undefined; | ||
this.defaultHeaders = {}; | ||
@@ -33,3 +34,3 @@ this.rootSelectors = rootSelectors; | ||
async loadResource(uri, headers = {}) { | ||
const response = await FetchUtil.fetchResource(uri, this.__mergeHeaders(new Headers(headers))); | ||
const response = await FetchUtil.fetchResource(uri, this.__mergeHeaders(new Headers(headers)), this.baseUri); | ||
const apiDocumentation = await getApiDocumentation.call(this, response, headers); | ||
@@ -43,3 +44,3 @@ if (apiDocumentation) { | ||
try { | ||
const response = await FetchUtil.fetchResource(uri, this.__mergeHeaders(new Headers(headers))); | ||
const response = await FetchUtil.fetchResource(uri, this.__mergeHeaders(new Headers(headers)), this.baseUri); | ||
const representation = await getHydraResponse(this, response, uri); | ||
@@ -80,3 +81,3 @@ const resource = representation.root; | ||
const mergedHeaders = this.__mergeHeaders(new Headers(headers)); | ||
const response = await FetchUtil.invokeOperation(operation.method, uri, body, mergedHeaders); | ||
const response = await FetchUtil.invokeOperation(operation.method, uri, body, mergedHeaders, this.baseUri); | ||
const apiDocumentation = await getApiDocumentation.call(this, response, mergedHeaders); | ||
@@ -83,0 +84,0 @@ if (apiDocumentation) { |
@@ -6,3 +6,7 @@ import * as Constants from './Constants'; | ||
const requestAcceptHeaders = Constants.MediaTypes.jsonLd + ', ' + Constants.MediaTypes.ntriples + ', ' + Constants.MediaTypes.nquads; | ||
async function getResponse(uri, method, headers = {}, body) { | ||
async function getResponse(uri, { method, headers = {}, body, baseUri }) { | ||
let effectiveUri = uri; | ||
if (uri.match(/^https?:\/\//) === null && baseUri) { | ||
effectiveUri = new URL(uri, baseUri).toString(); | ||
} | ||
const defaultHeaders = { | ||
@@ -21,11 +25,15 @@ accept: requestAcceptHeaders, | ||
requestInit.headers = merge(new Headers(defaultHeaders), new Headers(headers)); | ||
const res = await fetch(uri, requestInit); | ||
return new ResponseWrapper(uri, res); | ||
const res = await fetch(effectiveUri, requestInit); | ||
return new ResponseWrapper(effectiveUri, res); | ||
} | ||
export function fetchResource(uri, headers) { | ||
return getResponse(uri, 'get', headers); | ||
export function fetchResource(uri, headers, baseUri) { | ||
return getResponse(uri, { | ||
method: 'get', | ||
headers, | ||
baseUri, | ||
}); | ||
} | ||
export function invokeOperation(method, uri, body, headers) { | ||
return getResponse(uri, method, headers, body); | ||
export function invokeOperation(method, uri, body, headers, baseUri) { | ||
return getResponse(uri, { method, headers, body, baseUri }); | ||
} | ||
//# sourceMappingURL=FetchUtil.js.map |
@@ -36,2 +36,3 @@ "use strict"; | ||
constructor(rootSelectors, mediaTypeProcessors) { | ||
this.baseUri = undefined; | ||
this.defaultHeaders = {}; | ||
@@ -42,3 +43,3 @@ this.rootSelectors = rootSelectors; | ||
async loadResource(uri, headers = {}) { | ||
const response = await FetchUtil.fetchResource(uri, this.__mergeHeaders(new Headers(headers))); | ||
const response = await FetchUtil.fetchResource(uri, this.__mergeHeaders(new Headers(headers)), this.baseUri); | ||
const apiDocumentation = await getApiDocumentation.call(this, response, headers); | ||
@@ -52,3 +53,3 @@ if (apiDocumentation) { | ||
try { | ||
const response = await FetchUtil.fetchResource(uri, this.__mergeHeaders(new Headers(headers))); | ||
const response = await FetchUtil.fetchResource(uri, this.__mergeHeaders(new Headers(headers)), this.baseUri); | ||
const representation = await getHydraResponse(this, response, uri); | ||
@@ -89,3 +90,3 @@ const resource = representation.root; | ||
const mergedHeaders = this.__mergeHeaders(new Headers(headers)); | ||
const response = await FetchUtil.invokeOperation(operation.method, uri, body, mergedHeaders); | ||
const response = await FetchUtil.invokeOperation(operation.method, uri, body, mergedHeaders, this.baseUri); | ||
const apiDocumentation = await getApiDocumentation.call(this, response, mergedHeaders); | ||
@@ -92,0 +93,0 @@ if (apiDocumentation) { |
@@ -15,3 +15,7 @@ "use strict"; | ||
const requestAcceptHeaders = Constants.MediaTypes.jsonLd + ', ' + Constants.MediaTypes.ntriples + ', ' + Constants.MediaTypes.nquads; | ||
async function getResponse(uri, method, headers = {}, body) { | ||
async function getResponse(uri, { method, headers = {}, body, baseUri }) { | ||
let effectiveUri = uri; | ||
if (uri.match(/^https?:\/\//) === null && baseUri) { | ||
effectiveUri = new URL(uri, baseUri).toString(); | ||
} | ||
const defaultHeaders = { | ||
@@ -30,13 +34,17 @@ accept: requestAcceptHeaders, | ||
requestInit.headers = MergeHeaders_1.merge(new Headers(defaultHeaders), new Headers(headers)); | ||
const res = await fetch(uri, requestInit); | ||
return new ResponseWrapper_1.ResponseWrapper(uri, res); | ||
const res = await fetch(effectiveUri, requestInit); | ||
return new ResponseWrapper_1.ResponseWrapper(effectiveUri, res); | ||
} | ||
function fetchResource(uri, headers) { | ||
return getResponse(uri, 'get', headers); | ||
function fetchResource(uri, headers, baseUri) { | ||
return getResponse(uri, { | ||
method: 'get', | ||
headers, | ||
baseUri, | ||
}); | ||
} | ||
exports.fetchResource = fetchResource; | ||
function invokeOperation(method, uri, body, headers) { | ||
return getResponse(uri, method, headers, body); | ||
function invokeOperation(method, uri, body, headers, baseUri) { | ||
return getResponse(uri, { method, headers, body, baseUri }); | ||
} | ||
exports.invokeOperation = invokeOperation; | ||
//# sourceMappingURL=FetchUtil.js.map |
{ | ||
"name": "alcaeus", | ||
"version": "0.10.6", | ||
"version": "0.10.7", | ||
"description": "Hydra Core hypermedia-aware client library", | ||
@@ -44,3 +44,3 @@ "main": "lib/node/index.node.js", | ||
}, | ||
"homepage": "https://github.com/wikibus/alcaeus#readme", | ||
"homepage": "https://alcaeus.hydra.how", | ||
"dependencies": { | ||
@@ -47,0 +47,0 @@ "@rdfjs/parser-jsonld": "^1.1.1", |
@@ -15,2 +15,3 @@ import { IHydraResponse } from './HydraResponse'; | ||
export declare class Alcaeus implements IHydraClient { | ||
baseUri?: string; | ||
rootSelectors: IRootSelector[]; | ||
@@ -17,0 +18,0 @@ mediaTypeProcessors: { |
import { ResponseWrapper } from './ResponseWrapper'; | ||
export declare function fetchResource(uri: string, headers: HeadersInit): Promise<ResponseWrapper>; | ||
export declare function invokeOperation(method: string, uri: string, body?: BodyInit, headers?: HeadersInit): Promise<ResponseWrapper>; | ||
export declare function fetchResource(uri: string, headers: HeadersInit, baseUri?: string): Promise<ResponseWrapper>; | ||
export declare function invokeOperation(method: string, uri: string, body?: BodyInit, headers?: HeadersInit, baseUri?: string): Promise<ResponseWrapper>; |
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
368976
5391