@ama-sdk/client-fetch 12.1.10 → 12.1.12
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.
- package/cjs/api-fetch-client.js +16 -21
- package/cjs/plugins/abort/abort.spec.js +83 -81
- package/cjs/plugins/concurrent/concurrent.fetch.js +12 -20
- package/cjs/plugins/concurrent/concurrent.spec.js +99 -99
- package/cjs/plugins/keepalive/keepalive.request.js +7 -12
- package/cjs/plugins/keepalive/keepalive.spec.js +32 -34
- package/cjs/plugins/mock-intercept/mock-intercept.fetch.js +15 -22
- package/cjs/plugins/mock-intercept/mock-intercept.spec.js +247 -239
- package/cjs/plugins/perf-metric/perf-metric.fetch.js +11 -18
- package/cjs/plugins/retry/retry.fetch.js +18 -27
- package/cjs/plugins/retry/retry.spec.js +233 -225
- package/cjs/plugins/timeout/timeout.fetch.js +16 -22
- package/cjs/plugins/timeout/timeout.spec.js +211 -205
- package/cjs/plugins/wait-for/wait-for.fetch.js +19 -29
- package/cjs/plugins/wait-for/wait-for.spec.js +211 -203
- package/esm2015/api-fetch-client.js +16 -21
- package/esm2015/plugins/abort/abort.spec.js +83 -81
- package/esm2015/plugins/concurrent/concurrent.fetch.js +12 -20
- package/esm2015/plugins/concurrent/concurrent.spec.js +99 -99
- package/esm2015/plugins/keepalive/keepalive.request.js +7 -12
- package/esm2015/plugins/keepalive/keepalive.spec.js +32 -34
- package/esm2015/plugins/mock-intercept/mock-intercept.fetch.js +15 -22
- package/esm2015/plugins/mock-intercept/mock-intercept.spec.js +247 -239
- package/esm2015/plugins/perf-metric/perf-metric.fetch.js +11 -18
- package/esm2015/plugins/retry/retry.fetch.js +18 -27
- package/esm2015/plugins/retry/retry.spec.js +233 -225
- package/esm2015/plugins/timeout/timeout.fetch.js +13 -19
- package/esm2015/plugins/timeout/timeout.spec.js +211 -205
- package/esm2015/plugins/wait-for/wait-for.fetch.js +19 -29
- package/esm2015/plugins/wait-for/wait-for.spec.js +211 -203
- package/package.json +12 -8
- package/schematics/ng-add/index.d.ts.map +1 -1
- package/schematics/ng-add/index.js +14 -12
- package/schematics/ng-add/index.js.map +1 -1
|
@@ -131,7 +131,7 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
131
131
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
132
132
|
}
|
|
133
133
|
function _ts_generator(thisArg, body) {
|
|
134
|
-
var f, y, t,
|
|
134
|
+
var f, y, t, _ = {
|
|
135
135
|
label: 0,
|
|
136
136
|
sent: function() {
|
|
137
137
|
if (t[0] & 1) throw t[1];
|
|
@@ -139,12 +139,8 @@ function _ts_generator(thisArg, body) {
|
|
|
139
139
|
},
|
|
140
140
|
trys: [],
|
|
141
141
|
ops: []
|
|
142
|
-
};
|
|
143
|
-
return g = {
|
|
144
|
-
next: verb(0),
|
|
145
|
-
"throw": verb(1),
|
|
146
|
-
"return": verb(2)
|
|
147
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
142
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
143
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
148
144
|
return this;
|
|
149
145
|
}), g;
|
|
150
146
|
function verb(n) {
|
|
@@ -157,7 +153,7 @@ function _ts_generator(thisArg, body) {
|
|
|
157
153
|
}
|
|
158
154
|
function step(op) {
|
|
159
155
|
if (f) throw new TypeError("Generator is already executing.");
|
|
160
|
-
while(_)try {
|
|
156
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
161
157
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
162
158
|
if (y = 0, t) op = [
|
|
163
159
|
op[0] & 2,
|
|
@@ -272,7 +268,6 @@ var DEFAULT_OPTIONS = {
|
|
|
272
268
|
{
|
|
273
269
|
key: "getRequestOptions",
|
|
274
270
|
value: /** @inheritdoc */ function getRequestOptions(requestOptionsParameters) {
|
|
275
|
-
var _this = this;
|
|
276
271
|
return _async_to_generator(function() {
|
|
277
272
|
var opts, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, plugin, _requestOptionsParameters_api, err;
|
|
278
273
|
return _ts_generator(this, function(_state) {
|
|
@@ -282,7 +277,7 @@ var DEFAULT_OPTIONS = {
|
|
|
282
277
|
headers: new Headers(filterUndefinedValues(requestOptionsParameters.headers)),
|
|
283
278
|
queryParams: filterUndefinedValues(requestOptionsParameters.queryParams)
|
|
284
279
|
});
|
|
285
|
-
if (!
|
|
280
|
+
if (!this.options.requestPlugins) return [
|
|
286
281
|
3,
|
|
287
282
|
8
|
|
288
283
|
];
|
|
@@ -295,7 +290,7 @@ var DEFAULT_OPTIONS = {
|
|
|
295
290
|
7,
|
|
296
291
|
8
|
|
297
292
|
]);
|
|
298
|
-
_iterator =
|
|
293
|
+
_iterator = this.options.requestPlugins[Symbol.iterator]();
|
|
299
294
|
_state.label = 2;
|
|
300
295
|
case 2:
|
|
301
296
|
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
|
|
@@ -306,7 +301,7 @@ var DEFAULT_OPTIONS = {
|
|
|
306
301
|
return [
|
|
307
302
|
4,
|
|
308
303
|
plugin.load({
|
|
309
|
-
logger:
|
|
304
|
+
logger: this.options.logger,
|
|
310
305
|
apiName: (_requestOptionsParameters_api = requestOptionsParameters.api) === null || _requestOptionsParameters_api === void 0 ? void 0 : _requestOptionsParameters_api.apiName
|
|
311
306
|
}).transform(opts)
|
|
312
307
|
];
|
|
@@ -352,7 +347,7 @@ var DEFAULT_OPTIONS = {
|
|
|
352
347
|
];
|
|
353
348
|
}
|
|
354
349
|
});
|
|
355
|
-
})();
|
|
350
|
+
}).call(this);
|
|
356
351
|
}
|
|
357
352
|
},
|
|
358
353
|
{
|
|
@@ -395,12 +390,12 @@ var DEFAULT_OPTIONS = {
|
|
|
395
390
|
{
|
|
396
391
|
key: "processCall",
|
|
397
392
|
value: function processCall(url, options, apiType, apiName, revivers, operationId) {
|
|
398
|
-
var _this = this;
|
|
399
393
|
return _async_to_generator(function() {
|
|
400
|
-
var response, asyncResponse, root, body, exception, origin, _options_metadata, metadataSignal, controller, loadedPlugins, _loadedPlugins, canStart, isCanceledBy, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, plugin, e, reviver, replyPlugins, parsedData, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, pluginRunner, err;
|
|
394
|
+
var _this, response, asyncResponse, root, body, exception, origin, _options_metadata, metadataSignal, controller, loadedPlugins, _loadedPlugins, canStart, isCanceledBy, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, plugin, e, reviver, replyPlugins, parsedData, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, pluginRunner, err;
|
|
401
395
|
return _ts_generator(this, function(_state) {
|
|
402
396
|
switch(_state.label){
|
|
403
397
|
case 0:
|
|
398
|
+
_this = this;
|
|
404
399
|
origin = options.headers.get('Origin');
|
|
405
400
|
_state.label = 1;
|
|
406
401
|
case 1:
|
|
@@ -418,9 +413,9 @@ var DEFAULT_OPTIONS = {
|
|
|
418
413
|
return controller.abort();
|
|
419
414
|
});
|
|
420
415
|
loadedPlugins = [];
|
|
421
|
-
if (
|
|
416
|
+
if (this.options.fetchPlugins) {
|
|
422
417
|
;
|
|
423
|
-
(_loadedPlugins = loadedPlugins).push.apply(_loadedPlugins, _to_consumable_array(
|
|
418
|
+
(_loadedPlugins = loadedPlugins).push.apply(_loadedPlugins, _to_consumable_array(this.options.fetchPlugins.map(function(plugin) {
|
|
424
419
|
return plugin.load({
|
|
425
420
|
url: url,
|
|
426
421
|
options: options,
|
|
@@ -440,7 +435,7 @@ var DEFAULT_OPTIONS = {
|
|
|
440
435
|
case 2:
|
|
441
436
|
canStart = _state.sent();
|
|
442
437
|
isCanceledBy = canStart.indexOf(false);
|
|
443
|
-
asyncResponse = isCanceledBy === -1 ? fetch(url, options) : Promise.reject(new CanceledCallError("Is canceled by the plugin ".concat(isCanceledBy), isCanceledBy,
|
|
438
|
+
asyncResponse = isCanceledBy === -1 ? fetch(url, options) : Promise.reject(new CanceledCallError("Is canceled by the plugin ".concat(isCanceledBy), isCanceledBy, this.options.fetchPlugins[isCanceledBy], {
|
|
444
439
|
apiName: apiName,
|
|
445
440
|
operationId: operationId,
|
|
446
441
|
url: url,
|
|
@@ -518,10 +513,10 @@ var DEFAULT_OPTIONS = {
|
|
|
518
513
|
}
|
|
519
514
|
// eslint-disable-next-line no-console -- `console.error` is supposed to be the default value if the `options` argument is not provided, can be removed in Otter v12.
|
|
520
515
|
reviver = getResponseReviver(revivers, response, operationId, {
|
|
521
|
-
disableFallback:
|
|
516
|
+
disableFallback: this.options.disableFallback,
|
|
522
517
|
log: console.error
|
|
523
518
|
});
|
|
524
|
-
replyPlugins =
|
|
519
|
+
replyPlugins = this.options.replyPlugins ? this.options.replyPlugins.map(function(plugin) {
|
|
525
520
|
return plugin.load({
|
|
526
521
|
dictionaries: root && root.dictionaries,
|
|
527
522
|
response: response,
|
|
@@ -602,7 +597,7 @@ var DEFAULT_OPTIONS = {
|
|
|
602
597
|
];
|
|
603
598
|
}
|
|
604
599
|
});
|
|
605
|
-
})();
|
|
600
|
+
}).call(this);
|
|
606
601
|
}
|
|
607
602
|
}
|
|
608
603
|
]);
|
|
@@ -28,7 +28,7 @@ function _async_to_generator(fn) {
|
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
function _ts_generator(thisArg, body) {
|
|
31
|
-
var f, y, t,
|
|
31
|
+
var f, y, t, _ = {
|
|
32
32
|
label: 0,
|
|
33
33
|
sent: function() {
|
|
34
34
|
if (t[0] & 1) throw t[1];
|
|
@@ -36,12 +36,8 @@ function _ts_generator(thisArg, body) {
|
|
|
36
36
|
},
|
|
37
37
|
trys: [],
|
|
38
38
|
ops: []
|
|
39
|
-
};
|
|
40
|
-
return g = {
|
|
41
|
-
next: verb(0),
|
|
42
|
-
"throw": verb(1),
|
|
43
|
-
"return": verb(2)
|
|
44
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
39
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
40
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
45
41
|
return this;
|
|
46
42
|
}), g;
|
|
47
43
|
function verb(n) {
|
|
@@ -54,7 +50,7 @@ function _ts_generator(thisArg, body) {
|
|
|
54
50
|
}
|
|
55
51
|
function step(op) {
|
|
56
52
|
if (f) throw new TypeError("Generator is already executing.");
|
|
57
|
-
while(_)try {
|
|
53
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
58
54
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
59
55
|
if (y = 0, t) op = [
|
|
60
56
|
op[0] & 2,
|
|
@@ -124,77 +120,83 @@ function _ts_generator(thisArg, body) {
|
|
|
124
120
|
}
|
|
125
121
|
import { AbortFetch } from './abort.fetch';
|
|
126
122
|
describe('Abort Plugin', function() {
|
|
127
|
-
it('should trigger the callback',
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
runner.
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
123
|
+
it('should trigger the callback', function() {
|
|
124
|
+
return _async_to_generator(function() {
|
|
125
|
+
var fn, plugin, runner;
|
|
126
|
+
return _ts_generator(this, function(_state) {
|
|
127
|
+
switch(_state.label){
|
|
128
|
+
case 0:
|
|
129
|
+
fn = jest.fn();
|
|
130
|
+
plugin = new AbortFetch(fn);
|
|
131
|
+
runner = plugin.load({});
|
|
132
|
+
return [
|
|
133
|
+
4,
|
|
134
|
+
runner.transform(Promise.resolve())
|
|
135
|
+
];
|
|
136
|
+
case 1:
|
|
137
|
+
_state.sent();
|
|
138
|
+
expect(fn).toHaveBeenCalled();
|
|
139
|
+
return [
|
|
140
|
+
2
|
|
141
|
+
];
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
})();
|
|
145
|
+
});
|
|
146
|
+
it('should trigger abort signal if true', function() {
|
|
147
|
+
return _async_to_generator(function() {
|
|
148
|
+
var defaultContext, fn, plugin, runner;
|
|
149
|
+
return _ts_generator(this, function(_state) {
|
|
150
|
+
switch(_state.label){
|
|
151
|
+
case 0:
|
|
152
|
+
defaultContext = {
|
|
153
|
+
controller: {
|
|
154
|
+
abort: jest.fn()
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
fn = jest.fn().mockResolvedValue(true);
|
|
158
|
+
plugin = new AbortFetch(fn);
|
|
159
|
+
runner = plugin.load(defaultContext);
|
|
160
|
+
return [
|
|
161
|
+
4,
|
|
162
|
+
runner.transform(Promise.resolve())
|
|
163
|
+
];
|
|
164
|
+
case 1:
|
|
165
|
+
_state.sent();
|
|
166
|
+
expect(defaultContext.controller.abort).toHaveBeenCalled();
|
|
167
|
+
return [
|
|
168
|
+
2
|
|
169
|
+
];
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
})();
|
|
173
|
+
});
|
|
174
|
+
it('should not trigger abort signal if false', function() {
|
|
175
|
+
return _async_to_generator(function() {
|
|
176
|
+
var defaultContext, fn, plugin, runner;
|
|
177
|
+
return _ts_generator(this, function(_state) {
|
|
178
|
+
switch(_state.label){
|
|
179
|
+
case 0:
|
|
180
|
+
defaultContext = {
|
|
181
|
+
controller: {
|
|
182
|
+
abort: jest.fn()
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
fn = jest.fn().mockResolvedValue(false);
|
|
186
|
+
plugin = new AbortFetch(fn);
|
|
187
|
+
runner = plugin.load(defaultContext);
|
|
188
|
+
return [
|
|
189
|
+
4,
|
|
190
|
+
runner.transform(Promise.resolve())
|
|
191
|
+
];
|
|
192
|
+
case 1:
|
|
193
|
+
_state.sent();
|
|
194
|
+
expect(defaultContext.controller.abort).not.toHaveBeenCalled();
|
|
195
|
+
return [
|
|
196
|
+
2
|
|
197
|
+
];
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
})();
|
|
201
|
+
});
|
|
200
202
|
});
|
|
@@ -60,7 +60,7 @@ function _define_property(obj, key, value) {
|
|
|
60
60
|
return obj;
|
|
61
61
|
}
|
|
62
62
|
function _ts_generator(thisArg, body) {
|
|
63
|
-
var f, y, t,
|
|
63
|
+
var f, y, t, _ = {
|
|
64
64
|
label: 0,
|
|
65
65
|
sent: function() {
|
|
66
66
|
if (t[0] & 1) throw t[1];
|
|
@@ -68,12 +68,8 @@ function _ts_generator(thisArg, body) {
|
|
|
68
68
|
},
|
|
69
69
|
trys: [],
|
|
70
70
|
ops: []
|
|
71
|
-
};
|
|
72
|
-
return g = {
|
|
73
|
-
next: verb(0),
|
|
74
|
-
"throw": verb(1),
|
|
75
|
-
"return": verb(2)
|
|
76
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
71
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
72
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
77
73
|
return this;
|
|
78
74
|
}), g;
|
|
79
75
|
function verb(n) {
|
|
@@ -86,7 +82,7 @@ function _ts_generator(thisArg, body) {
|
|
|
86
82
|
}
|
|
87
83
|
function step(op) {
|
|
88
84
|
if (f) throw new TypeError("Generator is already executing.");
|
|
89
|
-
while(_)try {
|
|
85
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
90
86
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
91
87
|
if (y = 0, t) op = [
|
|
92
88
|
op[0] & 2,
|
|
@@ -191,20 +187,19 @@ function _ts_generator(thisArg, body) {
|
|
|
191
187
|
value: /** @inheritDoc */ function load(_context) {
|
|
192
188
|
var _this = this;
|
|
193
189
|
this.poolSize++;
|
|
194
|
-
var _this1 = this;
|
|
195
190
|
return {
|
|
196
191
|
canStart: function() {
|
|
197
192
|
return new Promise(function(resolve) {
|
|
198
193
|
return _this.canStart() ? resolve(true) : _this.waitingResolvers.push(resolve);
|
|
199
194
|
});
|
|
200
195
|
},
|
|
201
|
-
transform:
|
|
202
|
-
|
|
196
|
+
transform: function(fetchCall) {
|
|
197
|
+
return _async_to_generator(function() {
|
|
203
198
|
var fetchResponse;
|
|
204
199
|
return _ts_generator(this, function(_state) {
|
|
205
200
|
switch(_state.label){
|
|
206
201
|
case 0:
|
|
207
|
-
|
|
202
|
+
this.pool.push(fetchCall);
|
|
208
203
|
_state.label = 1;
|
|
209
204
|
case 1:
|
|
210
205
|
_state.trys.push([
|
|
@@ -224,11 +219,11 @@ function _ts_generator(thisArg, body) {
|
|
|
224
219
|
fetchResponse
|
|
225
220
|
];
|
|
226
221
|
case 3:
|
|
227
|
-
|
|
222
|
+
this.pool = this.pool.filter(function(call) {
|
|
228
223
|
return call !== fetchCall;
|
|
229
224
|
});
|
|
230
|
-
|
|
231
|
-
|
|
225
|
+
this.poolSize--;
|
|
226
|
+
this.unstackResolve();
|
|
232
227
|
return [
|
|
233
228
|
7
|
|
234
229
|
];
|
|
@@ -238,11 +233,8 @@ function _ts_generator(thisArg, body) {
|
|
|
238
233
|
];
|
|
239
234
|
}
|
|
240
235
|
});
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
return _ref.apply(this, arguments);
|
|
244
|
-
};
|
|
245
|
-
}()
|
|
236
|
+
}).call(_this);
|
|
237
|
+
}
|
|
246
238
|
};
|
|
247
239
|
}
|
|
248
240
|
}
|
|
@@ -28,7 +28,7 @@ function _async_to_generator(fn) {
|
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
function _ts_generator(thisArg, body) {
|
|
31
|
-
var f, y, t,
|
|
31
|
+
var f, y, t, _ = {
|
|
32
32
|
label: 0,
|
|
33
33
|
sent: function() {
|
|
34
34
|
if (t[0] & 1) throw t[1];
|
|
@@ -36,12 +36,8 @@ function _ts_generator(thisArg, body) {
|
|
|
36
36
|
},
|
|
37
37
|
trys: [],
|
|
38
38
|
ops: []
|
|
39
|
-
};
|
|
40
|
-
return g = {
|
|
41
|
-
next: verb(0),
|
|
42
|
-
"throw": verb(1),
|
|
43
|
-
"return": verb(2)
|
|
44
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
39
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
40
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
45
41
|
return this;
|
|
46
42
|
}), g;
|
|
47
43
|
function verb(n) {
|
|
@@ -54,7 +50,7 @@ function _ts_generator(thisArg, body) {
|
|
|
54
50
|
}
|
|
55
51
|
function step(op) {
|
|
56
52
|
if (f) throw new TypeError("Generator is already executing.");
|
|
57
|
-
while(_)try {
|
|
53
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
58
54
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
59
55
|
if (y = 0, t) op = [
|
|
60
56
|
op[0] & 2,
|
|
@@ -124,27 +120,29 @@ function _ts_generator(thisArg, body) {
|
|
|
124
120
|
}
|
|
125
121
|
import { ConcurrentFetch } from './concurrent.fetch';
|
|
126
122
|
describe('Concurrent Fetch Plugin', function() {
|
|
127
|
-
it('should start if the limit is not reach',
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
123
|
+
it('should start if the limit is not reach', function() {
|
|
124
|
+
return _async_to_generator(function() {
|
|
125
|
+
var plugin, runner, canStart;
|
|
126
|
+
return _ts_generator(this, function(_state) {
|
|
127
|
+
switch(_state.label){
|
|
128
|
+
case 0:
|
|
129
|
+
plugin = new ConcurrentFetch(3);
|
|
130
|
+
plugin.load({});
|
|
131
|
+
runner = plugin.load({});
|
|
132
|
+
return [
|
|
133
|
+
4,
|
|
134
|
+
runner.canStart()
|
|
135
|
+
];
|
|
136
|
+
case 1:
|
|
137
|
+
canStart = _state.sent();
|
|
138
|
+
expect(canStart).toBe(true);
|
|
139
|
+
return [
|
|
140
|
+
2
|
|
141
|
+
];
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
})();
|
|
145
|
+
});
|
|
148
146
|
it('should retrieve the fetch call in the pool', function() {
|
|
149
147
|
var plugin = new ConcurrentFetch(3);
|
|
150
148
|
var call = new Promise(function(resolve) {
|
|
@@ -162,74 +160,76 @@ describe('Concurrent Fetch Plugin', function() {
|
|
|
162
160
|
void plugin.load({}).transform(test);
|
|
163
161
|
expect(plugin.pool[2]).toBe(test);
|
|
164
162
|
});
|
|
165
|
-
it('should start only when the pool is available',
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
163
|
+
it('should start only when the pool is available', function() {
|
|
164
|
+
return _async_to_generator(function() {
|
|
165
|
+
var plugin, resolves, call0, call1, result, runner1, canStart1, runner2, pCanStart2;
|
|
166
|
+
return _ts_generator(this, function(_state) {
|
|
167
|
+
switch(_state.label){
|
|
168
|
+
case 0:
|
|
169
|
+
plugin = new ConcurrentFetch(2);
|
|
170
|
+
resolves = [
|
|
171
|
+
null,
|
|
172
|
+
null
|
|
173
|
+
];
|
|
174
|
+
call0 = new Promise(function(resolve) {
|
|
175
|
+
return resolves[0] = resolve;
|
|
176
|
+
});
|
|
177
|
+
call1 = new Promise(function(resolve) {
|
|
178
|
+
return resolves[1] = resolve;
|
|
179
|
+
});
|
|
180
|
+
result = {
|
|
181
|
+
res: false
|
|
182
|
+
};
|
|
183
|
+
void plugin.load({}).transform(call0);
|
|
184
|
+
runner1 = plugin.load({});
|
|
185
|
+
canStart1 = runner1.canStart();
|
|
186
|
+
return [
|
|
187
|
+
4,
|
|
188
|
+
jest.runAllTimersAsync()
|
|
189
|
+
];
|
|
190
|
+
case 1:
|
|
191
|
+
_state.sent();
|
|
192
|
+
return [
|
|
193
|
+
4,
|
|
194
|
+
canStart1
|
|
195
|
+
];
|
|
196
|
+
case 2:
|
|
197
|
+
expect.apply(void 0, [
|
|
198
|
+
_state.sent()
|
|
199
|
+
]).toBe(true);
|
|
200
|
+
void runner1.transform(call1);
|
|
201
|
+
runner2 = plugin.load({});
|
|
202
|
+
pCanStart2 = runner2.canStart();
|
|
203
|
+
return [
|
|
204
|
+
4,
|
|
205
|
+
jest.runAllTimersAsync()
|
|
206
|
+
];
|
|
207
|
+
case 3:
|
|
208
|
+
_state.sent();
|
|
209
|
+
expect(plugin.waitingResolvers.length).toBe(1);
|
|
210
|
+
result.res = true;
|
|
211
|
+
resolves[0]();
|
|
212
|
+
return [
|
|
213
|
+
4,
|
|
214
|
+
pCanStart2
|
|
215
|
+
];
|
|
216
|
+
case 4:
|
|
217
|
+
expect.apply(void 0, [
|
|
218
|
+
_state.sent()
|
|
219
|
+
]).toBe(true);
|
|
220
|
+
resolves[1]();
|
|
221
|
+
return [
|
|
222
|
+
4,
|
|
223
|
+
jest.advanceTimersByTimeAsync(500)
|
|
224
|
+
];
|
|
225
|
+
case 5:
|
|
226
|
+
_state.sent();
|
|
227
|
+
expect(plugin.waitingResolvers.length).toBe(0);
|
|
228
|
+
return [
|
|
229
|
+
2
|
|
230
|
+
];
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
})();
|
|
234
|
+
});
|
|
235
235
|
});
|