@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
package/cjs/api-fetch-client.js
CHANGED
|
@@ -142,7 +142,7 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
142
142
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
143
143
|
}
|
|
144
144
|
function _ts_generator(thisArg, body) {
|
|
145
|
-
var f, y, t,
|
|
145
|
+
var f, y, t, _ = {
|
|
146
146
|
label: 0,
|
|
147
147
|
sent: function() {
|
|
148
148
|
if (t[0] & 1) throw t[1];
|
|
@@ -150,12 +150,8 @@ function _ts_generator(thisArg, body) {
|
|
|
150
150
|
},
|
|
151
151
|
trys: [],
|
|
152
152
|
ops: []
|
|
153
|
-
};
|
|
154
|
-
return g = {
|
|
155
|
-
next: verb(0),
|
|
156
|
-
"throw": verb(1),
|
|
157
|
-
"return": verb(2)
|
|
158
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
153
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
154
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
159
155
|
return this;
|
|
160
156
|
}), g;
|
|
161
157
|
function verb(n) {
|
|
@@ -168,7 +164,7 @@ function _ts_generator(thisArg, body) {
|
|
|
168
164
|
}
|
|
169
165
|
function step(op) {
|
|
170
166
|
if (f) throw new TypeError("Generator is already executing.");
|
|
171
|
-
while(_)try {
|
|
167
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
172
168
|
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;
|
|
173
169
|
if (y = 0, t) op = [
|
|
174
170
|
op[0] & 2,
|
|
@@ -244,7 +240,8 @@ var DEFAULT_OPTIONS = {
|
|
|
244
240
|
fetchPlugins: [],
|
|
245
241
|
requestPlugins: [],
|
|
246
242
|
enableTokenization: false,
|
|
247
|
-
disableFallback: false
|
|
243
|
+
disableFallback: false,
|
|
244
|
+
enableParameterSerialization: false
|
|
248
245
|
};
|
|
249
246
|
var ApiFetchClient = /*#__PURE__*/ function() {
|
|
250
247
|
"use strict";
|
|
@@ -281,7 +278,6 @@ var ApiFetchClient = /*#__PURE__*/ function() {
|
|
|
281
278
|
{
|
|
282
279
|
key: "getRequestOptions",
|
|
283
280
|
value: /** @inheritdoc */ function getRequestOptions(requestOptionsParameters) {
|
|
284
|
-
var _this = this;
|
|
285
281
|
return _async_to_generator(function() {
|
|
286
282
|
var opts, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, plugin, _requestOptionsParameters_api, err;
|
|
287
283
|
return _ts_generator(this, function(_state) {
|
|
@@ -291,7 +287,7 @@ var ApiFetchClient = /*#__PURE__*/ function() {
|
|
|
291
287
|
headers: new Headers((0, _core.filterUndefinedValues)(requestOptionsParameters.headers)),
|
|
292
288
|
queryParams: (0, _core.filterUndefinedValues)(requestOptionsParameters.queryParams)
|
|
293
289
|
});
|
|
294
|
-
if (!
|
|
290
|
+
if (!this.options.requestPlugins) return [
|
|
295
291
|
3,
|
|
296
292
|
8
|
|
297
293
|
];
|
|
@@ -304,7 +300,7 @@ var ApiFetchClient = /*#__PURE__*/ function() {
|
|
|
304
300
|
7,
|
|
305
301
|
8
|
|
306
302
|
]);
|
|
307
|
-
_iterator =
|
|
303
|
+
_iterator = this.options.requestPlugins[Symbol.iterator]();
|
|
308
304
|
_state.label = 2;
|
|
309
305
|
case 2:
|
|
310
306
|
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
|
|
@@ -315,7 +311,7 @@ var ApiFetchClient = /*#__PURE__*/ function() {
|
|
|
315
311
|
return [
|
|
316
312
|
4,
|
|
317
313
|
plugin.load({
|
|
318
|
-
logger:
|
|
314
|
+
logger: this.options.logger,
|
|
319
315
|
apiName: (_requestOptionsParameters_api = requestOptionsParameters.api) === null || _requestOptionsParameters_api === void 0 ? void 0 : _requestOptionsParameters_api.apiName
|
|
320
316
|
}).transform(opts)
|
|
321
317
|
];
|
|
@@ -361,7 +357,7 @@ var ApiFetchClient = /*#__PURE__*/ function() {
|
|
|
361
357
|
];
|
|
362
358
|
}
|
|
363
359
|
});
|
|
364
|
-
})();
|
|
360
|
+
}).call(this);
|
|
365
361
|
}
|
|
366
362
|
},
|
|
367
363
|
{
|
|
@@ -404,12 +400,12 @@ var ApiFetchClient = /*#__PURE__*/ function() {
|
|
|
404
400
|
{
|
|
405
401
|
key: "processCall",
|
|
406
402
|
value: function processCall(url, options, apiType, apiName, revivers, operationId) {
|
|
407
|
-
var _this = this;
|
|
408
403
|
return _async_to_generator(function() {
|
|
409
|
-
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;
|
|
404
|
+
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;
|
|
410
405
|
return _ts_generator(this, function(_state) {
|
|
411
406
|
switch(_state.label){
|
|
412
407
|
case 0:
|
|
408
|
+
_this = this;
|
|
413
409
|
origin = options.headers.get('Origin');
|
|
414
410
|
_state.label = 1;
|
|
415
411
|
case 1:
|
|
@@ -427,9 +423,9 @@ var ApiFetchClient = /*#__PURE__*/ function() {
|
|
|
427
423
|
return controller.abort();
|
|
428
424
|
});
|
|
429
425
|
loadedPlugins = [];
|
|
430
|
-
if (
|
|
426
|
+
if (this.options.fetchPlugins) {
|
|
431
427
|
;
|
|
432
|
-
(_loadedPlugins = loadedPlugins).push.apply(_loadedPlugins, _to_consumable_array(
|
|
428
|
+
(_loadedPlugins = loadedPlugins).push.apply(_loadedPlugins, _to_consumable_array(this.options.fetchPlugins.map(function(plugin) {
|
|
433
429
|
return plugin.load({
|
|
434
430
|
url: url,
|
|
435
431
|
options: options,
|
|
@@ -449,7 +445,7 @@ var ApiFetchClient = /*#__PURE__*/ function() {
|
|
|
449
445
|
case 2:
|
|
450
446
|
canStart = _state.sent();
|
|
451
447
|
isCanceledBy = canStart.indexOf(false);
|
|
452
|
-
asyncResponse = isCanceledBy === -1 ? fetch(url, options) : Promise.reject(new _core.CanceledCallError("Is canceled by the plugin ".concat(isCanceledBy), isCanceledBy,
|
|
448
|
+
asyncResponse = isCanceledBy === -1 ? fetch(url, options) : Promise.reject(new _core.CanceledCallError("Is canceled by the plugin ".concat(isCanceledBy), isCanceledBy, this.options.fetchPlugins[isCanceledBy], {
|
|
453
449
|
apiName: apiName,
|
|
454
450
|
operationId: operationId,
|
|
455
451
|
url: url,
|
|
@@ -527,10 +523,10 @@ var ApiFetchClient = /*#__PURE__*/ function() {
|
|
|
527
523
|
}
|
|
528
524
|
// 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.
|
|
529
525
|
reviver = (0, _core.getResponseReviver)(revivers, response, operationId, {
|
|
530
|
-
disableFallback:
|
|
526
|
+
disableFallback: this.options.disableFallback,
|
|
531
527
|
log: console.error
|
|
532
528
|
});
|
|
533
|
-
replyPlugins =
|
|
529
|
+
replyPlugins = this.options.replyPlugins ? this.options.replyPlugins.map(function(plugin) {
|
|
534
530
|
return plugin.load({
|
|
535
531
|
dictionaries: root && root.dictionaries,
|
|
536
532
|
response: response,
|
|
@@ -611,7 +607,7 @@ var ApiFetchClient = /*#__PURE__*/ function() {
|
|
|
611
607
|
];
|
|
612
608
|
}
|
|
613
609
|
});
|
|
614
|
-
})();
|
|
610
|
+
}).call(this);
|
|
615
611
|
}
|
|
616
612
|
}
|
|
617
613
|
]);
|
|
@@ -33,7 +33,7 @@ function _async_to_generator(fn) {
|
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
35
|
function _ts_generator(thisArg, body) {
|
|
36
|
-
var f, y, t,
|
|
36
|
+
var f, y, t, _ = {
|
|
37
37
|
label: 0,
|
|
38
38
|
sent: function() {
|
|
39
39
|
if (t[0] & 1) throw t[1];
|
|
@@ -41,12 +41,8 @@ function _ts_generator(thisArg, body) {
|
|
|
41
41
|
},
|
|
42
42
|
trys: [],
|
|
43
43
|
ops: []
|
|
44
|
-
};
|
|
45
|
-
return g = {
|
|
46
|
-
next: verb(0),
|
|
47
|
-
"throw": verb(1),
|
|
48
|
-
"return": verb(2)
|
|
49
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
44
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
45
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
50
46
|
return this;
|
|
51
47
|
}), g;
|
|
52
48
|
function verb(n) {
|
|
@@ -59,7 +55,7 @@ function _ts_generator(thisArg, body) {
|
|
|
59
55
|
}
|
|
60
56
|
function step(op) {
|
|
61
57
|
if (f) throw new TypeError("Generator is already executing.");
|
|
62
|
-
while(_)try {
|
|
58
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
63
59
|
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;
|
|
64
60
|
if (y = 0, t) op = [
|
|
65
61
|
op[0] & 2,
|
|
@@ -128,77 +124,83 @@ function _ts_generator(thisArg, body) {
|
|
|
128
124
|
}
|
|
129
125
|
}
|
|
130
126
|
describe('Abort Plugin', function() {
|
|
131
|
-
it('should trigger the callback',
|
|
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
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
runner.
|
|
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
|
-
|
|
127
|
+
it('should trigger the callback', function() {
|
|
128
|
+
return _async_to_generator(function() {
|
|
129
|
+
var fn, plugin, runner;
|
|
130
|
+
return _ts_generator(this, function(_state) {
|
|
131
|
+
switch(_state.label){
|
|
132
|
+
case 0:
|
|
133
|
+
fn = jest.fn();
|
|
134
|
+
plugin = new _abortfetch.AbortFetch(fn);
|
|
135
|
+
runner = plugin.load({});
|
|
136
|
+
return [
|
|
137
|
+
4,
|
|
138
|
+
runner.transform(Promise.resolve())
|
|
139
|
+
];
|
|
140
|
+
case 1:
|
|
141
|
+
_state.sent();
|
|
142
|
+
expect(fn).toHaveBeenCalled();
|
|
143
|
+
return [
|
|
144
|
+
2
|
|
145
|
+
];
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
})();
|
|
149
|
+
});
|
|
150
|
+
it('should trigger abort signal if true', function() {
|
|
151
|
+
return _async_to_generator(function() {
|
|
152
|
+
var defaultContext, fn, plugin, runner;
|
|
153
|
+
return _ts_generator(this, function(_state) {
|
|
154
|
+
switch(_state.label){
|
|
155
|
+
case 0:
|
|
156
|
+
defaultContext = {
|
|
157
|
+
controller: {
|
|
158
|
+
abort: jest.fn()
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
fn = jest.fn().mockResolvedValue(true);
|
|
162
|
+
plugin = new _abortfetch.AbortFetch(fn);
|
|
163
|
+
runner = plugin.load(defaultContext);
|
|
164
|
+
return [
|
|
165
|
+
4,
|
|
166
|
+
runner.transform(Promise.resolve())
|
|
167
|
+
];
|
|
168
|
+
case 1:
|
|
169
|
+
_state.sent();
|
|
170
|
+
expect(defaultContext.controller.abort).toHaveBeenCalled();
|
|
171
|
+
return [
|
|
172
|
+
2
|
|
173
|
+
];
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
})();
|
|
177
|
+
});
|
|
178
|
+
it('should not trigger abort signal if false', function() {
|
|
179
|
+
return _async_to_generator(function() {
|
|
180
|
+
var defaultContext, fn, plugin, runner;
|
|
181
|
+
return _ts_generator(this, function(_state) {
|
|
182
|
+
switch(_state.label){
|
|
183
|
+
case 0:
|
|
184
|
+
defaultContext = {
|
|
185
|
+
controller: {
|
|
186
|
+
abort: jest.fn()
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
fn = jest.fn().mockResolvedValue(false);
|
|
190
|
+
plugin = new _abortfetch.AbortFetch(fn);
|
|
191
|
+
runner = plugin.load(defaultContext);
|
|
192
|
+
return [
|
|
193
|
+
4,
|
|
194
|
+
runner.transform(Promise.resolve())
|
|
195
|
+
];
|
|
196
|
+
case 1:
|
|
197
|
+
_state.sent();
|
|
198
|
+
expect(defaultContext.controller.abort).not.toHaveBeenCalled();
|
|
199
|
+
return [
|
|
200
|
+
2
|
|
201
|
+
];
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
})();
|
|
205
|
+
});
|
|
204
206
|
});
|
|
@@ -70,7 +70,7 @@ function _define_property(obj, key, value) {
|
|
|
70
70
|
return obj;
|
|
71
71
|
}
|
|
72
72
|
function _ts_generator(thisArg, body) {
|
|
73
|
-
var f, y, t,
|
|
73
|
+
var f, y, t, _ = {
|
|
74
74
|
label: 0,
|
|
75
75
|
sent: function() {
|
|
76
76
|
if (t[0] & 1) throw t[1];
|
|
@@ -78,12 +78,8 @@ function _ts_generator(thisArg, body) {
|
|
|
78
78
|
},
|
|
79
79
|
trys: [],
|
|
80
80
|
ops: []
|
|
81
|
-
};
|
|
82
|
-
return g = {
|
|
83
|
-
next: verb(0),
|
|
84
|
-
"throw": verb(1),
|
|
85
|
-
"return": verb(2)
|
|
86
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
81
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
82
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
87
83
|
return this;
|
|
88
84
|
}), g;
|
|
89
85
|
function verb(n) {
|
|
@@ -96,7 +92,7 @@ function _ts_generator(thisArg, body) {
|
|
|
96
92
|
}
|
|
97
93
|
function step(op) {
|
|
98
94
|
if (f) throw new TypeError("Generator is already executing.");
|
|
99
|
-
while(_)try {
|
|
95
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
100
96
|
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;
|
|
101
97
|
if (y = 0, t) op = [
|
|
102
98
|
op[0] & 2,
|
|
@@ -199,20 +195,19 @@ var ConcurrentFetch = /*#__PURE__*/ function() {
|
|
|
199
195
|
value: /** @inheritDoc */ function load(_context) {
|
|
200
196
|
var _this = this;
|
|
201
197
|
this.poolSize++;
|
|
202
|
-
var _this1 = this;
|
|
203
198
|
return {
|
|
204
199
|
canStart: function() {
|
|
205
200
|
return new Promise(function(resolve) {
|
|
206
201
|
return _this.canStart() ? resolve(true) : _this.waitingResolvers.push(resolve);
|
|
207
202
|
});
|
|
208
203
|
},
|
|
209
|
-
transform:
|
|
210
|
-
|
|
204
|
+
transform: function(fetchCall) {
|
|
205
|
+
return _async_to_generator(function() {
|
|
211
206
|
var fetchResponse;
|
|
212
207
|
return _ts_generator(this, function(_state) {
|
|
213
208
|
switch(_state.label){
|
|
214
209
|
case 0:
|
|
215
|
-
|
|
210
|
+
this.pool.push(fetchCall);
|
|
216
211
|
_state.label = 1;
|
|
217
212
|
case 1:
|
|
218
213
|
_state.trys.push([
|
|
@@ -232,11 +227,11 @@ var ConcurrentFetch = /*#__PURE__*/ function() {
|
|
|
232
227
|
fetchResponse
|
|
233
228
|
];
|
|
234
229
|
case 3:
|
|
235
|
-
|
|
230
|
+
this.pool = this.pool.filter(function(call) {
|
|
236
231
|
return call !== fetchCall;
|
|
237
232
|
});
|
|
238
|
-
|
|
239
|
-
|
|
233
|
+
this.poolSize--;
|
|
234
|
+
this.unstackResolve();
|
|
240
235
|
return [
|
|
241
236
|
7
|
|
242
237
|
];
|
|
@@ -246,11 +241,8 @@ var ConcurrentFetch = /*#__PURE__*/ function() {
|
|
|
246
241
|
];
|
|
247
242
|
}
|
|
248
243
|
});
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
return _ref.apply(this, arguments);
|
|
252
|
-
};
|
|
253
|
-
}()
|
|
244
|
+
}).call(_this);
|
|
245
|
+
}
|
|
254
246
|
};
|
|
255
247
|
}
|
|
256
248
|
}
|
|
@@ -33,7 +33,7 @@ function _async_to_generator(fn) {
|
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
35
|
function _ts_generator(thisArg, body) {
|
|
36
|
-
var f, y, t,
|
|
36
|
+
var f, y, t, _ = {
|
|
37
37
|
label: 0,
|
|
38
38
|
sent: function() {
|
|
39
39
|
if (t[0] & 1) throw t[1];
|
|
@@ -41,12 +41,8 @@ function _ts_generator(thisArg, body) {
|
|
|
41
41
|
},
|
|
42
42
|
trys: [],
|
|
43
43
|
ops: []
|
|
44
|
-
};
|
|
45
|
-
return g = {
|
|
46
|
-
next: verb(0),
|
|
47
|
-
"throw": verb(1),
|
|
48
|
-
"return": verb(2)
|
|
49
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
44
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
45
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
50
46
|
return this;
|
|
51
47
|
}), g;
|
|
52
48
|
function verb(n) {
|
|
@@ -59,7 +55,7 @@ function _ts_generator(thisArg, body) {
|
|
|
59
55
|
}
|
|
60
56
|
function step(op) {
|
|
61
57
|
if (f) throw new TypeError("Generator is already executing.");
|
|
62
|
-
while(_)try {
|
|
58
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
63
59
|
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;
|
|
64
60
|
if (y = 0, t) op = [
|
|
65
61
|
op[0] & 2,
|
|
@@ -128,27 +124,29 @@ function _ts_generator(thisArg, body) {
|
|
|
128
124
|
}
|
|
129
125
|
}
|
|
130
126
|
describe('Concurrent Fetch Plugin', function() {
|
|
131
|
-
it('should start if the limit is not reach',
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
127
|
+
it('should start if the limit is not reach', function() {
|
|
128
|
+
return _async_to_generator(function() {
|
|
129
|
+
var plugin, runner, canStart;
|
|
130
|
+
return _ts_generator(this, function(_state) {
|
|
131
|
+
switch(_state.label){
|
|
132
|
+
case 0:
|
|
133
|
+
plugin = new _concurrentfetch.ConcurrentFetch(3);
|
|
134
|
+
plugin.load({});
|
|
135
|
+
runner = plugin.load({});
|
|
136
|
+
return [
|
|
137
|
+
4,
|
|
138
|
+
runner.canStart()
|
|
139
|
+
];
|
|
140
|
+
case 1:
|
|
141
|
+
canStart = _state.sent();
|
|
142
|
+
expect(canStart).toBe(true);
|
|
143
|
+
return [
|
|
144
|
+
2
|
|
145
|
+
];
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
})();
|
|
149
|
+
});
|
|
152
150
|
it('should retrieve the fetch call in the pool', function() {
|
|
153
151
|
var plugin = new _concurrentfetch.ConcurrentFetch(3);
|
|
154
152
|
var call = new Promise(function(resolve) {
|
|
@@ -166,74 +164,76 @@ describe('Concurrent Fetch Plugin', function() {
|
|
|
166
164
|
void plugin.load({}).transform(test);
|
|
167
165
|
expect(plugin.pool[2]).toBe(test);
|
|
168
166
|
});
|
|
169
|
-
it('should start only when the pool is available',
|
|
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
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
167
|
+
it('should start only when the pool is available', function() {
|
|
168
|
+
return _async_to_generator(function() {
|
|
169
|
+
var plugin, resolves, call0, call1, result, runner1, canStart1, runner2, pCanStart2;
|
|
170
|
+
return _ts_generator(this, function(_state) {
|
|
171
|
+
switch(_state.label){
|
|
172
|
+
case 0:
|
|
173
|
+
plugin = new _concurrentfetch.ConcurrentFetch(2);
|
|
174
|
+
resolves = [
|
|
175
|
+
null,
|
|
176
|
+
null
|
|
177
|
+
];
|
|
178
|
+
call0 = new Promise(function(resolve) {
|
|
179
|
+
return resolves[0] = resolve;
|
|
180
|
+
});
|
|
181
|
+
call1 = new Promise(function(resolve) {
|
|
182
|
+
return resolves[1] = resolve;
|
|
183
|
+
});
|
|
184
|
+
result = {
|
|
185
|
+
res: false
|
|
186
|
+
};
|
|
187
|
+
void plugin.load({}).transform(call0);
|
|
188
|
+
runner1 = plugin.load({});
|
|
189
|
+
canStart1 = runner1.canStart();
|
|
190
|
+
return [
|
|
191
|
+
4,
|
|
192
|
+
jest.runAllTimersAsync()
|
|
193
|
+
];
|
|
194
|
+
case 1:
|
|
195
|
+
_state.sent();
|
|
196
|
+
return [
|
|
197
|
+
4,
|
|
198
|
+
canStart1
|
|
199
|
+
];
|
|
200
|
+
case 2:
|
|
201
|
+
expect.apply(void 0, [
|
|
202
|
+
_state.sent()
|
|
203
|
+
]).toBe(true);
|
|
204
|
+
void runner1.transform(call1);
|
|
205
|
+
runner2 = plugin.load({});
|
|
206
|
+
pCanStart2 = runner2.canStart();
|
|
207
|
+
return [
|
|
208
|
+
4,
|
|
209
|
+
jest.runAllTimersAsync()
|
|
210
|
+
];
|
|
211
|
+
case 3:
|
|
212
|
+
_state.sent();
|
|
213
|
+
expect(plugin.waitingResolvers.length).toBe(1);
|
|
214
|
+
result.res = true;
|
|
215
|
+
resolves[0]();
|
|
216
|
+
return [
|
|
217
|
+
4,
|
|
218
|
+
pCanStart2
|
|
219
|
+
];
|
|
220
|
+
case 4:
|
|
221
|
+
expect.apply(void 0, [
|
|
222
|
+
_state.sent()
|
|
223
|
+
]).toBe(true);
|
|
224
|
+
resolves[1]();
|
|
225
|
+
return [
|
|
226
|
+
4,
|
|
227
|
+
jest.advanceTimersByTimeAsync(500)
|
|
228
|
+
];
|
|
229
|
+
case 5:
|
|
230
|
+
_state.sent();
|
|
231
|
+
expect(plugin.waitingResolvers.length).toBe(0);
|
|
232
|
+
return [
|
|
233
|
+
2
|
|
234
|
+
];
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
})();
|
|
238
|
+
});
|
|
239
239
|
});
|