@ama-sdk/client-fetch 12.3.0-prerelease.70 → 12.3.0-prerelease.71
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 +12 -13
- package/cjs/plugins/abort/abort.spec.js +79 -73
- package/cjs/plugins/concurrent/concurrent.fetch.js +8 -12
- package/cjs/plugins/concurrent/concurrent.spec.js +95 -91
- package/cjs/plugins/keepalive/keepalive.request.js +3 -4
- package/cjs/plugins/keepalive/keepalive.spec.js +28 -26
- package/cjs/plugins/mock-intercept/mock-intercept.fetch.js +11 -14
- package/cjs/plugins/mock-intercept/mock-intercept.spec.js +243 -231
- package/cjs/plugins/perf-metric/perf-metric.fetch.js +7 -10
- package/cjs/plugins/retry/retry.fetch.js +14 -19
- package/cjs/plugins/retry/retry.spec.js +229 -217
- package/cjs/plugins/timeout/timeout.fetch.js +9 -11
- package/cjs/plugins/timeout/timeout.spec.js +207 -197
- package/cjs/plugins/wait-for/wait-for.fetch.js +15 -21
- package/cjs/plugins/wait-for/wait-for.spec.js +207 -195
- package/esm2015/api-fetch-client.js +12 -13
- package/esm2015/plugins/abort/abort.spec.js +79 -73
- package/esm2015/plugins/concurrent/concurrent.fetch.js +8 -12
- package/esm2015/plugins/concurrent/concurrent.spec.js +95 -91
- package/esm2015/plugins/keepalive/keepalive.request.js +3 -4
- package/esm2015/plugins/keepalive/keepalive.spec.js +28 -26
- package/esm2015/plugins/mock-intercept/mock-intercept.fetch.js +11 -14
- package/esm2015/plugins/mock-intercept/mock-intercept.spec.js +243 -231
- package/esm2015/plugins/perf-metric/perf-metric.fetch.js +7 -10
- package/esm2015/plugins/retry/retry.fetch.js +14 -19
- package/esm2015/plugins/retry/retry.spec.js +229 -217
- package/esm2015/plugins/timeout/timeout.fetch.js +9 -11
- package/esm2015/plugins/timeout/timeout.spec.js +207 -197
- package/esm2015/plugins/wait-for/wait-for.fetch.js +15 -21
- package/esm2015/plugins/wait-for/wait-for.spec.js +207 -195
- package/package.json +8 -8
|
@@ -177,203 +177,215 @@ function _ts_generator(thisArg, body) {
|
|
|
177
177
|
}
|
|
178
178
|
describe('Wait For Fetch Plugin', function() {
|
|
179
179
|
var defaultContext = {};
|
|
180
|
-
it('should not start if timeout',
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
return
|
|
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
|
-
runner.
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
180
|
+
it('should not start if timeout', function() {
|
|
181
|
+
return _async_to_generator(function() {
|
|
182
|
+
var plugin, runner, canStart;
|
|
183
|
+
return _ts_generator(this, function(_state) {
|
|
184
|
+
switch(_state.label){
|
|
185
|
+
case 0:
|
|
186
|
+
plugin = new _waitforfetch.WaitForFetch(function() {
|
|
187
|
+
return {
|
|
188
|
+
result: new Promise(function(resolve) {
|
|
189
|
+
return setTimeout(function() {
|
|
190
|
+
return resolve(true);
|
|
191
|
+
}, 2000);
|
|
192
|
+
})
|
|
193
|
+
};
|
|
194
|
+
}, 100);
|
|
195
|
+
runner = plugin.load(defaultContext);
|
|
196
|
+
canStart = runner.canStart();
|
|
197
|
+
return [
|
|
198
|
+
4,
|
|
199
|
+
jest.runAllTimersAsync()
|
|
200
|
+
];
|
|
201
|
+
case 1:
|
|
202
|
+
_state.sent();
|
|
203
|
+
return [
|
|
204
|
+
4,
|
|
205
|
+
canStart
|
|
206
|
+
];
|
|
207
|
+
case 2:
|
|
208
|
+
expect.apply(void 0, [
|
|
209
|
+
_state.sent()
|
|
210
|
+
]).toBe(false);
|
|
211
|
+
return [
|
|
212
|
+
2
|
|
213
|
+
];
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
})();
|
|
217
|
+
});
|
|
218
|
+
it('should start if promise condition passed', function() {
|
|
219
|
+
return _async_to_generator(function() {
|
|
220
|
+
var plugin, runner, canStart;
|
|
221
|
+
return _ts_generator(this, function(_state) {
|
|
222
|
+
switch(_state.label){
|
|
223
|
+
case 0:
|
|
224
|
+
plugin = new _waitforfetch.WaitForFetch(function() {
|
|
225
|
+
return {
|
|
226
|
+
result: Promise.resolve(true)
|
|
227
|
+
};
|
|
228
|
+
}, 100);
|
|
229
|
+
runner = plugin.load(defaultContext);
|
|
230
|
+
return [
|
|
231
|
+
4,
|
|
232
|
+
runner.canStart()
|
|
233
|
+
];
|
|
234
|
+
case 1:
|
|
235
|
+
canStart = _state.sent();
|
|
236
|
+
expect(canStart).toBe(true);
|
|
237
|
+
return [
|
|
238
|
+
2
|
|
239
|
+
];
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
})();
|
|
243
|
+
});
|
|
244
|
+
it('should start if condition passed', function() {
|
|
245
|
+
return _async_to_generator(function() {
|
|
246
|
+
var plugin, runner, canStart;
|
|
247
|
+
return _ts_generator(this, function(_state) {
|
|
248
|
+
switch(_state.label){
|
|
249
|
+
case 0:
|
|
250
|
+
plugin = new _waitforfetch.WaitForFetch(function() {
|
|
251
|
+
return {
|
|
252
|
+
result: true
|
|
253
|
+
};
|
|
254
|
+
}, 100);
|
|
255
|
+
runner = plugin.load(defaultContext);
|
|
256
|
+
return [
|
|
257
|
+
4,
|
|
258
|
+
runner.canStart()
|
|
259
|
+
];
|
|
260
|
+
case 1:
|
|
261
|
+
canStart = _state.sent();
|
|
262
|
+
expect(canStart).toBe(true);
|
|
263
|
+
return [
|
|
264
|
+
2
|
|
265
|
+
];
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
})();
|
|
269
|
+
});
|
|
270
|
+
it('should call the callback function on success', function() {
|
|
271
|
+
return _async_to_generator(function() {
|
|
272
|
+
var callback, plugin, runner, response, fetchCall;
|
|
273
|
+
return _ts_generator(this, function(_state) {
|
|
274
|
+
switch(_state.label){
|
|
275
|
+
case 0:
|
|
276
|
+
callback = jest.fn();
|
|
277
|
+
plugin = new _waitforfetch.WaitForFetch(function() {
|
|
278
|
+
return {
|
|
279
|
+
result: true
|
|
280
|
+
};
|
|
281
|
+
}, 100, callback);
|
|
282
|
+
runner = plugin.load(defaultContext);
|
|
283
|
+
response = {
|
|
284
|
+
test: true
|
|
248
285
|
};
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
}
|
|
262
|
-
});
|
|
263
|
-
})
|
|
264
|
-
it('should call the callback function
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
286
|
+
fetchCall = Promise.resolve(response);
|
|
287
|
+
return [
|
|
288
|
+
4,
|
|
289
|
+
runner.transform(fetchCall)
|
|
290
|
+
];
|
|
291
|
+
case 1:
|
|
292
|
+
_state.sent();
|
|
293
|
+
expect(callback).toHaveBeenCalledWith(expect.objectContaining(defaultContext), fetchCall, response);
|
|
294
|
+
return [
|
|
295
|
+
2
|
|
296
|
+
];
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
})();
|
|
300
|
+
});
|
|
301
|
+
it('should call the callback function with the correct data', function() {
|
|
302
|
+
return _async_to_generator(function() {
|
|
303
|
+
var callback, plugin, runner, response, fetchCall;
|
|
304
|
+
return _ts_generator(this, function(_state) {
|
|
305
|
+
switch(_state.label){
|
|
306
|
+
case 0:
|
|
307
|
+
callback = jest.fn();
|
|
308
|
+
plugin = new _waitforfetch.WaitForFetch(function() {
|
|
309
|
+
return {
|
|
310
|
+
result: true,
|
|
311
|
+
data: 'test'
|
|
312
|
+
};
|
|
313
|
+
}, 100, callback);
|
|
314
|
+
runner = plugin.load(defaultContext);
|
|
315
|
+
response = {
|
|
316
|
+
test: true
|
|
273
317
|
};
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
2
|
|
289
|
-
];
|
|
290
|
-
}
|
|
291
|
-
});
|
|
292
|
-
}));
|
|
293
|
-
it('should call the callback function with the correct data', /*#__PURE__*/ _async_to_generator(function() {
|
|
294
|
-
var callback, plugin, runner, response, fetchCall;
|
|
295
|
-
return _ts_generator(this, function(_state) {
|
|
296
|
-
switch(_state.label){
|
|
297
|
-
case 0:
|
|
298
|
-
callback = jest.fn();
|
|
299
|
-
plugin = new _waitforfetch.WaitForFetch(function() {
|
|
300
|
-
return {
|
|
301
|
-
result: true,
|
|
318
|
+
fetchCall = Promise.resolve(response);
|
|
319
|
+
return [
|
|
320
|
+
4,
|
|
321
|
+
runner.canStart()
|
|
322
|
+
];
|
|
323
|
+
case 1:
|
|
324
|
+
_state.sent();
|
|
325
|
+
return [
|
|
326
|
+
4,
|
|
327
|
+
runner.transform(fetchCall)
|
|
328
|
+
];
|
|
329
|
+
case 2:
|
|
330
|
+
_state.sent();
|
|
331
|
+
expect(callback).toHaveBeenCalledWith(expect.objectContaining(_object_spread_props(_object_spread({}, defaultContext), {
|
|
302
332
|
data: 'test'
|
|
333
|
+
})), fetchCall, response);
|
|
334
|
+
return [
|
|
335
|
+
2
|
|
336
|
+
];
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
})();
|
|
340
|
+
});
|
|
341
|
+
it('should call the callback function on failure', function() {
|
|
342
|
+
return _async_to_generator(function() {
|
|
343
|
+
var callback, plugin, runner, response, fetchCall, e;
|
|
344
|
+
return _ts_generator(this, function(_state) {
|
|
345
|
+
switch(_state.label){
|
|
346
|
+
case 0:
|
|
347
|
+
callback = jest.fn();
|
|
348
|
+
plugin = new _waitforfetch.WaitForFetch(function() {
|
|
349
|
+
return {
|
|
350
|
+
result: true
|
|
351
|
+
};
|
|
352
|
+
}, 100, callback);
|
|
353
|
+
runner = plugin.load(defaultContext);
|
|
354
|
+
response = {
|
|
355
|
+
test: true
|
|
303
356
|
};
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
return {
|
|
339
|
-
result: true
|
|
340
|
-
};
|
|
341
|
-
}, 100, callback);
|
|
342
|
-
runner = plugin.load(defaultContext);
|
|
343
|
-
response = {
|
|
344
|
-
test: true
|
|
345
|
-
};
|
|
346
|
-
fetchCall = Promise.reject(new Error(JSON.stringify(response)));
|
|
347
|
-
_state.label = 1;
|
|
348
|
-
case 1:
|
|
349
|
-
_state.trys.push([
|
|
350
|
-
1,
|
|
351
|
-
3,
|
|
352
|
-
,
|
|
353
|
-
4
|
|
354
|
-
]);
|
|
355
|
-
return [
|
|
356
|
-
4,
|
|
357
|
-
runner.transform(fetchCall)
|
|
358
|
-
];
|
|
359
|
-
case 2:
|
|
360
|
-
_state.sent();
|
|
361
|
-
return [
|
|
362
|
-
3,
|
|
363
|
-
4
|
|
364
|
-
];
|
|
365
|
-
case 3:
|
|
366
|
-
e = _state.sent();
|
|
367
|
-
return [
|
|
368
|
-
3,
|
|
369
|
-
4
|
|
370
|
-
];
|
|
371
|
-
case 4:
|
|
372
|
-
expect(callback).toHaveBeenCalledWith(expect.objectContaining(defaultContext), fetchCall, undefined);
|
|
373
|
-
return [
|
|
374
|
-
2
|
|
375
|
-
];
|
|
376
|
-
}
|
|
377
|
-
});
|
|
378
|
-
}));
|
|
357
|
+
fetchCall = Promise.reject(new Error(JSON.stringify(response)));
|
|
358
|
+
_state.label = 1;
|
|
359
|
+
case 1:
|
|
360
|
+
_state.trys.push([
|
|
361
|
+
1,
|
|
362
|
+
3,
|
|
363
|
+
,
|
|
364
|
+
4
|
|
365
|
+
]);
|
|
366
|
+
return [
|
|
367
|
+
4,
|
|
368
|
+
runner.transform(fetchCall)
|
|
369
|
+
];
|
|
370
|
+
case 2:
|
|
371
|
+
_state.sent();
|
|
372
|
+
return [
|
|
373
|
+
3,
|
|
374
|
+
4
|
|
375
|
+
];
|
|
376
|
+
case 3:
|
|
377
|
+
e = _state.sent();
|
|
378
|
+
return [
|
|
379
|
+
3,
|
|
380
|
+
4
|
|
381
|
+
];
|
|
382
|
+
case 4:
|
|
383
|
+
expect(callback).toHaveBeenCalledWith(expect.objectContaining(defaultContext), fetchCall, undefined);
|
|
384
|
+
return [
|
|
385
|
+
2
|
|
386
|
+
];
|
|
387
|
+
}
|
|
388
|
+
});
|
|
389
|
+
})();
|
|
390
|
+
});
|
|
379
391
|
});
|
|
@@ -268,7 +268,6 @@ var DEFAULT_OPTIONS = {
|
|
|
268
268
|
{
|
|
269
269
|
key: "getRequestOptions",
|
|
270
270
|
value: /** @inheritdoc */ function getRequestOptions(requestOptionsParameters) {
|
|
271
|
-
var _this = this;
|
|
272
271
|
return _async_to_generator(function() {
|
|
273
272
|
var opts, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, plugin, _requestOptionsParameters_api, err;
|
|
274
273
|
return _ts_generator(this, function(_state) {
|
|
@@ -278,7 +277,7 @@ var DEFAULT_OPTIONS = {
|
|
|
278
277
|
headers: new Headers(filterUndefinedValues(requestOptionsParameters.headers)),
|
|
279
278
|
queryParams: filterUndefinedValues(requestOptionsParameters.queryParams)
|
|
280
279
|
});
|
|
281
|
-
if (!
|
|
280
|
+
if (!this.options.requestPlugins) return [
|
|
282
281
|
3,
|
|
283
282
|
8
|
|
284
283
|
];
|
|
@@ -291,7 +290,7 @@ var DEFAULT_OPTIONS = {
|
|
|
291
290
|
7,
|
|
292
291
|
8
|
|
293
292
|
]);
|
|
294
|
-
_iterator =
|
|
293
|
+
_iterator = this.options.requestPlugins[Symbol.iterator]();
|
|
295
294
|
_state.label = 2;
|
|
296
295
|
case 2:
|
|
297
296
|
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
|
|
@@ -302,7 +301,7 @@ var DEFAULT_OPTIONS = {
|
|
|
302
301
|
return [
|
|
303
302
|
4,
|
|
304
303
|
plugin.load({
|
|
305
|
-
logger:
|
|
304
|
+
logger: this.options.logger,
|
|
306
305
|
apiName: (_requestOptionsParameters_api = requestOptionsParameters.api) === null || _requestOptionsParameters_api === void 0 ? void 0 : _requestOptionsParameters_api.apiName
|
|
307
306
|
}).transform(opts)
|
|
308
307
|
];
|
|
@@ -348,7 +347,7 @@ var DEFAULT_OPTIONS = {
|
|
|
348
347
|
];
|
|
349
348
|
}
|
|
350
349
|
});
|
|
351
|
-
})();
|
|
350
|
+
}).call(this);
|
|
352
351
|
}
|
|
353
352
|
},
|
|
354
353
|
{
|
|
@@ -391,12 +390,12 @@ var DEFAULT_OPTIONS = {
|
|
|
391
390
|
{
|
|
392
391
|
key: "processCall",
|
|
393
392
|
value: function processCall(url, options, apiType, apiName, revivers, operationId) {
|
|
394
|
-
var _this = this;
|
|
395
393
|
return _async_to_generator(function() {
|
|
396
|
-
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;
|
|
397
395
|
return _ts_generator(this, function(_state) {
|
|
398
396
|
switch(_state.label){
|
|
399
397
|
case 0:
|
|
398
|
+
_this = this;
|
|
400
399
|
origin = options.headers.get('Origin');
|
|
401
400
|
_state.label = 1;
|
|
402
401
|
case 1:
|
|
@@ -414,9 +413,9 @@ var DEFAULT_OPTIONS = {
|
|
|
414
413
|
return controller.abort();
|
|
415
414
|
});
|
|
416
415
|
loadedPlugins = [];
|
|
417
|
-
if (
|
|
416
|
+
if (this.options.fetchPlugins) {
|
|
418
417
|
;
|
|
419
|
-
(_loadedPlugins = loadedPlugins).push.apply(_loadedPlugins, _to_consumable_array(
|
|
418
|
+
(_loadedPlugins = loadedPlugins).push.apply(_loadedPlugins, _to_consumable_array(this.options.fetchPlugins.map(function(plugin) {
|
|
420
419
|
return plugin.load({
|
|
421
420
|
url: url,
|
|
422
421
|
options: options,
|
|
@@ -436,7 +435,7 @@ var DEFAULT_OPTIONS = {
|
|
|
436
435
|
case 2:
|
|
437
436
|
canStart = _state.sent();
|
|
438
437
|
isCanceledBy = canStart.indexOf(false);
|
|
439
|
-
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], {
|
|
440
439
|
apiName: apiName,
|
|
441
440
|
operationId: operationId,
|
|
442
441
|
url: url,
|
|
@@ -514,10 +513,10 @@ var DEFAULT_OPTIONS = {
|
|
|
514
513
|
}
|
|
515
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.
|
|
516
515
|
reviver = getResponseReviver(revivers, response, operationId, {
|
|
517
|
-
disableFallback:
|
|
516
|
+
disableFallback: this.options.disableFallback,
|
|
518
517
|
log: console.error
|
|
519
518
|
});
|
|
520
|
-
replyPlugins =
|
|
519
|
+
replyPlugins = this.options.replyPlugins ? this.options.replyPlugins.map(function(plugin) {
|
|
521
520
|
return plugin.load({
|
|
522
521
|
dictionaries: root && root.dictionaries,
|
|
523
522
|
response: response,
|
|
@@ -598,7 +597,7 @@ var DEFAULT_OPTIONS = {
|
|
|
598
597
|
];
|
|
599
598
|
}
|
|
600
599
|
});
|
|
601
|
-
})();
|
|
600
|
+
}).call(this);
|
|
602
601
|
}
|
|
603
602
|
}
|
|
604
603
|
]);
|