@ama-sdk/client-fetch 11.3.0-prerelease.33

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.
Files changed (157) hide show
  1. package/LICENSE +26 -0
  2. package/README.md +33 -0
  3. package/cjs/api-fetch-client.js +581 -0
  4. package/cjs/fetch-plugin.js +4 -0
  5. package/cjs/plugins/abort/abort.fetch.js +84 -0
  6. package/cjs/plugins/abort/abort.spec.js +204 -0
  7. package/cjs/plugins/abort/index.js +18 -0
  8. package/cjs/plugins/concurrent/concurrent.fetch.js +263 -0
  9. package/cjs/plugins/concurrent/concurrent.spec.js +239 -0
  10. package/cjs/plugins/concurrent/index.js +18 -0
  11. package/cjs/plugins/index.js +25 -0
  12. package/cjs/plugins/keepalive/index.js +18 -0
  13. package/cjs/plugins/keepalive/keepalive.request.js +289 -0
  14. package/cjs/plugins/keepalive/keepalive.spec.js +162 -0
  15. package/cjs/plugins/mock-intercept/index.js +19 -0
  16. package/cjs/plugins/mock-intercept/mock-intercept.fetch.js +288 -0
  17. package/cjs/plugins/mock-intercept/mock-intercept.interface.js +4 -0
  18. package/cjs/plugins/mock-intercept/mock-intercept.spec.js +445 -0
  19. package/cjs/plugins/perf-metric/index.js +18 -0
  20. package/cjs/plugins/perf-metric/perf-metric.fetch.js +371 -0
  21. package/cjs/plugins/perf-metric/perf-metric.probe.spec.js +60 -0
  22. package/cjs/plugins/retry/index.js +18 -0
  23. package/cjs/plugins/retry/retry.fetch.js +371 -0
  24. package/cjs/plugins/retry/retry.spec.js +348 -0
  25. package/cjs/plugins/timeout/index.js +18 -0
  26. package/cjs/plugins/timeout/timeout.fetch.js +320 -0
  27. package/cjs/plugins/timeout/timeout.spec.js +443 -0
  28. package/cjs/plugins/wait-for/index.js +18 -0
  29. package/cjs/plugins/wait-for/wait-for.fetch.js +350 -0
  30. package/cjs/plugins/wait-for/wait-for.spec.js +383 -0
  31. package/cjs/public_api.js +20 -0
  32. package/collection.json +11 -0
  33. package/esm2015/api-fetch-client.js +571 -0
  34. package/esm2015/fetch-plugin.js +4 -0
  35. package/esm2015/plugins/abort/abort.fetch.js +74 -0
  36. package/esm2015/plugins/abort/abort.spec.js +200 -0
  37. package/esm2015/plugins/abort/index.js +1 -0
  38. package/esm2015/plugins/concurrent/concurrent.fetch.js +255 -0
  39. package/esm2015/plugins/concurrent/concurrent.spec.js +235 -0
  40. package/esm2015/plugins/concurrent/index.js +1 -0
  41. package/esm2015/plugins/index.js +8 -0
  42. package/esm2015/plugins/keepalive/index.js +1 -0
  43. package/esm2015/plugins/keepalive/keepalive.request.js +281 -0
  44. package/esm2015/plugins/keepalive/keepalive.spec.js +158 -0
  45. package/esm2015/plugins/mock-intercept/index.js +2 -0
  46. package/esm2015/plugins/mock-intercept/mock-intercept.fetch.js +283 -0
  47. package/esm2015/plugins/mock-intercept/mock-intercept.interface.js +1 -0
  48. package/esm2015/plugins/mock-intercept/mock-intercept.spec.js +441 -0
  49. package/esm2015/plugins/perf-metric/index.js +1 -0
  50. package/esm2015/plugins/perf-metric/perf-metric.fetch.js +363 -0
  51. package/esm2015/plugins/perf-metric/perf-metric.probe.spec.js +56 -0
  52. package/esm2015/plugins/retry/index.js +1 -0
  53. package/esm2015/plugins/retry/retry.fetch.js +363 -0
  54. package/esm2015/plugins/retry/retry.spec.js +344 -0
  55. package/esm2015/plugins/timeout/index.js +1 -0
  56. package/esm2015/plugins/timeout/timeout.fetch.js +310 -0
  57. package/esm2015/plugins/timeout/timeout.spec.js +439 -0
  58. package/esm2015/plugins/wait-for/index.js +1 -0
  59. package/esm2015/plugins/wait-for/wait-for.fetch.js +379 -0
  60. package/esm2015/plugins/wait-for/wait-for.spec.js +379 -0
  61. package/esm2015/public_api.js +3 -0
  62. package/package.json +196 -0
  63. package/schematics/ng-add/index.d.ts +8 -0
  64. package/schematics/ng-add/index.d.ts.map +1 -0
  65. package/schematics/ng-add/index.js +67 -0
  66. package/schematics/ng-add/migration/import-map.d.ts +6 -0
  67. package/schematics/ng-add/migration/import-map.d.ts.map +1 -0
  68. package/schematics/ng-add/migration/import-map.js +39 -0
  69. package/schematics/ng-add/schema.d.ts +6 -0
  70. package/schematics/ng-add/schema.d.ts.map +1 -0
  71. package/schematics/ng-add/schema.js +3 -0
  72. package/schematics/ng-add/schema.json +18 -0
  73. package/schematics/package.json +3 -0
  74. package/src/api-fetch-client.d.ts +46 -0
  75. package/src/api-fetch-client.d.ts.map +1 -0
  76. package/src/api-fetch-client.js +126 -0
  77. package/src/api-fetch-client.js.map +1 -0
  78. package/src/fetch-plugin.d.ts +38 -0
  79. package/src/fetch-plugin.d.ts.map +1 -0
  80. package/src/fetch-plugin.js +2 -0
  81. package/src/fetch-plugin.js.map +1 -0
  82. package/src/plugins/abort/abort.fetch.d.ts +66 -0
  83. package/src/plugins/abort/abort.fetch.d.ts.map +1 -0
  84. package/src/plugins/abort/abort.fetch.js +32 -0
  85. package/src/plugins/abort/abort.fetch.js.map +1 -0
  86. package/src/plugins/abort/index.d.ts +2 -0
  87. package/src/plugins/abort/index.d.ts.map +1 -0
  88. package/src/plugins/abort/index.js +2 -0
  89. package/src/plugins/abort/index.js.map +1 -0
  90. package/src/plugins/concurrent/concurrent.fetch.d.ts +33 -0
  91. package/src/plugins/concurrent/concurrent.fetch.d.ts.map +1 -0
  92. package/src/plugins/concurrent/concurrent.fetch.js +57 -0
  93. package/src/plugins/concurrent/concurrent.fetch.js.map +1 -0
  94. package/src/plugins/concurrent/index.d.ts +2 -0
  95. package/src/plugins/concurrent/index.d.ts.map +1 -0
  96. package/src/plugins/concurrent/index.js +2 -0
  97. package/src/plugins/concurrent/index.js.map +1 -0
  98. package/src/plugins/index.d.ts +9 -0
  99. package/src/plugins/index.d.ts.map +1 -0
  100. package/src/plugins/index.js +9 -0
  101. package/src/plugins/index.js.map +1 -0
  102. package/src/plugins/keepalive/index.d.ts +2 -0
  103. package/src/plugins/keepalive/index.d.ts.map +1 -0
  104. package/src/plugins/keepalive/index.js +2 -0
  105. package/src/plugins/keepalive/index.js.map +1 -0
  106. package/src/plugins/keepalive/keepalive.request.d.ts +18 -0
  107. package/src/plugins/keepalive/keepalive.request.d.ts.map +1 -0
  108. package/src/plugins/keepalive/keepalive.request.js +39 -0
  109. package/src/plugins/keepalive/keepalive.request.js.map +1 -0
  110. package/src/plugins/mock-intercept/index.d.ts +3 -0
  111. package/src/plugins/mock-intercept/index.d.ts.map +1 -0
  112. package/src/plugins/mock-intercept/index.js +3 -0
  113. package/src/plugins/mock-intercept/index.js.map +1 -0
  114. package/src/plugins/mock-intercept/mock-intercept.fetch.d.ts +15 -0
  115. package/src/plugins/mock-intercept/mock-intercept.fetch.d.ts.map +1 -0
  116. package/src/plugins/mock-intercept/mock-intercept.fetch.js +47 -0
  117. package/src/plugins/mock-intercept/mock-intercept.fetch.js.map +1 -0
  118. package/src/plugins/mock-intercept/mock-intercept.interface.d.ts +10 -0
  119. package/src/plugins/mock-intercept/mock-intercept.interface.d.ts.map +1 -0
  120. package/src/plugins/mock-intercept/mock-intercept.interface.js +2 -0
  121. package/src/plugins/mock-intercept/mock-intercept.interface.js.map +1 -0
  122. package/src/plugins/perf-metric/index.d.ts +2 -0
  123. package/src/plugins/perf-metric/index.d.ts.map +1 -0
  124. package/src/plugins/perf-metric/index.js +2 -0
  125. package/src/plugins/perf-metric/index.js.map +1 -0
  126. package/src/plugins/perf-metric/perf-metric.fetch.d.ts +133 -0
  127. package/src/plugins/perf-metric/perf-metric.fetch.d.ts.map +1 -0
  128. package/src/plugins/perf-metric/perf-metric.fetch.js +111 -0
  129. package/src/plugins/perf-metric/perf-metric.fetch.js.map +1 -0
  130. package/src/plugins/retry/index.d.ts +2 -0
  131. package/src/plugins/retry/index.d.ts.map +1 -0
  132. package/src/plugins/retry/index.js +2 -0
  133. package/src/plugins/retry/index.js.map +1 -0
  134. package/src/plugins/retry/retry.fetch.d.ts +53 -0
  135. package/src/plugins/retry/retry.fetch.d.ts.map +1 -0
  136. package/src/plugins/retry/retry.fetch.js +66 -0
  137. package/src/plugins/retry/retry.fetch.js.map +1 -0
  138. package/src/plugins/timeout/index.d.ts +2 -0
  139. package/src/plugins/timeout/index.d.ts.map +1 -0
  140. package/src/plugins/timeout/index.js +2 -0
  141. package/src/plugins/timeout/index.js.map +1 -0
  142. package/src/plugins/timeout/timeout.fetch.d.ts +47 -0
  143. package/src/plugins/timeout/timeout.fetch.d.ts.map +1 -0
  144. package/src/plugins/timeout/timeout.fetch.js +105 -0
  145. package/src/plugins/timeout/timeout.fetch.js.map +1 -0
  146. package/src/plugins/wait-for/index.d.ts +2 -0
  147. package/src/plugins/wait-for/index.d.ts.map +1 -0
  148. package/src/plugins/wait-for/index.js +2 -0
  149. package/src/plugins/wait-for/index.js.map +1 -0
  150. package/src/plugins/wait-for/wait-for.fetch.d.ts +78 -0
  151. package/src/plugins/wait-for/wait-for.fetch.d.ts.map +1 -0
  152. package/src/plugins/wait-for/wait-for.fetch.js +104 -0
  153. package/src/plugins/wait-for/wait-for.fetch.js.map +1 -0
  154. package/src/public_api.d.ts +4 -0
  155. package/src/public_api.d.ts.map +1 -0
  156. package/src/public_api.js +4 -0
  157. package/src/public_api.js.map +1 -0
@@ -0,0 +1,200 @@
1
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
+ try {
3
+ var info = gen[key](arg);
4
+ var value = info.value;
5
+ } catch (error) {
6
+ reject(error);
7
+ return;
8
+ }
9
+ if (info.done) {
10
+ resolve(value);
11
+ } else {
12
+ Promise.resolve(value).then(_next, _throw);
13
+ }
14
+ }
15
+ function _async_to_generator(fn) {
16
+ return function() {
17
+ var self = this, args = arguments;
18
+ return new Promise(function(resolve, reject) {
19
+ var gen = fn.apply(self, args);
20
+ function _next(value) {
21
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
+ }
23
+ function _throw(err) {
24
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
+ }
26
+ _next(undefined);
27
+ });
28
+ };
29
+ }
30
+ function _ts_generator(thisArg, body) {
31
+ var f, y, t, g, _ = {
32
+ label: 0,
33
+ sent: function() {
34
+ if (t[0] & 1) throw t[1];
35
+ return t[1];
36
+ },
37
+ trys: [],
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() {
45
+ return this;
46
+ }), g;
47
+ function verb(n) {
48
+ return function(v) {
49
+ return step([
50
+ n,
51
+ v
52
+ ]);
53
+ };
54
+ }
55
+ function step(op) {
56
+ if (f) throw new TypeError("Generator is already executing.");
57
+ while(_)try {
58
+ 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
+ if (y = 0, t) op = [
60
+ op[0] & 2,
61
+ t.value
62
+ ];
63
+ switch(op[0]){
64
+ case 0:
65
+ case 1:
66
+ t = op;
67
+ break;
68
+ case 4:
69
+ _.label++;
70
+ return {
71
+ value: op[1],
72
+ done: false
73
+ };
74
+ case 5:
75
+ _.label++;
76
+ y = op[1];
77
+ op = [
78
+ 0
79
+ ];
80
+ continue;
81
+ case 7:
82
+ op = _.ops.pop();
83
+ _.trys.pop();
84
+ continue;
85
+ default:
86
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
87
+ _ = 0;
88
+ continue;
89
+ }
90
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
91
+ _.label = op[1];
92
+ break;
93
+ }
94
+ if (op[0] === 6 && _.label < t[1]) {
95
+ _.label = t[1];
96
+ t = op;
97
+ break;
98
+ }
99
+ if (t && _.label < t[2]) {
100
+ _.label = t[2];
101
+ _.ops.push(op);
102
+ break;
103
+ }
104
+ if (t[2]) _.ops.pop();
105
+ _.trys.pop();
106
+ continue;
107
+ }
108
+ op = body.call(thisArg, _);
109
+ } catch (e) {
110
+ op = [
111
+ 6,
112
+ e
113
+ ];
114
+ y = 0;
115
+ } finally{
116
+ f = t = 0;
117
+ }
118
+ if (op[0] & 5) throw op[1];
119
+ return {
120
+ value: op[0] ? op[1] : void 0,
121
+ done: true
122
+ };
123
+ }
124
+ }
125
+ import { AbortFetch } from './abort.fetch';
126
+ describe('Abort Plugin', function() {
127
+ it('should trigger the callback', /*#__PURE__*/ _async_to_generator(function() {
128
+ var fn, plugin, runner;
129
+ return _ts_generator(this, function(_state) {
130
+ switch(_state.label){
131
+ case 0:
132
+ fn = jest.fn();
133
+ plugin = new AbortFetch(fn);
134
+ runner = plugin.load({});
135
+ return [
136
+ 4,
137
+ runner.transform(Promise.resolve())
138
+ ];
139
+ case 1:
140
+ _state.sent();
141
+ expect(fn).toHaveBeenCalled();
142
+ return [
143
+ 2
144
+ ];
145
+ }
146
+ });
147
+ }));
148
+ it('should trigger abort signal if true', /*#__PURE__*/ _async_to_generator(function() {
149
+ var defaultContext, fn, plugin, runner;
150
+ return _ts_generator(this, function(_state) {
151
+ switch(_state.label){
152
+ case 0:
153
+ defaultContext = {
154
+ controller: {
155
+ abort: jest.fn()
156
+ }
157
+ };
158
+ fn = jest.fn().mockResolvedValue(true);
159
+ plugin = new AbortFetch(fn);
160
+ runner = plugin.load(defaultContext);
161
+ return [
162
+ 4,
163
+ runner.transform(Promise.resolve())
164
+ ];
165
+ case 1:
166
+ _state.sent();
167
+ expect(defaultContext.controller.abort).toHaveBeenCalled();
168
+ return [
169
+ 2
170
+ ];
171
+ }
172
+ });
173
+ }));
174
+ it('should not trigger abort signal if false', /*#__PURE__*/ _async_to_generator(function() {
175
+ var defaultContext, fn, plugin, runner;
176
+ return _ts_generator(this, function(_state) {
177
+ switch(_state.label){
178
+ case 0:
179
+ defaultContext = {
180
+ controller: {
181
+ abort: jest.fn()
182
+ }
183
+ };
184
+ fn = jest.fn().mockResolvedValue(false);
185
+ plugin = new AbortFetch(fn);
186
+ runner = plugin.load(defaultContext);
187
+ return [
188
+ 4,
189
+ runner.transform(Promise.resolve())
190
+ ];
191
+ case 1:
192
+ _state.sent();
193
+ expect(defaultContext.controller.abort).not.toHaveBeenCalled();
194
+ return [
195
+ 2
196
+ ];
197
+ }
198
+ });
199
+ }));
200
+ });
@@ -0,0 +1 @@
1
+ export * from './abort.fetch';
@@ -0,0 +1,255 @@
1
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
+ try {
3
+ var info = gen[key](arg);
4
+ var value = info.value;
5
+ } catch (error) {
6
+ reject(error);
7
+ return;
8
+ }
9
+ if (info.done) {
10
+ resolve(value);
11
+ } else {
12
+ Promise.resolve(value).then(_next, _throw);
13
+ }
14
+ }
15
+ function _async_to_generator(fn) {
16
+ return function() {
17
+ var self = this, args = arguments;
18
+ return new Promise(function(resolve, reject) {
19
+ var gen = fn.apply(self, args);
20
+ function _next(value) {
21
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
+ }
23
+ function _throw(err) {
24
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
+ }
26
+ _next(undefined);
27
+ });
28
+ };
29
+ }
30
+ function _class_call_check(instance, Constructor) {
31
+ if (!(instance instanceof Constructor)) {
32
+ throw new TypeError("Cannot call a class as a function");
33
+ }
34
+ }
35
+ function _defineProperties(target, props) {
36
+ for(var i = 0; i < props.length; i++){
37
+ var descriptor = props[i];
38
+ descriptor.enumerable = descriptor.enumerable || false;
39
+ descriptor.configurable = true;
40
+ if ("value" in descriptor) descriptor.writable = true;
41
+ Object.defineProperty(target, descriptor.key, descriptor);
42
+ }
43
+ }
44
+ function _create_class(Constructor, protoProps, staticProps) {
45
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
46
+ if (staticProps) _defineProperties(Constructor, staticProps);
47
+ return Constructor;
48
+ }
49
+ function _define_property(obj, key, value) {
50
+ if (key in obj) {
51
+ Object.defineProperty(obj, key, {
52
+ value: value,
53
+ enumerable: true,
54
+ configurable: true,
55
+ writable: true
56
+ });
57
+ } else {
58
+ obj[key] = value;
59
+ }
60
+ return obj;
61
+ }
62
+ function _ts_generator(thisArg, body) {
63
+ var f, y, t, g, _ = {
64
+ label: 0,
65
+ sent: function() {
66
+ if (t[0] & 1) throw t[1];
67
+ return t[1];
68
+ },
69
+ trys: [],
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() {
77
+ return this;
78
+ }), g;
79
+ function verb(n) {
80
+ return function(v) {
81
+ return step([
82
+ n,
83
+ v
84
+ ]);
85
+ };
86
+ }
87
+ function step(op) {
88
+ if (f) throw new TypeError("Generator is already executing.");
89
+ while(_)try {
90
+ 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
+ if (y = 0, t) op = [
92
+ op[0] & 2,
93
+ t.value
94
+ ];
95
+ switch(op[0]){
96
+ case 0:
97
+ case 1:
98
+ t = op;
99
+ break;
100
+ case 4:
101
+ _.label++;
102
+ return {
103
+ value: op[1],
104
+ done: false
105
+ };
106
+ case 5:
107
+ _.label++;
108
+ y = op[1];
109
+ op = [
110
+ 0
111
+ ];
112
+ continue;
113
+ case 7:
114
+ op = _.ops.pop();
115
+ _.trys.pop();
116
+ continue;
117
+ default:
118
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
119
+ _ = 0;
120
+ continue;
121
+ }
122
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
123
+ _.label = op[1];
124
+ break;
125
+ }
126
+ if (op[0] === 6 && _.label < t[1]) {
127
+ _.label = t[1];
128
+ t = op;
129
+ break;
130
+ }
131
+ if (t && _.label < t[2]) {
132
+ _.label = t[2];
133
+ _.ops.push(op);
134
+ break;
135
+ }
136
+ if (t[2]) _.ops.pop();
137
+ _.trys.pop();
138
+ continue;
139
+ }
140
+ op = body.call(thisArg, _);
141
+ } catch (e) {
142
+ op = [
143
+ 6,
144
+ e
145
+ ];
146
+ y = 0;
147
+ } finally{
148
+ f = t = 0;
149
+ }
150
+ if (op[0] & 5) throw op[1];
151
+ return {
152
+ value: op[0] ? op[1] : void 0,
153
+ done: true
154
+ };
155
+ }
156
+ }
157
+ /**
158
+ * Plugin to limit the number of concurrent call
159
+ */ export var ConcurrentFetch = /*#__PURE__*/ function() {
160
+ "use strict";
161
+ function ConcurrentFetch() {
162
+ var maxConcurrentPoolSize = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 10;
163
+ _class_call_check(this, ConcurrentFetch);
164
+ /** Maximum number of concurrent call */ _define_property(this, "maxConcurrentPoolSize", void 0);
165
+ /** Pool of pending fetch calls */ _define_property(this, "pool", []);
166
+ /** Size of the pool of concurrent calls */ _define_property(this, "poolSize", 0);
167
+ /** List of calls waiting to start */ _define_property(this, "waitingResolvers", []);
168
+ this.maxConcurrentPoolSize = maxConcurrentPoolSize;
169
+ }
170
+ _create_class(ConcurrentFetch, [
171
+ {
172
+ key: "canStart",
173
+ value: /**
174
+ * Return true if a new call can start
175
+ */ function canStart() {
176
+ return this.poolSize <= this.maxConcurrentPoolSize;
177
+ }
178
+ },
179
+ {
180
+ key: "unstackResolve",
181
+ value: /**
182
+ * Unstack and resolve the promise stopping the call to start
183
+ */ function unstackResolve() {
184
+ if (this.canStart() && this.waitingResolvers.length) {
185
+ this.waitingResolvers.shift()(true);
186
+ }
187
+ }
188
+ },
189
+ {
190
+ key: "load",
191
+ value: /** @inheritDoc */ function load(_context) {
192
+ var _this = this;
193
+ this.poolSize++;
194
+ var _this1 = this;
195
+ return {
196
+ canStart: function() {
197
+ return new Promise(function(resolve) {
198
+ return _this.canStart() ? resolve(true) : _this.waitingResolvers.push(resolve);
199
+ });
200
+ },
201
+ transform: function() {
202
+ var _ref = _async_to_generator(function(fetchCall) {
203
+ var fetchResponse, e;
204
+ return _ts_generator(this, function(_state) {
205
+ switch(_state.label){
206
+ case 0:
207
+ _this1.pool.push(fetchCall);
208
+ _state.label = 1;
209
+ case 1:
210
+ _state.trys.push([
211
+ 1,
212
+ 3,
213
+ 4,
214
+ 5
215
+ ]);
216
+ return [
217
+ 4,
218
+ fetchCall
219
+ ];
220
+ case 2:
221
+ fetchResponse = _state.sent();
222
+ return [
223
+ 2,
224
+ fetchResponse
225
+ ];
226
+ case 3:
227
+ e = _state.sent();
228
+ throw e;
229
+ case 4:
230
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
231
+ _this1.pool = _this1.pool.filter(function(call) {
232
+ return call !== fetchCall;
233
+ });
234
+ _this1.poolSize--;
235
+ _this1.unstackResolve();
236
+ return [
237
+ 7
238
+ ];
239
+ case 5:
240
+ return [
241
+ 2
242
+ ];
243
+ }
244
+ });
245
+ });
246
+ return function(fetchCall) {
247
+ return _ref.apply(this, arguments);
248
+ };
249
+ }()
250
+ };
251
+ }
252
+ }
253
+ ]);
254
+ return ConcurrentFetch;
255
+ }();
@@ -0,0 +1,235 @@
1
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
+ try {
3
+ var info = gen[key](arg);
4
+ var value = info.value;
5
+ } catch (error) {
6
+ reject(error);
7
+ return;
8
+ }
9
+ if (info.done) {
10
+ resolve(value);
11
+ } else {
12
+ Promise.resolve(value).then(_next, _throw);
13
+ }
14
+ }
15
+ function _async_to_generator(fn) {
16
+ return function() {
17
+ var self = this, args = arguments;
18
+ return new Promise(function(resolve, reject) {
19
+ var gen = fn.apply(self, args);
20
+ function _next(value) {
21
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
+ }
23
+ function _throw(err) {
24
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
+ }
26
+ _next(undefined);
27
+ });
28
+ };
29
+ }
30
+ function _ts_generator(thisArg, body) {
31
+ var f, y, t, g, _ = {
32
+ label: 0,
33
+ sent: function() {
34
+ if (t[0] & 1) throw t[1];
35
+ return t[1];
36
+ },
37
+ trys: [],
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() {
45
+ return this;
46
+ }), g;
47
+ function verb(n) {
48
+ return function(v) {
49
+ return step([
50
+ n,
51
+ v
52
+ ]);
53
+ };
54
+ }
55
+ function step(op) {
56
+ if (f) throw new TypeError("Generator is already executing.");
57
+ while(_)try {
58
+ 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
+ if (y = 0, t) op = [
60
+ op[0] & 2,
61
+ t.value
62
+ ];
63
+ switch(op[0]){
64
+ case 0:
65
+ case 1:
66
+ t = op;
67
+ break;
68
+ case 4:
69
+ _.label++;
70
+ return {
71
+ value: op[1],
72
+ done: false
73
+ };
74
+ case 5:
75
+ _.label++;
76
+ y = op[1];
77
+ op = [
78
+ 0
79
+ ];
80
+ continue;
81
+ case 7:
82
+ op = _.ops.pop();
83
+ _.trys.pop();
84
+ continue;
85
+ default:
86
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
87
+ _ = 0;
88
+ continue;
89
+ }
90
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
91
+ _.label = op[1];
92
+ break;
93
+ }
94
+ if (op[0] === 6 && _.label < t[1]) {
95
+ _.label = t[1];
96
+ t = op;
97
+ break;
98
+ }
99
+ if (t && _.label < t[2]) {
100
+ _.label = t[2];
101
+ _.ops.push(op);
102
+ break;
103
+ }
104
+ if (t[2]) _.ops.pop();
105
+ _.trys.pop();
106
+ continue;
107
+ }
108
+ op = body.call(thisArg, _);
109
+ } catch (e) {
110
+ op = [
111
+ 6,
112
+ e
113
+ ];
114
+ y = 0;
115
+ } finally{
116
+ f = t = 0;
117
+ }
118
+ if (op[0] & 5) throw op[1];
119
+ return {
120
+ value: op[0] ? op[1] : void 0,
121
+ done: true
122
+ };
123
+ }
124
+ }
125
+ import { ConcurrentFetch } from './concurrent.fetch';
126
+ describe('Concurrent Fetch Plugin', function() {
127
+ it('should start if the limit is not reach', /*#__PURE__*/ _async_to_generator(function() {
128
+ var plugin, runner, canStart;
129
+ return _ts_generator(this, function(_state) {
130
+ switch(_state.label){
131
+ case 0:
132
+ plugin = new ConcurrentFetch(3);
133
+ plugin.load({});
134
+ runner = plugin.load({});
135
+ return [
136
+ 4,
137
+ runner.canStart()
138
+ ];
139
+ case 1:
140
+ canStart = _state.sent();
141
+ expect(canStart).toBe(true);
142
+ return [
143
+ 2
144
+ ];
145
+ }
146
+ });
147
+ }));
148
+ it('should retrieve the fetch call in the pool', function() {
149
+ var plugin = new ConcurrentFetch(3);
150
+ var call = new Promise(function(resolve) {
151
+ return setTimeout(function() {
152
+ return resolve(undefined);
153
+ }, 1000);
154
+ });
155
+ var test = new Promise(function(resolve) {
156
+ return setTimeout(function() {
157
+ return resolve(undefined);
158
+ }, 1000);
159
+ });
160
+ void plugin.load({}).transform(call);
161
+ void plugin.load({}).transform(call);
162
+ void plugin.load({}).transform(test);
163
+ expect(plugin.pool[2]).toBe(test);
164
+ });
165
+ it('should start only when the pool is available', /*#__PURE__*/ _async_to_generator(function() {
166
+ var plugin, resolves, call0, call1, result, runner1, canStart1, runner2, pCanStart2;
167
+ return _ts_generator(this, function(_state) {
168
+ switch(_state.label){
169
+ case 0:
170
+ plugin = new ConcurrentFetch(2);
171
+ resolves = [
172
+ null,
173
+ null
174
+ ];
175
+ call0 = new Promise(function(resolve) {
176
+ return resolves[0] = resolve;
177
+ });
178
+ call1 = new Promise(function(resolve) {
179
+ return resolves[1] = resolve;
180
+ });
181
+ result = {
182
+ res: false
183
+ };
184
+ void plugin.load({}).transform(call0);
185
+ runner1 = plugin.load({});
186
+ canStart1 = runner1.canStart();
187
+ return [
188
+ 4,
189
+ jest.runAllTimersAsync()
190
+ ];
191
+ case 1:
192
+ _state.sent();
193
+ return [
194
+ 4,
195
+ canStart1
196
+ ];
197
+ case 2:
198
+ expect.apply(void 0, [
199
+ _state.sent()
200
+ ]).toBe(true);
201
+ void runner1.transform(call1);
202
+ runner2 = plugin.load({});
203
+ pCanStart2 = runner2.canStart();
204
+ return [
205
+ 4,
206
+ jest.runAllTimersAsync()
207
+ ];
208
+ case 3:
209
+ _state.sent();
210
+ expect(plugin.waitingResolvers.length).toBe(1);
211
+ result.res = true;
212
+ resolves[0]();
213
+ return [
214
+ 4,
215
+ pCanStart2
216
+ ];
217
+ case 4:
218
+ expect.apply(void 0, [
219
+ _state.sent()
220
+ ]).toBe(true);
221
+ resolves[1]();
222
+ return [
223
+ 4,
224
+ jest.advanceTimersByTimeAsync(500)
225
+ ];
226
+ case 5:
227
+ _state.sent();
228
+ expect(plugin.waitingResolvers.length).toBe(0);
229
+ return [
230
+ 2
231
+ ];
232
+ }
233
+ });
234
+ }));
235
+ });
@@ -0,0 +1 @@
1
+ export * from './concurrent.fetch';
@@ -0,0 +1,8 @@
1
+ export * from './abort/index';
2
+ export * from './concurrent/index';
3
+ export * from './keepalive/index';
4
+ export * from './mock-intercept/index';
5
+ export * from './perf-metric/index';
6
+ export * from './retry/index';
7
+ export * from './timeout/index';
8
+ export * from './wait-for/index';
@@ -0,0 +1 @@
1
+ export * from './keepalive.request';