@ama-sdk/client-fetch 12.3.0-prerelease.9 → 12.4.0-prerelease.0
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 +18 -22
- 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 +13 -19
- 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 +18 -22
- 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 +15 -15
- package/schematics/ng-add/index.d.ts.map +1 -1
- package/schematics/ng-add/index.js +11 -21
- package/src/api-fetch-client.d.ts +1 -1
- package/src/api-fetch-client.d.ts.map +1 -1
- package/src/api-fetch-client.js +2 -1
- package/src/api-fetch-client.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,
|
|
@@ -234,7 +230,8 @@ var DEFAULT_OPTIONS = {
|
|
|
234
230
|
fetchPlugins: [],
|
|
235
231
|
requestPlugins: [],
|
|
236
232
|
enableTokenization: false,
|
|
237
|
-
disableFallback: false
|
|
233
|
+
disableFallback: false,
|
|
234
|
+
enableParameterSerialization: false
|
|
238
235
|
};
|
|
239
236
|
/** Client to process the call to the API using Fetch API */ export var ApiFetchClient = /*#__PURE__*/ function() {
|
|
240
237
|
"use strict";
|
|
@@ -271,7 +268,6 @@ var DEFAULT_OPTIONS = {
|
|
|
271
268
|
{
|
|
272
269
|
key: "getRequestOptions",
|
|
273
270
|
value: /** @inheritdoc */ function getRequestOptions(requestOptionsParameters) {
|
|
274
|
-
var _this = this;
|
|
275
271
|
return _async_to_generator(function() {
|
|
276
272
|
var opts, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, plugin, _requestOptionsParameters_api, err;
|
|
277
273
|
return _ts_generator(this, function(_state) {
|
|
@@ -281,7 +277,7 @@ var DEFAULT_OPTIONS = {
|
|
|
281
277
|
headers: new Headers(filterUndefinedValues(requestOptionsParameters.headers)),
|
|
282
278
|
queryParams: filterUndefinedValues(requestOptionsParameters.queryParams)
|
|
283
279
|
});
|
|
284
|
-
if (!
|
|
280
|
+
if (!this.options.requestPlugins) return [
|
|
285
281
|
3,
|
|
286
282
|
8
|
|
287
283
|
];
|
|
@@ -294,7 +290,7 @@ var DEFAULT_OPTIONS = {
|
|
|
294
290
|
7,
|
|
295
291
|
8
|
|
296
292
|
]);
|
|
297
|
-
_iterator =
|
|
293
|
+
_iterator = this.options.requestPlugins[Symbol.iterator]();
|
|
298
294
|
_state.label = 2;
|
|
299
295
|
case 2:
|
|
300
296
|
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
|
|
@@ -305,7 +301,7 @@ var DEFAULT_OPTIONS = {
|
|
|
305
301
|
return [
|
|
306
302
|
4,
|
|
307
303
|
plugin.load({
|
|
308
|
-
logger:
|
|
304
|
+
logger: this.options.logger,
|
|
309
305
|
apiName: (_requestOptionsParameters_api = requestOptionsParameters.api) === null || _requestOptionsParameters_api === void 0 ? void 0 : _requestOptionsParameters_api.apiName
|
|
310
306
|
}).transform(opts)
|
|
311
307
|
];
|
|
@@ -351,7 +347,7 @@ var DEFAULT_OPTIONS = {
|
|
|
351
347
|
];
|
|
352
348
|
}
|
|
353
349
|
});
|
|
354
|
-
})();
|
|
350
|
+
}).call(this);
|
|
355
351
|
}
|
|
356
352
|
},
|
|
357
353
|
{
|
|
@@ -394,12 +390,12 @@ var DEFAULT_OPTIONS = {
|
|
|
394
390
|
{
|
|
395
391
|
key: "processCall",
|
|
396
392
|
value: function processCall(url, options, apiType, apiName, revivers, operationId) {
|
|
397
|
-
var _this = this;
|
|
398
393
|
return _async_to_generator(function() {
|
|
399
|
-
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;
|
|
400
395
|
return _ts_generator(this, function(_state) {
|
|
401
396
|
switch(_state.label){
|
|
402
397
|
case 0:
|
|
398
|
+
_this = this;
|
|
403
399
|
origin = options.headers.get('Origin');
|
|
404
400
|
_state.label = 1;
|
|
405
401
|
case 1:
|
|
@@ -417,9 +413,9 @@ var DEFAULT_OPTIONS = {
|
|
|
417
413
|
return controller.abort();
|
|
418
414
|
});
|
|
419
415
|
loadedPlugins = [];
|
|
420
|
-
if (
|
|
416
|
+
if (this.options.fetchPlugins) {
|
|
421
417
|
;
|
|
422
|
-
(_loadedPlugins = loadedPlugins).push.apply(_loadedPlugins, _to_consumable_array(
|
|
418
|
+
(_loadedPlugins = loadedPlugins).push.apply(_loadedPlugins, _to_consumable_array(this.options.fetchPlugins.map(function(plugin) {
|
|
423
419
|
return plugin.load({
|
|
424
420
|
url: url,
|
|
425
421
|
options: options,
|
|
@@ -439,7 +435,7 @@ var DEFAULT_OPTIONS = {
|
|
|
439
435
|
case 2:
|
|
440
436
|
canStart = _state.sent();
|
|
441
437
|
isCanceledBy = canStart.indexOf(false);
|
|
442
|
-
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], {
|
|
443
439
|
apiName: apiName,
|
|
444
440
|
operationId: operationId,
|
|
445
441
|
url: url,
|
|
@@ -517,10 +513,10 @@ var DEFAULT_OPTIONS = {
|
|
|
517
513
|
}
|
|
518
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.
|
|
519
515
|
reviver = getResponseReviver(revivers, response, operationId, {
|
|
520
|
-
disableFallback:
|
|
516
|
+
disableFallback: this.options.disableFallback,
|
|
521
517
|
log: console.error
|
|
522
518
|
});
|
|
523
|
-
replyPlugins =
|
|
519
|
+
replyPlugins = this.options.replyPlugins ? this.options.replyPlugins.map(function(plugin) {
|
|
524
520
|
return plugin.load({
|
|
525
521
|
dictionaries: root && root.dictionaries,
|
|
526
522
|
response: response,
|
|
@@ -601,7 +597,7 @@ var DEFAULT_OPTIONS = {
|
|
|
601
597
|
];
|
|
602
598
|
}
|
|
603
599
|
});
|
|
604
|
-
})();
|
|
600
|
+
}).call(this);
|
|
605
601
|
}
|
|
606
602
|
}
|
|
607
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
|
});
|