axios 1.7.1 → 1.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of axios might be problematic. Click here for more details.
- package/CHANGELOG.md +26 -0
- package/dist/axios.js +172 -82
- package/dist/axios.js.map +1 -1
- package/dist/axios.min.js +1 -1
- package/dist/axios.min.js.map +1 -1
- package/dist/browser/axios.cjs +157 -81
- package/dist/browser/axios.cjs.map +1 -1
- package/dist/esm/axios.js +156 -80
- package/dist/esm/axios.js.map +1 -1
- package/dist/esm/axios.min.js +1 -1
- package/dist/esm/axios.min.js.map +1 -1
- package/dist/node/axios.cjs +278 -240
- package/dist/node/axios.cjs.map +1 -1
- package/lib/adapters/fetch.js +34 -32
- package/lib/adapters/http.js +25 -15
- package/lib/adapters/xhr.js +22 -15
- package/lib/env/data.js +1 -1
- package/lib/helpers/AxiosTransformStream.js +3 -52
- package/lib/helpers/progressEventReducer.js +16 -4
- package/lib/helpers/throttle.js +29 -20
- package/lib/helpers/trackStream.js +25 -13
- package/lib/utils.js +33 -1
- package/package.json +2 -2
package/lib/adapters/fetch.js
CHANGED
@@ -4,29 +4,28 @@ import AxiosError from "../core/AxiosError.js";
|
|
4
4
|
import composeSignals from "../helpers/composeSignals.js";
|
5
5
|
import {trackStream} from "../helpers/trackStream.js";
|
6
6
|
import AxiosHeaders from "../core/AxiosHeaders.js";
|
7
|
-
import progressEventReducer from "../helpers/progressEventReducer.js";
|
7
|
+
import {progressEventReducer, progressEventDecorator, asyncDecorator} from "../helpers/progressEventReducer.js";
|
8
8
|
import resolveConfig from "../helpers/resolveConfig.js";
|
9
9
|
import settle from "../core/settle.js";
|
10
10
|
|
11
|
-
const
|
12
|
-
|
13
|
-
return (loaded) => setTimeout(() => fn({
|
14
|
-
lengthComputable,
|
15
|
-
total,
|
16
|
-
loaded
|
17
|
-
}));
|
18
|
-
}
|
19
|
-
|
20
|
-
const isFetchSupported = typeof fetch !== 'undefined';
|
21
|
-
const isReadableStreamSupported = isFetchSupported && typeof ReadableStream !== 'undefined';
|
11
|
+
const isFetchSupported = typeof fetch === 'function' && typeof Request === 'function' && typeof Response === 'function';
|
12
|
+
const isReadableStreamSupported = isFetchSupported && typeof ReadableStream === 'function';
|
22
13
|
|
23
14
|
// used only inside the fetch adapter
|
24
|
-
const encodeText = isFetchSupported && (typeof TextEncoder
|
15
|
+
const encodeText = isFetchSupported && (typeof TextEncoder === 'function' ?
|
25
16
|
((encoder) => (str) => encoder.encode(str))(new TextEncoder()) :
|
26
17
|
async (str) => new Uint8Array(await new Response(str).arrayBuffer())
|
27
18
|
);
|
28
19
|
|
29
|
-
const
|
20
|
+
const test = (fn, ...args) => {
|
21
|
+
try {
|
22
|
+
return !!fn(...args);
|
23
|
+
} catch (e) {
|
24
|
+
return false
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
const supportsRequestStream = isReadableStreamSupported && test(() => {
|
30
29
|
let duplexAccessed = false;
|
31
30
|
|
32
31
|
const hasContentType = new Request(platform.origin, {
|
@@ -39,17 +38,13 @@ const supportsRequestStream = isReadableStreamSupported && (() => {
|
|
39
38
|
}).headers.has('Content-Type');
|
40
39
|
|
41
40
|
return duplexAccessed && !hasContentType;
|
42
|
-
})
|
41
|
+
});
|
43
42
|
|
44
43
|
const DEFAULT_CHUNK_SIZE = 64 * 1024;
|
45
44
|
|
46
|
-
const supportsResponseStream = isReadableStreamSupported &&
|
47
|
-
|
48
|
-
|
49
|
-
} catch(err) {
|
50
|
-
// return undefined
|
51
|
-
}
|
52
|
-
})();
|
45
|
+
const supportsResponseStream = isReadableStreamSupported &&
|
46
|
+
test(() => utils.isReadableStream(new Response('').body));
|
47
|
+
|
53
48
|
|
54
49
|
const resolvers = {
|
55
50
|
stream: supportsResponseStream && ((res) => res.body)
|
@@ -77,7 +72,7 @@ const getBodyLength = async (body) => {
|
|
77
72
|
return (await new Request(body).arrayBuffer()).byteLength;
|
78
73
|
}
|
79
74
|
|
80
|
-
if(utils.isArrayBufferView(body)) {
|
75
|
+
if(utils.isArrayBufferView(body) || utils.isArrayBuffer(body)) {
|
81
76
|
return body.byteLength;
|
82
77
|
}
|
83
78
|
|
@@ -147,15 +142,17 @@ export default isFetchSupported && (async (config) => {
|
|
147
142
|
}
|
148
143
|
|
149
144
|
if (_request.body) {
|
150
|
-
|
145
|
+
const [onProgress, flush] = progressEventDecorator(
|
151
146
|
requestContentLength,
|
152
|
-
progressEventReducer(onUploadProgress)
|
153
|
-
)
|
147
|
+
progressEventReducer(asyncDecorator(onUploadProgress))
|
148
|
+
);
|
149
|
+
|
150
|
+
data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush, encodeText);
|
154
151
|
}
|
155
152
|
}
|
156
153
|
|
157
154
|
if (!utils.isString(withCredentials)) {
|
158
|
-
withCredentials = withCredentials ? '
|
155
|
+
withCredentials = withCredentials ? 'include' : 'omit';
|
159
156
|
}
|
160
157
|
|
161
158
|
request = new Request(url, {
|
@@ -165,7 +162,7 @@ export default isFetchSupported && (async (config) => {
|
|
165
162
|
headers: headers.normalize().toJSON(),
|
166
163
|
body: data,
|
167
164
|
duplex: "half",
|
168
|
-
withCredentials
|
165
|
+
credentials: withCredentials
|
169
166
|
});
|
170
167
|
|
171
168
|
let response = await fetch(request);
|
@@ -181,11 +178,16 @@ export default isFetchSupported && (async (config) => {
|
|
181
178
|
|
182
179
|
const responseContentLength = utils.toFiniteNumber(response.headers.get('content-length'));
|
183
180
|
|
181
|
+
const [onProgress, flush] = onDownloadProgress && progressEventDecorator(
|
182
|
+
responseContentLength,
|
183
|
+
progressEventReducer(asyncDecorator(onDownloadProgress), true)
|
184
|
+
) || [];
|
185
|
+
|
184
186
|
response = new Response(
|
185
|
-
trackStream(response.body, DEFAULT_CHUNK_SIZE,
|
186
|
-
|
187
|
-
|
188
|
-
|
187
|
+
trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
|
188
|
+
flush && flush();
|
189
|
+
isStreamResponse && onFinish();
|
190
|
+
}, encodeText),
|
189
191
|
options
|
190
192
|
);
|
191
193
|
}
|
package/lib/adapters/http.js
CHANGED
@@ -24,6 +24,7 @@ import formDataToStream from "../helpers/formDataToStream.js";
|
|
24
24
|
import readBlob from "../helpers/readBlob.js";
|
25
25
|
import ZlibHeaderTransformStream from '../helpers/ZlibHeaderTransformStream.js';
|
26
26
|
import callbackify from "../helpers/callbackify.js";
|
27
|
+
import {progressEventReducer, progressEventDecorator, asyncDecorator} from "../helpers/progressEventReducer.js";
|
27
28
|
|
28
29
|
const zlibOptions = {
|
29
30
|
flush: zlib.constants.Z_SYNC_FLUSH,
|
@@ -45,6 +46,14 @@ const supportedProtocols = platform.protocols.map(protocol => {
|
|
45
46
|
return protocol + ':';
|
46
47
|
});
|
47
48
|
|
49
|
+
const flushOnFinish = (stream, [throttled, flush]) => {
|
50
|
+
stream
|
51
|
+
.on('end', flush)
|
52
|
+
.on('error', flush);
|
53
|
+
|
54
|
+
return throttled;
|
55
|
+
}
|
56
|
+
|
48
57
|
/**
|
49
58
|
* If the proxy or config beforeRedirects functions are defined, call them with the options
|
50
59
|
* object.
|
@@ -278,8 +287,7 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
|
|
278
287
|
// Only set header if it hasn't been set in config
|
279
288
|
headers.set('User-Agent', 'axios/' + VERSION, false);
|
280
289
|
|
281
|
-
const onDownloadProgress = config
|
282
|
-
const onUploadProgress = config.onUploadProgress;
|
290
|
+
const {onUploadProgress, onDownloadProgress} = config;
|
283
291
|
const maxRate = config.maxRate;
|
284
292
|
let maxUploadRate = undefined;
|
285
293
|
let maxDownloadRate = undefined;
|
@@ -352,15 +360,16 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
|
|
352
360
|
}
|
353
361
|
|
354
362
|
data = stream.pipeline([data, new AxiosTransformStream({
|
355
|
-
length: contentLength,
|
356
363
|
maxRate: utils.toFiniteNumber(maxUploadRate)
|
357
364
|
})], utils.noop);
|
358
365
|
|
359
|
-
onUploadProgress && data.on('progress',
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
366
|
+
onUploadProgress && data.on('progress', flushOnFinish(
|
367
|
+
data,
|
368
|
+
progressEventDecorator(
|
369
|
+
contentLength,
|
370
|
+
progressEventReducer(asyncDecorator(onUploadProgress), false, 3)
|
371
|
+
)
|
372
|
+
));
|
364
373
|
}
|
365
374
|
|
366
375
|
// HTTP basic authentication
|
@@ -459,17 +468,18 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
|
|
459
468
|
|
460
469
|
const responseLength = +res.headers['content-length'];
|
461
470
|
|
462
|
-
if (onDownloadProgress) {
|
471
|
+
if (onDownloadProgress || maxDownloadRate) {
|
463
472
|
const transformStream = new AxiosTransformStream({
|
464
|
-
length: utils.toFiniteNumber(responseLength),
|
465
473
|
maxRate: utils.toFiniteNumber(maxDownloadRate)
|
466
474
|
});
|
467
475
|
|
468
|
-
onDownloadProgress && transformStream.on('progress',
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
476
|
+
onDownloadProgress && transformStream.on('progress', flushOnFinish(
|
477
|
+
transformStream,
|
478
|
+
progressEventDecorator(
|
479
|
+
responseLength,
|
480
|
+
progressEventReducer(asyncDecorator(onDownloadProgress), true, 3)
|
481
|
+
)
|
482
|
+
));
|
473
483
|
|
474
484
|
streams.push(transformStream);
|
475
485
|
}
|
package/lib/adapters/xhr.js
CHANGED
@@ -6,7 +6,7 @@ import CanceledError from '../cancel/CanceledError.js';
|
|
6
6
|
import parseProtocol from '../helpers/parseProtocol.js';
|
7
7
|
import platform from '../platform/index.js';
|
8
8
|
import AxiosHeaders from '../core/AxiosHeaders.js';
|
9
|
-
import progressEventReducer from '../helpers/progressEventReducer.js';
|
9
|
+
import {progressEventReducer} from '../helpers/progressEventReducer.js';
|
10
10
|
import resolveConfig from "../helpers/resolveConfig.js";
|
11
11
|
|
12
12
|
const isXHRAdapterSupported = typeof XMLHttpRequest !== 'undefined';
|
@@ -16,16 +16,18 @@ export default isXHRAdapterSupported && function (config) {
|
|
16
16
|
const _config = resolveConfig(config);
|
17
17
|
let requestData = _config.data;
|
18
18
|
const requestHeaders = AxiosHeaders.from(_config.headers).normalize();
|
19
|
-
let {responseType} = _config;
|
19
|
+
let {responseType, onUploadProgress, onDownloadProgress} = _config;
|
20
20
|
let onCanceled;
|
21
|
+
let uploadThrottled, downloadThrottled;
|
22
|
+
let flushUpload, flushDownload;
|
23
|
+
|
21
24
|
function done() {
|
22
|
-
|
23
|
-
|
24
|
-
}
|
25
|
+
flushUpload && flushUpload(); // flush events
|
26
|
+
flushDownload && flushDownload(); // flush events
|
25
27
|
|
26
|
-
|
27
|
-
|
28
|
-
|
28
|
+
_config.cancelToken && _config.cancelToken.unsubscribe(onCanceled);
|
29
|
+
|
30
|
+
_config.signal && _config.signal.removeEventListener('abort', onCanceled);
|
29
31
|
}
|
30
32
|
|
31
33
|
let request = new XMLHttpRequest();
|
@@ -95,7 +97,7 @@ export default isXHRAdapterSupported && function (config) {
|
|
95
97
|
return;
|
96
98
|
}
|
97
99
|
|
98
|
-
reject(new AxiosError('Request aborted', AxiosError.ECONNABORTED,
|
100
|
+
reject(new AxiosError('Request aborted', AxiosError.ECONNABORTED, config, request));
|
99
101
|
|
100
102
|
// Clean up request
|
101
103
|
request = null;
|
@@ -105,7 +107,7 @@ export default isXHRAdapterSupported && function (config) {
|
|
105
107
|
request.onerror = function handleError() {
|
106
108
|
// Real errors are hidden from us by the browser
|
107
109
|
// onerror should only fire if it's a network error
|
108
|
-
reject(new AxiosError('Network Error', AxiosError.ERR_NETWORK,
|
110
|
+
reject(new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request));
|
109
111
|
|
110
112
|
// Clean up request
|
111
113
|
request = null;
|
@@ -121,7 +123,7 @@ export default isXHRAdapterSupported && function (config) {
|
|
121
123
|
reject(new AxiosError(
|
122
124
|
timeoutErrorMessage,
|
123
125
|
transitional.clarifyTimeoutError ? AxiosError.ETIMEDOUT : AxiosError.ECONNABORTED,
|
124
|
-
|
126
|
+
config,
|
125
127
|
request));
|
126
128
|
|
127
129
|
// Clean up request
|
@@ -149,13 +151,18 @@ export default isXHRAdapterSupported && function (config) {
|
|
149
151
|
}
|
150
152
|
|
151
153
|
// Handle progress if needed
|
152
|
-
if (
|
153
|
-
|
154
|
+
if (onDownloadProgress) {
|
155
|
+
([downloadThrottled, flushDownload] = progressEventReducer(onDownloadProgress, true));
|
156
|
+
request.addEventListener('progress', downloadThrottled);
|
154
157
|
}
|
155
158
|
|
156
159
|
// Not all browsers support upload events
|
157
|
-
if (
|
158
|
-
|
160
|
+
if (onUploadProgress && request.upload) {
|
161
|
+
([uploadThrottled, flushUpload] = progressEventReducer(onUploadProgress));
|
162
|
+
|
163
|
+
request.upload.addEventListener('progress', uploadThrottled);
|
164
|
+
|
165
|
+
request.upload.addEventListener('loadend', flushUpload);
|
159
166
|
}
|
160
167
|
|
161
168
|
if (_config.cancelToken || _config.signal) {
|
package/lib/env/data.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const VERSION = "1.7.
|
1
|
+
export const VERSION = "1.7.3";
|
@@ -2,8 +2,6 @@
|
|
2
2
|
|
3
3
|
import stream from 'stream';
|
4
4
|
import utils from '../utils.js';
|
5
|
-
import throttle from './throttle.js';
|
6
|
-
import speedometer from './speedometer.js';
|
7
5
|
|
8
6
|
const kInternals = Symbol('internals');
|
9
7
|
|
@@ -24,12 +22,8 @@ class AxiosTransformStream extends stream.Transform{
|
|
24
22
|
readableHighWaterMark: options.chunkSize
|
25
23
|
});
|
26
24
|
|
27
|
-
const self = this;
|
28
|
-
|
29
25
|
const internals = this[kInternals] = {
|
30
|
-
length: options.length,
|
31
26
|
timeWindow: options.timeWindow,
|
32
|
-
ticksRate: options.ticksRate,
|
33
27
|
chunkSize: options.chunkSize,
|
34
28
|
maxRate: options.maxRate,
|
35
29
|
minChunkSize: options.minChunkSize,
|
@@ -41,8 +35,6 @@ class AxiosTransformStream extends stream.Transform{
|
|
41
35
|
onReadCallback: null
|
42
36
|
};
|
43
37
|
|
44
|
-
const _speedometer = speedometer(internals.ticksRate * options.samplesCount, internals.timeWindow);
|
45
|
-
|
46
38
|
this.on('newListener', event => {
|
47
39
|
if (event === 'progress') {
|
48
40
|
if (!internals.isCaptured) {
|
@@ -50,39 +42,6 @@ class AxiosTransformStream extends stream.Transform{
|
|
50
42
|
}
|
51
43
|
}
|
52
44
|
});
|
53
|
-
|
54
|
-
let bytesNotified = 0;
|
55
|
-
|
56
|
-
internals.updateProgress = throttle(function throttledHandler() {
|
57
|
-
const totalBytes = internals.length;
|
58
|
-
const bytesTransferred = internals.bytesSeen;
|
59
|
-
const progressBytes = bytesTransferred - bytesNotified;
|
60
|
-
if (!progressBytes || self.destroyed) return;
|
61
|
-
|
62
|
-
const rate = _speedometer(progressBytes);
|
63
|
-
|
64
|
-
bytesNotified = bytesTransferred;
|
65
|
-
|
66
|
-
process.nextTick(() => {
|
67
|
-
self.emit('progress', {
|
68
|
-
loaded: bytesTransferred,
|
69
|
-
total: totalBytes,
|
70
|
-
progress: totalBytes ? (bytesTransferred / totalBytes) : undefined,
|
71
|
-
bytes: progressBytes,
|
72
|
-
rate: rate ? rate : undefined,
|
73
|
-
estimated: rate && totalBytes && bytesTransferred <= totalBytes ?
|
74
|
-
(totalBytes - bytesTransferred) / rate : undefined,
|
75
|
-
lengthComputable: totalBytes != null
|
76
|
-
});
|
77
|
-
});
|
78
|
-
}, internals.ticksRate);
|
79
|
-
|
80
|
-
const onFinish = () => {
|
81
|
-
internals.updateProgress.call(true);
|
82
|
-
};
|
83
|
-
|
84
|
-
this.once('end', onFinish);
|
85
|
-
this.once('error', onFinish);
|
86
45
|
}
|
87
46
|
|
88
47
|
_read(size) {
|
@@ -96,7 +55,6 @@ class AxiosTransformStream extends stream.Transform{
|
|
96
55
|
}
|
97
56
|
|
98
57
|
_transform(chunk, encoding, callback) {
|
99
|
-
const self = this;
|
100
58
|
const internals = this[kInternals];
|
101
59
|
const maxRate = internals.maxRate;
|
102
60
|
|
@@ -108,16 +66,14 @@ class AxiosTransformStream extends stream.Transform{
|
|
108
66
|
const bytesThreshold = (maxRate / divider);
|
109
67
|
const minChunkSize = internals.minChunkSize !== false ? Math.max(internals.minChunkSize, bytesThreshold * 0.01) : 0;
|
110
68
|
|
111
|
-
|
69
|
+
const pushChunk = (_chunk, _callback) => {
|
112
70
|
const bytes = Buffer.byteLength(_chunk);
|
113
71
|
internals.bytesSeen += bytes;
|
114
72
|
internals.bytes += bytes;
|
115
73
|
|
116
|
-
|
117
|
-
internals.updateProgress();
|
118
|
-
}
|
74
|
+
internals.isCaptured && this.emit('progress', internals.bytesSeen);
|
119
75
|
|
120
|
-
if (
|
76
|
+
if (this.push(_chunk)) {
|
121
77
|
process.nextTick(_callback);
|
122
78
|
} else {
|
123
79
|
internals.onReadCallback = () => {
|
@@ -182,11 +138,6 @@ class AxiosTransformStream extends stream.Transform{
|
|
182
138
|
}
|
183
139
|
});
|
184
140
|
}
|
185
|
-
|
186
|
-
setLength(length) {
|
187
|
-
this[kInternals].length = +length;
|
188
|
-
return this;
|
189
|
-
}
|
190
141
|
}
|
191
142
|
|
192
143
|
export default AxiosTransformStream;
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import speedometer from "./speedometer.js";
|
2
2
|
import throttle from "./throttle.js";
|
3
|
+
import utils from "../utils.js";
|
3
4
|
|
4
|
-
export
|
5
|
+
export const progressEventReducer = (listener, isDownloadStream, freq = 3) => {
|
5
6
|
let bytesNotified = 0;
|
6
7
|
const _speedometer = speedometer(50, 250);
|
7
8
|
|
@@ -22,11 +23,22 @@ export default (listener, isDownloadStream, freq = 3) => {
|
|
22
23
|
rate: rate ? rate : undefined,
|
23
24
|
estimated: rate && total && inRange ? (total - loaded) / rate : undefined,
|
24
25
|
event: e,
|
25
|
-
lengthComputable: total != null
|
26
|
+
lengthComputable: total != null,
|
27
|
+
[isDownloadStream ? 'download' : 'upload']: true
|
26
28
|
};
|
27
29
|
|
28
|
-
data[isDownloadStream ? 'download' : 'upload'] = true;
|
29
|
-
|
30
30
|
listener(data);
|
31
31
|
}, freq);
|
32
32
|
}
|
33
|
+
|
34
|
+
export const progressEventDecorator = (total, throttled) => {
|
35
|
+
const lengthComputable = total != null;
|
36
|
+
|
37
|
+
return [(loaded) => throttled[0]({
|
38
|
+
lengthComputable,
|
39
|
+
total,
|
40
|
+
loaded
|
41
|
+
}), throttled[1]];
|
42
|
+
}
|
43
|
+
|
44
|
+
export const asyncDecorator = (fn) => (...args) => utils.asap(() => fn(...args));
|
package/lib/helpers/throttle.js
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
1
|
/**
|
4
2
|
* Throttle decorator
|
5
3
|
* @param {Function} fn
|
@@ -8,28 +6,39 @@
|
|
8
6
|
*/
|
9
7
|
function throttle(fn, freq) {
|
10
8
|
let timestamp = 0;
|
11
|
-
|
12
|
-
let
|
13
|
-
|
14
|
-
|
9
|
+
let threshold = 1000 / freq;
|
10
|
+
let lastArgs;
|
11
|
+
let timer;
|
12
|
+
|
13
|
+
const invoke = (args, now = Date.now()) => {
|
14
|
+
timestamp = now;
|
15
|
+
lastArgs = null;
|
16
|
+
if (timer) {
|
17
|
+
clearTimeout(timer);
|
18
|
+
timer = null;
|
19
|
+
}
|
20
|
+
fn.apply(null, args);
|
21
|
+
}
|
15
22
|
|
23
|
+
const throttled = (...args) => {
|
16
24
|
const now = Date.now();
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
25
|
+
const passed = now - timestamp;
|
26
|
+
if ( passed >= threshold) {
|
27
|
+
invoke(args, now);
|
28
|
+
} else {
|
29
|
+
lastArgs = args;
|
30
|
+
if (!timer) {
|
31
|
+
timer = setTimeout(() => {
|
32
|
+
timer = null;
|
33
|
+
invoke(lastArgs)
|
34
|
+
}, threshold - passed);
|
21
35
|
}
|
22
|
-
timestamp = now;
|
23
|
-
return fn.apply(null, arguments);
|
24
36
|
}
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
}, threshold - (now - timestamp));
|
31
|
-
}
|
32
|
-
};
|
37
|
+
}
|
38
|
+
|
39
|
+
const flush = () => lastArgs && invoke(lastArgs);
|
40
|
+
|
41
|
+
return [throttled, flush];
|
33
42
|
}
|
34
43
|
|
35
44
|
export default throttle;
|
@@ -1,5 +1,4 @@
|
|
1
1
|
|
2
|
-
|
3
2
|
export const streamChunk = function* (chunk, chunkSize) {
|
4
3
|
let len = chunk.byteLength;
|
5
4
|
|
@@ -28,25 +27,38 @@ export const trackStream = (stream, chunkSize, onProgress, onFinish, encode) =>
|
|
28
27
|
const iterator = readBytes(stream, chunkSize, encode);
|
29
28
|
|
30
29
|
let bytes = 0;
|
30
|
+
let done;
|
31
|
+
let _onFinish = (e) => {
|
32
|
+
if (!done) {
|
33
|
+
done = true;
|
34
|
+
onFinish && onFinish(e);
|
35
|
+
}
|
36
|
+
}
|
31
37
|
|
32
38
|
return new ReadableStream({
|
33
|
-
type: 'bytes',
|
34
|
-
|
35
39
|
async pull(controller) {
|
36
|
-
|
40
|
+
try {
|
41
|
+
const {done, value} = await iterator.next();
|
37
42
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
+
if (done) {
|
44
|
+
_onFinish();
|
45
|
+
controller.close();
|
46
|
+
return;
|
47
|
+
}
|
43
48
|
|
44
|
-
|
45
|
-
|
46
|
-
|
49
|
+
let len = value.byteLength;
|
50
|
+
if (onProgress) {
|
51
|
+
let loadedBytes = bytes += len;
|
52
|
+
onProgress(loadedBytes);
|
53
|
+
}
|
54
|
+
controller.enqueue(new Uint8Array(value));
|
55
|
+
} catch (err) {
|
56
|
+
_onFinish(err);
|
57
|
+
throw err;
|
58
|
+
}
|
47
59
|
},
|
48
60
|
cancel(reason) {
|
49
|
-
|
61
|
+
_onFinish(reason);
|
50
62
|
return iterator.return();
|
51
63
|
}
|
52
64
|
}, {
|
package/lib/utils.js
CHANGED
@@ -669,6 +669,36 @@ const isAsyncFn = kindOfTest('AsyncFunction');
|
|
669
669
|
const isThenable = (thing) =>
|
670
670
|
thing && (isObject(thing) || isFunction(thing)) && isFunction(thing.then) && isFunction(thing.catch);
|
671
671
|
|
672
|
+
// original code
|
673
|
+
// https://github.com/DigitalBrainJS/AxiosPromise/blob/16deab13710ec09779922131f3fa5954320f83ab/lib/utils.js#L11-L34
|
674
|
+
|
675
|
+
const _setImmediate = ((setImmediateSupported, postMessageSupported) => {
|
676
|
+
if (setImmediateSupported) {
|
677
|
+
return setImmediate;
|
678
|
+
}
|
679
|
+
|
680
|
+
return postMessageSupported ? ((token, callbacks) => {
|
681
|
+
_global.addEventListener("message", ({source, data}) => {
|
682
|
+
if (source === _global && data === token) {
|
683
|
+
callbacks.length && callbacks.shift()();
|
684
|
+
}
|
685
|
+
}, false);
|
686
|
+
|
687
|
+
return (cb) => {
|
688
|
+
callbacks.push(cb);
|
689
|
+
_global.postMessage(token, "*");
|
690
|
+
}
|
691
|
+
})(`axios@${Math.random()}`, []) : (cb) => setTimeout(cb);
|
692
|
+
})(
|
693
|
+
typeof setImmediate === 'function',
|
694
|
+
isFunction(_global.postMessage)
|
695
|
+
);
|
696
|
+
|
697
|
+
const asap = typeof queueMicrotask !== 'undefined' ?
|
698
|
+
queueMicrotask.bind(_global) : ( typeof process !== 'undefined' && process.nextTick || _setImmediate);
|
699
|
+
|
700
|
+
// *********************
|
701
|
+
|
672
702
|
export default {
|
673
703
|
isArray,
|
674
704
|
isArrayBuffer,
|
@@ -724,5 +754,7 @@ export default {
|
|
724
754
|
isSpecCompliantForm,
|
725
755
|
toJSONObject,
|
726
756
|
isAsyncFn,
|
727
|
-
isThenable
|
757
|
+
isThenable,
|
758
|
+
setImmediate: _setImmediate,
|
759
|
+
asap
|
728
760
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "axios",
|
3
|
-
"version": "1.7.
|
3
|
+
"version": "1.7.3",
|
4
4
|
"description": "Promise based HTTP client for the browser and node.js",
|
5
5
|
"main": "index.js",
|
6
6
|
"exports": {
|
@@ -160,8 +160,8 @@
|
|
160
160
|
"contributors": [
|
161
161
|
"Matt Zabriskie (https://github.com/mzabriskie)",
|
162
162
|
"Nick Uraltsev (https://github.com/nickuraltsev)",
|
163
|
-
"Jay (https://github.com/jasonsaayman)",
|
164
163
|
"Dmitriy Mozgovoy (https://github.com/DigitalBrainJS)",
|
164
|
+
"Jay (https://github.com/jasonsaayman)",
|
165
165
|
"Emily Morehouse (https://github.com/emilyemorehouse)",
|
166
166
|
"Rubén Norte (https://github.com/rubennorte)",
|
167
167
|
"Justin Beckwith (https://github.com/JustinBeckwith)",
|