Skip to content

Commit ce37d7e

Browse files
committed
Update naming and documentation
1 parent 939c60c commit ce37d7e

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

src/api.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ const MEDIATYPES = {
2626
PNG: "image/png"
2727
};
2828

29+
/**
30+
* A callback with the request instance and metadata information
31+
* of the currently request being executed that should necessarily
32+
* return the given request optionally modified.
33+
* @typedef {function} RequestInterceptor
34+
* @param {XMLHttpRequest} request - The original XMLHttpRequest instance.
35+
* @param {object} metadata - The metadata used by the request.
36+
*/
37+
2938
/**
3039
* Class for interacting with DICOMweb RESTful services.
3140
*/
@@ -37,7 +46,7 @@ class DICOMwebClient {
3746
* @param {String} options.username - Username
3847
* @param {String} options.password - Password
3948
* @param {Object} options.headers - HTTP headers
40-
* @param {Array} options.enhancers - Enhancers
49+
* @param {Array.<RequestInterceptor>} options.requestInterceptors - Request interceptors.
4150
*/
4251
constructor(options) {
4352
this.baseURL = options.url;
@@ -76,8 +85,8 @@ class DICOMwebClient {
7685
this.stowURL = this.baseURL;
7786
}
7887

79-
if ("enhancers" in options) {
80-
this.enhancers = options.enhancers;
88+
if ("requestInterceptors" in options) {
89+
this.requestInterceptors = options.requestInterceptors;
8190
}
8291

8392
// Headers to pass to requests.
@@ -105,12 +114,13 @@ class DICOMwebClient {
105114
* @param {String} method
106115
* @param {Object} headers
107116
* @param {Object} options
117+
* @param {Array.<RequestInterceptor>} options.requestInterceptors - Request interceptors.
108118
* @return {*}
109119
* @private
110120
*/
111121
_httpRequest(url, method, headers, options = {}) {
112122

113-
const {errorInterceptor} = this;
123+
const { errorInterceptor, requestInterceptors } = this;
114124

115125
return new Promise((resolve, reject) => {
116126
let request = new XMLHttpRequest();
@@ -176,10 +186,10 @@ class DICOMwebClient {
176186
}
177187
}
178188

179-
if ("enhancers" in options) {
189+
if (requestInterceptors) {
180190
const metadata = { method, url };
181-
const pipe = functions => (args) => functions.reduce((args, fn) => fn(args, metadata), args);
182-
const pipedRequest = pipe(options.enhancers);
191+
const pipeRequestInterceptors = functions => (args) => functions.reduce((args, fn) => fn(args, metadata), args);
192+
const pipedRequest = pipeRequestInterceptors(requestInterceptors);
183193
request = pipedRequest(request);
184194
}
185195

@@ -202,9 +212,7 @@ class DICOMwebClient {
202212
* @private
203213
*/
204214
_httpGet(url, headers, responseType, progressCallback) {
205-
const options = { responseType, progressCallback };
206-
if (this.enhancers) options.enhancers = this.enhancers;
207-
return this._httpRequest(url, "get", headers, options);
215+
return this._httpRequest(url, "get", headers, { responseType, progressCallback });
208216
}
209217

210218
/**
@@ -640,9 +648,7 @@ class DICOMwebClient {
640648
* @returns {Promise} Response
641649
*/
642650
_httpPost(url, headers, data, progressCallback) {
643-
const options = { data, progressCallback };
644-
if (this.enhancers) options.enhancers = this.enhancers;
645-
return this._httpRequest(url, "post", headers, options);
651+
return this._httpRequest(url, "post", headers, { data, progressCallback });
646652
}
647653

648654
/**

0 commit comments

Comments
 (0)