@modern-js/prod-server 2.14.0 → 2.16.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.
Files changed (122) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/cjs/constants.js +15 -31
  3. package/dist/cjs/index.js +35 -37
  4. package/dist/cjs/libs/context/context.js +53 -66
  5. package/dist/cjs/libs/context/index.js +15 -28
  6. package/dist/cjs/libs/hook-api/index.js +59 -54
  7. package/dist/cjs/libs/hook-api/route.js +28 -30
  8. package/dist/cjs/libs/hook-api/template.js +30 -34
  9. package/dist/cjs/libs/loadConfig.js +74 -65
  10. package/dist/cjs/libs/logger.js +46 -37
  11. package/dist/cjs/libs/metrics.js +7 -25
  12. package/dist/cjs/libs/proxy.js +29 -46
  13. package/dist/cjs/libs/render/cache/__tests__/cache.fun.test.js +48 -64
  14. package/dist/cjs/libs/render/cache/__tests__/cache.test.js +53 -37
  15. package/dist/cjs/libs/render/cache/__tests__/cacheable.js +38 -34
  16. package/dist/cjs/libs/render/cache/__tests__/error-configuration.js +22 -30
  17. package/dist/cjs/libs/render/cache/__tests__/matched-cache.js +86 -46
  18. package/dist/cjs/libs/render/cache/index.js +17 -37
  19. package/dist/cjs/libs/render/cache/page-caches/index.js +12 -28
  20. package/dist/cjs/libs/render/cache/page-caches/lru.js +32 -40
  21. package/dist/cjs/libs/render/cache/spr.js +104 -111
  22. package/dist/cjs/libs/render/cache/type.js +4 -15
  23. package/dist/cjs/libs/render/cache/util.js +29 -53
  24. package/dist/cjs/libs/render/index.js +75 -73
  25. package/dist/cjs/libs/render/measure.js +19 -34
  26. package/dist/cjs/libs/render/reader.js +52 -61
  27. package/dist/cjs/libs/render/ssr.js +34 -66
  28. package/dist/cjs/libs/render/static.js +22 -45
  29. package/dist/cjs/libs/render/type.js +10 -28
  30. package/dist/cjs/libs/render/utils.js +17 -38
  31. package/dist/cjs/libs/route/index.js +32 -31
  32. package/dist/cjs/libs/route/matcher.js +38 -38
  33. package/dist/cjs/libs/route/route.js +29 -26
  34. package/dist/cjs/libs/serveFile.js +23 -41
  35. package/dist/cjs/server/index.js +101 -107
  36. package/dist/cjs/server/modernServer.js +191 -171
  37. package/dist/cjs/server/modernServerSplit.js +12 -30
  38. package/dist/cjs/type.js +4 -15
  39. package/dist/cjs/utils.js +50 -50
  40. package/dist/cjs/workerServer.js +26 -36
  41. package/dist/esm/constants.js +24 -25
  42. package/dist/esm/index.js +11 -10
  43. package/dist/esm/libs/context/context.js +271 -264
  44. package/dist/esm/libs/context/index.js +3 -3
  45. package/dist/esm/libs/hook-api/index.js +237 -223
  46. package/dist/esm/libs/hook-api/route.js +62 -60
  47. package/dist/esm/libs/hook-api/template.js +117 -115
  48. package/dist/esm/libs/loadConfig.js +68 -69
  49. package/dist/esm/libs/logger.js +188 -174
  50. package/dist/esm/libs/metrics.js +6 -3
  51. package/dist/esm/libs/proxy.js +236 -221
  52. package/dist/esm/libs/render/cache/__tests__/cache.fun.test.js +286 -267
  53. package/dist/esm/libs/render/cache/__tests__/cache.test.js +765 -745
  54. package/dist/esm/libs/render/cache/__tests__/cacheable.js +62 -63
  55. package/dist/esm/libs/render/cache/__tests__/error-configuration.js +42 -43
  56. package/dist/esm/libs/render/cache/__tests__/matched-cache.js +134 -135
  57. package/dist/esm/libs/render/cache/index.js +337 -326
  58. package/dist/esm/libs/render/cache/page-caches/index.js +147 -141
  59. package/dist/esm/libs/render/cache/page-caches/lru.js +78 -76
  60. package/dist/esm/libs/render/cache/spr.js +465 -456
  61. package/dist/esm/libs/render/cache/type.js +1 -1
  62. package/dist/esm/libs/render/cache/util.js +266 -246
  63. package/dist/esm/libs/render/index.js +226 -218
  64. package/dist/esm/libs/render/measure.js +136 -128
  65. package/dist/esm/libs/render/reader.js +315 -304
  66. package/dist/esm/libs/render/ssr.js +214 -209
  67. package/dist/esm/libs/render/static.js +208 -198
  68. package/dist/esm/libs/render/type.js +6 -7
  69. package/dist/esm/libs/render/utils.js +8 -9
  70. package/dist/esm/libs/route/index.js +134 -123
  71. package/dist/esm/libs/route/matcher.js +140 -130
  72. package/dist/esm/libs/route/route.js +36 -37
  73. package/dist/esm/libs/serveFile.js +177 -168
  74. package/dist/esm/server/index.js +578 -549
  75. package/dist/esm/server/modernServer.js +1137 -1074
  76. package/dist/esm/server/modernServerSplit.js +344 -328
  77. package/dist/esm/type.js +1 -1
  78. package/dist/esm/utils.js +133 -124
  79. package/dist/esm/workerServer.js +226 -220
  80. package/dist/esm-node/constants.js +7 -14
  81. package/dist/esm-node/index.js +4 -9
  82. package/dist/esm-node/libs/context/context.js +32 -25
  83. package/dist/esm-node/libs/context/index.js +2 -5
  84. package/dist/esm-node/libs/hook-api/index.js +40 -21
  85. package/dist/esm-node/libs/hook-api/route.js +21 -8
  86. package/dist/esm-node/libs/hook-api/template.js +19 -14
  87. package/dist/esm-node/libs/loadConfig.js +11 -28
  88. package/dist/esm-node/libs/logger.js +37 -17
  89. package/dist/esm-node/libs/metrics.js +1 -3
  90. package/dist/esm-node/libs/proxy.js +14 -22
  91. package/dist/esm-node/libs/render/cache/__tests__/cache.fun.test.js +25 -36
  92. package/dist/esm-node/libs/render/cache/__tests__/cache.test.js +23 -11
  93. package/dist/esm-node/libs/render/cache/__tests__/cacheable.js +32 -13
  94. package/dist/esm-node/libs/render/cache/__tests__/error-configuration.js +16 -9
  95. package/dist/esm-node/libs/render/cache/__tests__/matched-cache.js +80 -25
  96. package/dist/esm-node/libs/render/cache/index.js +3 -10
  97. package/dist/esm-node/libs/render/cache/page-caches/index.js +4 -5
  98. package/dist/esm-node/libs/render/cache/page-caches/lru.js +20 -8
  99. package/dist/esm-node/libs/render/cache/spr.js +79 -80
  100. package/dist/esm-node/libs/render/cache/type.js +1 -0
  101. package/dist/esm-node/libs/render/cache/util.js +13 -23
  102. package/dist/esm-node/libs/render/index.js +10 -28
  103. package/dist/esm-node/libs/render/measure.js +7 -13
  104. package/dist/esm-node/libs/render/reader.js +31 -26
  105. package/dist/esm-node/libs/render/ssr.js +5 -21
  106. package/dist/esm-node/libs/render/static.js +1 -4
  107. package/dist/esm-node/libs/render/type.js +3 -6
  108. package/dist/esm-node/libs/render/utils.js +6 -18
  109. package/dist/esm-node/libs/route/index.js +20 -9
  110. package/dist/esm-node/libs/route/matcher.js +28 -17
  111. package/dist/esm-node/libs/route/route.js +23 -5
  112. package/dist/esm-node/libs/serveFile.js +2 -6
  113. package/dist/esm-node/server/index.js +72 -75
  114. package/dist/esm-node/server/modernServer.js +102 -130
  115. package/dist/esm-node/server/modernServerSplit.js +1 -4
  116. package/dist/esm-node/type.js +1 -0
  117. package/dist/esm-node/utils.js +41 -32
  118. package/dist/esm-node/workerServer.js +9 -10
  119. package/dist/types/libs/context/context.d.ts +1 -1
  120. package/dist/types/server/modernServer.d.ts +1 -1
  121. package/dist/types/utils.d.ts +1 -1
  122. package/package.json +12 -8
@@ -1,781 +1,801 @@
1
- function _arrayLikeToArray(arr, len) {
2
- if (len == null || len > arr.length) len = arr.length;
3
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
- return arr2;
1
+ function _array_like_to_array(arr, len) {
2
+ if (len == null || len > arr.length)
3
+ len = arr.length;
4
+ for (var i = 0, arr2 = new Array(len); i < len; i++)
5
+ arr2[i] = arr[i];
6
+ return arr2;
5
7
  }
6
- function _arrayWithHoles(arr) {
7
- if (Array.isArray(arr)) return arr;
8
+ function _array_with_holes(arr) {
9
+ if (Array.isArray(arr))
10
+ return arr;
8
11
  }
9
12
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
10
- try {
11
- var info = gen[key](arg);
12
- var value = info.value;
13
- } catch (error) {
14
- reject(error);
15
- return;
16
- }
17
- if (info.done) {
18
- resolve(value);
19
- } else {
20
- Promise.resolve(value).then(_next, _throw);
21
- }
13
+ try {
14
+ var info = gen[key](arg);
15
+ var value = info.value;
16
+ } catch (error) {
17
+ reject(error);
18
+ return;
19
+ }
20
+ if (info.done) {
21
+ resolve(value);
22
+ } else {
23
+ Promise.resolve(value).then(_next, _throw);
24
+ }
22
25
  }
23
- function _asyncToGenerator(fn) {
24
- return function() {
25
- var self = this, args = arguments;
26
- return new Promise(function(resolve, reject) {
27
- var gen = fn.apply(self, args);
28
- function _next(value) {
29
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
30
- }
31
- function _throw(err) {
32
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
33
- }
34
- _next(undefined);
35
- });
36
- };
26
+ function _async_to_generator(fn) {
27
+ return function() {
28
+ var self = this, args = arguments;
29
+ return new Promise(function(resolve, reject) {
30
+ var gen = fn.apply(self, args);
31
+ function _next(value) {
32
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
33
+ }
34
+ function _throw(err) {
35
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
36
+ }
37
+ _next(void 0);
38
+ });
39
+ };
37
40
  }
38
- function _defineProperty(obj, key, value) {
39
- if (key in obj) {
40
- Object.defineProperty(obj, key, {
41
- value: value,
42
- enumerable: true,
43
- configurable: true,
44
- writable: true
45
- });
46
- } else {
47
- obj[key] = value;
48
- }
49
- return obj;
41
+ function _define_property(obj, key, value) {
42
+ if (key in obj) {
43
+ Object.defineProperty(obj, key, {
44
+ value,
45
+ enumerable: true,
46
+ configurable: true,
47
+ writable: true
48
+ });
49
+ } else {
50
+ obj[key] = value;
51
+ }
52
+ return obj;
50
53
  }
51
- function _iterableToArray(iter) {
52
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
54
+ function _iterable_to_array(iter) {
55
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null)
56
+ return Array.from(iter);
53
57
  }
54
- function _nonIterableRest() {
55
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
58
+ function _non_iterable_rest() {
59
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
56
60
  }
57
- function _objectSpread(target) {
58
- for(var i = 1; i < arguments.length; i++){
59
- var source = arguments[i] != null ? arguments[i] : {};
60
- var ownKeys = Object.keys(source);
61
- if (typeof Object.getOwnPropertySymbols === "function") {
62
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
63
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
64
- }));
65
- }
66
- ownKeys.forEach(function(key) {
67
- _defineProperty(target, key, source[key]);
68
- });
61
+ function _object_spread(target) {
62
+ for (var i = 1; i < arguments.length; i++) {
63
+ var source = arguments[i] != null ? arguments[i] : {};
64
+ var ownKeys = Object.keys(source);
65
+ if (typeof Object.getOwnPropertySymbols === "function") {
66
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
67
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
68
+ }));
69
69
  }
70
- return target;
70
+ ownKeys.forEach(function(key) {
71
+ _define_property(target, key, source[key]);
72
+ });
73
+ }
74
+ return target;
71
75
  }
72
- function _toArray(arr) {
73
- return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest();
76
+ function _to_array(arr) {
77
+ return _array_with_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_rest();
74
78
  }
75
- function _unsupportedIterableToArray(o, minLen) {
76
- if (!o) return;
77
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
78
- var n = Object.prototype.toString.call(o).slice(8, -1);
79
- if (n === "Object" && o.constructor) n = o.constructor.name;
80
- if (n === "Map" || n === "Set") return Array.from(n);
81
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
79
+ function _unsupported_iterable_to_array(o, minLen) {
80
+ if (!o)
81
+ return;
82
+ if (typeof o === "string")
83
+ return _array_like_to_array(o, minLen);
84
+ var n = Object.prototype.toString.call(o).slice(8, -1);
85
+ if (n === "Object" && o.constructor)
86
+ n = o.constructor.name;
87
+ if (n === "Map" || n === "Set")
88
+ return Array.from(n);
89
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
90
+ return _array_like_to_array(o, minLen);
82
91
  }
83
92
  var __generator = this && this.__generator || function(thisArg, body) {
84
- var f, y, t, g, _ = {
85
- label: 0,
86
- sent: function() {
87
- if (t[0] & 1) throw t[1];
88
- return t[1];
89
- },
90
- trys: [],
91
- ops: []
93
+ var f, y, t, g, _ = {
94
+ label: 0,
95
+ sent: function() {
96
+ if (t[0] & 1)
97
+ throw t[1];
98
+ return t[1];
99
+ },
100
+ trys: [],
101
+ ops: []
102
+ };
103
+ return g = {
104
+ next: verb(0),
105
+ "throw": verb(1),
106
+ "return": verb(2)
107
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
108
+ return this;
109
+ }), g;
110
+ function verb(n) {
111
+ return function(v) {
112
+ return step([
113
+ n,
114
+ v
115
+ ]);
92
116
  };
93
- return g = {
94
- next: verb(0),
95
- "throw": verb(1),
96
- "return": verb(2)
97
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
98
- return this;
99
- }), g;
100
- function verb(n) {
101
- return function(v) {
102
- return step([
103
- n,
104
- v
105
- ]);
106
- };
107
- }
108
- function step(op) {
109
- if (f) throw new TypeError("Generator is already executing.");
110
- while(_)try {
111
- 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;
112
- if (y = 0, t) op = [
113
- op[0] & 2,
114
- t.value
115
- ];
116
- switch(op[0]){
117
- case 0:
118
- case 1:
119
- t = op;
120
- break;
121
- case 4:
122
- _.label++;
123
- return {
124
- value: op[1],
125
- done: false
126
- };
127
- case 5:
128
- _.label++;
129
- y = op[1];
130
- op = [
131
- 0
132
- ];
133
- continue;
134
- case 7:
135
- op = _.ops.pop();
136
- _.trys.pop();
137
- continue;
138
- default:
139
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
140
- _ = 0;
141
- continue;
142
- }
143
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
144
- _.label = op[1];
145
- break;
146
- }
147
- if (op[0] === 6 && _.label < t[1]) {
148
- _.label = t[1];
149
- t = op;
150
- break;
151
- }
152
- if (t && _.label < t[2]) {
153
- _.label = t[2];
154
- _.ops.push(op);
155
- break;
156
- }
157
- if (t[2]) _.ops.pop();
158
- _.trys.pop();
159
- continue;
160
- }
161
- op = body.call(thisArg, _);
162
- } catch (e) {
117
+ }
118
+ function step(op) {
119
+ if (f)
120
+ throw new TypeError("Generator is already executing.");
121
+ while (_)
122
+ try {
123
+ 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)
124
+ return t;
125
+ if (y = 0, t)
126
+ op = [
127
+ op[0] & 2,
128
+ t.value
129
+ ];
130
+ switch (op[0]) {
131
+ case 0:
132
+ case 1:
133
+ t = op;
134
+ break;
135
+ case 4:
136
+ _.label++;
137
+ return {
138
+ value: op[1],
139
+ done: false
140
+ };
141
+ case 5:
142
+ _.label++;
143
+ y = op[1];
163
144
  op = [
164
- 6,
165
- e
145
+ 0
166
146
  ];
167
- y = 0;
168
- } finally{
169
- f = t = 0;
147
+ continue;
148
+ case 7:
149
+ op = _.ops.pop();
150
+ _.trys.pop();
151
+ continue;
152
+ default:
153
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
154
+ _ = 0;
155
+ continue;
156
+ }
157
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
158
+ _.label = op[1];
159
+ break;
160
+ }
161
+ if (op[0] === 6 && _.label < t[1]) {
162
+ _.label = t[1];
163
+ t = op;
164
+ break;
165
+ }
166
+ if (t && _.label < t[2]) {
167
+ _.label = t[2];
168
+ _.ops.push(op);
169
+ break;
170
+ }
171
+ if (t[2])
172
+ _.ops.pop();
173
+ _.trys.pop();
174
+ continue;
170
175
  }
171
- if (op[0] & 5) throw op[1];
172
- return {
173
- value: op[0] ? op[1] : void 0,
174
- done: true
175
- };
176
- }
176
+ op = body.call(thisArg, _);
177
+ } catch (e) {
178
+ op = [
179
+ 6,
180
+ e
181
+ ];
182
+ y = 0;
183
+ } finally {
184
+ f = t = 0;
185
+ }
186
+ if (op[0] & 5)
187
+ throw op[1];
188
+ return {
189
+ value: op[0] ? op[1] : void 0,
190
+ done: true
191
+ };
192
+ }
177
193
  };
178
194
  import { createCache, destroyCache } from "../spr";
179
195
  import { errorConfiguration } from "./error-configuration";
180
196
  import { cacheabelAry } from "./cacheable";
181
197
  import { matchedCacheableAry } from "./matched-cache";
182
198
  var createCacheConfig = function() {
183
- var config = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
184
- return _objectSpread({
185
- excludes: null,
186
- includes: null,
187
- interval: 10,
188
- staleLimit: false,
189
- level: 0,
190
- fallback: false,
191
- matches: null
192
- }, config);
199
+ var config = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
200
+ return _object_spread({
201
+ excludes: null,
202
+ includes: null,
203
+ interval: 10,
204
+ staleLimit: false,
205
+ level: 0,
206
+ fallback: false,
207
+ matches: null
208
+ }, config);
193
209
  };
194
210
  jest.setTimeout(6e4);
195
211
  describe("cache", function() {
196
- it("should cache correctly", /*#__PURE__*/ _asyncToGenerator(function() {
197
- var cache, context, content, cacheConfig, cacheResult;
198
- return __generator(this, function(_state) {
199
- switch(_state.label){
200
- case 0:
201
- destroyCache();
202
- cache = createCache();
203
- context = {
204
- entry: "",
205
- pathname: "",
206
- query: {},
207
- headers: {}
208
- };
209
- content = "hello";
210
- cacheConfig = createCacheConfig();
211
- return [
212
- 4,
213
- cache.set(context, content, cacheConfig, true)
214
- ];
215
- case 1:
216
- _state.sent();
217
- return [
218
- 4,
219
- cache.get(context)
220
- ];
221
- case 2:
222
- cacheResult = _state.sent();
223
- expect(cacheResult).not.toBe(null);
224
- expect(cacheResult === null || cacheResult === void 0 ? void 0 : cacheResult.content).toBe("hello");
225
- return [
226
- 2
227
- ];
212
+ it("should cache correctly", /* @__PURE__ */ _async_to_generator(function() {
213
+ var cache, context, content, cacheConfig, cacheResult;
214
+ return __generator(this, function(_state) {
215
+ switch (_state.label) {
216
+ case 0:
217
+ destroyCache();
218
+ cache = createCache();
219
+ context = {
220
+ entry: "",
221
+ pathname: "",
222
+ query: {},
223
+ headers: {}
224
+ };
225
+ content = "hello";
226
+ cacheConfig = createCacheConfig();
227
+ return [
228
+ 4,
229
+ cache.set(context, content, cacheConfig, true)
230
+ ];
231
+ case 1:
232
+ _state.sent();
233
+ return [
234
+ 4,
235
+ cache.get(context)
236
+ ];
237
+ case 2:
238
+ cacheResult = _state.sent();
239
+ expect(cacheResult).not.toBe(null);
240
+ expect(cacheResult === null || cacheResult === void 0 ? void 0 : cacheResult.content).toBe("hello");
241
+ return [
242
+ 2
243
+ ];
244
+ }
245
+ });
246
+ }));
247
+ it("should ignore cache set when cache config not exist", /* @__PURE__ */ _async_to_generator(function() {
248
+ var cache, context, content, shouldCache;
249
+ return __generator(this, function(_state) {
250
+ switch (_state.label) {
251
+ case 0:
252
+ destroyCache();
253
+ destroyCache();
254
+ cache = createCache();
255
+ context = {
256
+ entry: "",
257
+ pathname: "",
258
+ query: {},
259
+ headers: {}
260
+ };
261
+ content = "hello";
262
+ return [
263
+ 4,
264
+ cache.set(context, content, null, true)
265
+ ];
266
+ case 1:
267
+ shouldCache = _state.sent();
268
+ expect(shouldCache).toBe(false);
269
+ return [
270
+ 2
271
+ ];
272
+ }
273
+ });
274
+ }));
275
+ it("should calcual cache key error", /* @__PURE__ */ _async_to_generator(function() {
276
+ var cache, content, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, config, cacheConfig, tmpEntry, context, shouldCache, err;
277
+ return __generator(this, function(_state) {
278
+ switch (_state.label) {
279
+ case 0:
280
+ destroyCache();
281
+ cache = createCache();
282
+ content = "hello";
283
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
284
+ _state.label = 1;
285
+ case 1:
286
+ _state.trys.push([
287
+ 1,
288
+ 6,
289
+ 7,
290
+ 8
291
+ ]);
292
+ _iterator = errorConfiguration[Symbol.iterator]();
293
+ _state.label = 2;
294
+ case 2:
295
+ if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done))
296
+ return [
297
+ 3,
298
+ 5
299
+ ];
300
+ config = _step.value;
301
+ cacheConfig = createCacheConfig(config);
302
+ tmpEntry = Math.random().toString();
303
+ context = {
304
+ entry: tmpEntry,
305
+ pathname: "",
306
+ query: {},
307
+ headers: {}
308
+ };
309
+ return [
310
+ 4,
311
+ cache.set(context, content, cacheConfig)
312
+ ];
313
+ case 3:
314
+ shouldCache = _state.sent();
315
+ expect(shouldCache).toBe(false);
316
+ _state.label = 4;
317
+ case 4:
318
+ _iteratorNormalCompletion = true;
319
+ return [
320
+ 3,
321
+ 2
322
+ ];
323
+ case 5:
324
+ return [
325
+ 3,
326
+ 8
327
+ ];
328
+ case 6:
329
+ err = _state.sent();
330
+ _didIteratorError = true;
331
+ _iteratorError = err;
332
+ return [
333
+ 3,
334
+ 8
335
+ ];
336
+ case 7:
337
+ try {
338
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
339
+ _iterator.return();
340
+ }
341
+ } finally {
342
+ if (_didIteratorError) {
343
+ throw _iteratorError;
228
344
  }
229
- });
230
- }));
231
- it("should ignore cache set when cache config not exist", /*#__PURE__*/ _asyncToGenerator(function() {
232
- var cache, context, content, shouldCache;
233
- return __generator(this, function(_state) {
234
- switch(_state.label){
235
- case 0:
236
- destroyCache();
237
- destroyCache();
238
- cache = createCache();
239
- context = {
240
- entry: "",
241
- pathname: "",
242
- query: {},
243
- headers: {}
244
- };
245
- content = "hello";
246
- return [
247
- 4,
248
- cache.set(context, content, null, true)
249
- ];
250
- case 1:
251
- shouldCache = _state.sent();
252
- expect(shouldCache).toBe(false);
253
- return [
254
- 2
255
- ];
345
+ }
346
+ return [
347
+ 7
348
+ ];
349
+ case 8:
350
+ return [
351
+ 2
352
+ ];
353
+ }
354
+ });
355
+ }));
356
+ it("should get nothing for diff requestKey", /* @__PURE__ */ _async_to_generator(function() {
357
+ var cache, context, content, cacheConfig, context_req, cacheResult;
358
+ return __generator(this, function(_state) {
359
+ switch (_state.label) {
360
+ case 0:
361
+ destroyCache();
362
+ cache = createCache();
363
+ context = {
364
+ entry: "",
365
+ pathname: "",
366
+ query: {},
367
+ headers: {}
368
+ };
369
+ content = "hello";
370
+ cacheConfig = createCacheConfig({
371
+ level: 1,
372
+ includes: {
373
+ query: [
374
+ "name"
375
+ ]
256
376
  }
257
- });
258
- }));
259
- it("should calcual cache key error", /*#__PURE__*/ _asyncToGenerator(function() {
260
- var cache, content, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, config, cacheConfig, tmpEntry, context, shouldCache, err;
261
- return __generator(this, function(_state) {
262
- switch(_state.label){
263
- case 0:
264
- destroyCache();
265
- cache = createCache();
266
- content = "hello";
267
- _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
268
- _state.label = 1;
269
- case 1:
270
- _state.trys.push([
271
- 1,
272
- 6,
273
- 7,
274
- 8
275
- ]);
276
- _iterator = errorConfiguration[Symbol.iterator]();
277
- _state.label = 2;
278
- case 2:
279
- if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
280
- 3,
281
- 5
282
- ];
283
- config = _step.value;
284
- cacheConfig = createCacheConfig(config);
285
- tmpEntry = Math.random().toString();
286
- context = {
287
- entry: tmpEntry,
288
- pathname: "",
289
- query: {},
290
- headers: {}
291
- };
292
- return [
293
- 4,
294
- cache.set(context, content, cacheConfig)
295
- ];
296
- case 3:
297
- shouldCache = _state.sent();
298
- expect(shouldCache).toBe(false);
299
- _state.label = 4;
300
- case 4:
301
- _iteratorNormalCompletion = true;
302
- return [
303
- 3,
304
- 2
305
- ];
306
- case 5:
307
- return [
308
- 3,
309
- 8
310
- ];
311
- case 6:
312
- err = _state.sent();
313
- _didIteratorError = true;
314
- _iteratorError = err;
315
- return [
316
- 3,
317
- 8
318
- ];
319
- case 7:
320
- try {
321
- if (!_iteratorNormalCompletion && _iterator.return != null) {
322
- _iterator.return();
323
- }
324
- } finally{
325
- if (_didIteratorError) {
326
- throw _iteratorError;
327
- }
328
- }
329
- return [
330
- 7
331
- ];
332
- case 8:
333
- return [
334
- 2
335
- ];
377
+ });
378
+ return [
379
+ 4,
380
+ cache.set(context, content, cacheConfig, true)
381
+ ];
382
+ case 1:
383
+ _state.sent();
384
+ context_req = {
385
+ entry: "",
386
+ pathname: "/home",
387
+ query: {},
388
+ headers: {}
389
+ };
390
+ return [
391
+ 4,
392
+ cache.get(context_req)
393
+ ];
394
+ case 2:
395
+ cacheResult = _state.sent();
396
+ expect(cacheResult).toBe(null);
397
+ return [
398
+ 2
399
+ ];
400
+ }
401
+ });
402
+ }));
403
+ it("should get nothing for diff cacheHash", /* @__PURE__ */ _async_to_generator(function() {
404
+ var cache, context, content, cacheConfig, context_req, cacheResult;
405
+ return __generator(this, function(_state) {
406
+ switch (_state.label) {
407
+ case 0:
408
+ destroyCache();
409
+ cache = createCache();
410
+ context = {
411
+ entry: "",
412
+ pathname: "",
413
+ query: {},
414
+ headers: {}
415
+ };
416
+ content = "hello";
417
+ cacheConfig = createCacheConfig({
418
+ level: 1,
419
+ includes: {
420
+ query: [
421
+ "name"
422
+ ]
336
423
  }
337
- });
338
- }));
339
- it("should get nothing for diff requestKey", /*#__PURE__*/ _asyncToGenerator(function() {
340
- var cache, context, content, cacheConfig, context_req, cacheResult;
341
- return __generator(this, function(_state) {
342
- switch(_state.label){
343
- case 0:
344
- destroyCache();
345
- cache = createCache();
346
- context = {
347
- entry: "",
348
- pathname: "",
349
- query: {},
350
- headers: {}
351
- };
352
- content = "hello";
353
- cacheConfig = createCacheConfig({
354
- level: 1,
355
- includes: {
356
- query: [
357
- "name"
358
- ]
359
- }
360
- });
361
- return [
362
- 4,
363
- cache.set(context, content, cacheConfig, true)
364
- ];
365
- case 1:
366
- _state.sent();
367
- context_req = {
368
- entry: "",
369
- pathname: "/home",
370
- query: {},
371
- headers: {}
372
- };
373
- return [
374
- 4,
375
- cache.get(context_req)
376
- ];
377
- case 2:
378
- cacheResult = _state.sent();
379
- expect(cacheResult).toBe(null);
380
- return [
381
- 2
382
- ];
424
+ });
425
+ return [
426
+ 4,
427
+ cache.set(context, content, cacheConfig, true)
428
+ ];
429
+ case 1:
430
+ _state.sent();
431
+ context_req = {
432
+ entry: "",
433
+ pathname: "",
434
+ query: {
435
+ name: "zll"
436
+ },
437
+ headers: {}
438
+ };
439
+ return [
440
+ 4,
441
+ cache.get(context_req)
442
+ ];
443
+ case 2:
444
+ cacheResult = _state.sent();
445
+ expect(cacheResult).toBe(null);
446
+ return [
447
+ 2
448
+ ];
449
+ }
450
+ });
451
+ }));
452
+ it("should get cache correctly", /* @__PURE__ */ _async_to_generator(function() {
453
+ var cache, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, cacheable, context, cacheConfig, cacheResult, err;
454
+ return __generator(this, function(_state) {
455
+ switch (_state.label) {
456
+ case 0:
457
+ destroyCache();
458
+ cache = createCache();
459
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
460
+ _state.label = 1;
461
+ case 1:
462
+ _state.trys.push([
463
+ 1,
464
+ 7,
465
+ 8,
466
+ 9
467
+ ]);
468
+ _iterator = cacheabelAry[Symbol.iterator]();
469
+ _state.label = 2;
470
+ case 2:
471
+ if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done))
472
+ return [
473
+ 3,
474
+ 6
475
+ ];
476
+ cacheable = _step.value;
477
+ context = {
478
+ entry: "",
479
+ pathname: cacheable.requestOpt.url,
480
+ query: cacheable.requestOpt.query || {},
481
+ headers: cacheable.requestOpt.headers || {}
482
+ };
483
+ cacheConfig = createCacheConfig(cacheable.cacheConfig || {});
484
+ return [
485
+ 4,
486
+ cache.set(context, cacheable.content, cacheConfig, true)
487
+ ];
488
+ case 3:
489
+ _state.sent();
490
+ return [
491
+ 4,
492
+ cache.get(context)
493
+ ];
494
+ case 4:
495
+ cacheResult = _state.sent();
496
+ expect(cacheResult === null || cacheResult === void 0 ? void 0 : cacheResult.content).toBe(cacheable.content);
497
+ _state.label = 5;
498
+ case 5:
499
+ _iteratorNormalCompletion = true;
500
+ return [
501
+ 3,
502
+ 2
503
+ ];
504
+ case 6:
505
+ return [
506
+ 3,
507
+ 9
508
+ ];
509
+ case 7:
510
+ err = _state.sent();
511
+ _didIteratorError = true;
512
+ _iteratorError = err;
513
+ return [
514
+ 3,
515
+ 9
516
+ ];
517
+ case 8:
518
+ try {
519
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
520
+ _iterator.return();
383
521
  }
384
- });
385
- }));
386
- it("should get nothing for diff cacheHash", /*#__PURE__*/ _asyncToGenerator(function() {
387
- var cache, context, content, cacheConfig, context_req, cacheResult;
388
- return __generator(this, function(_state) {
389
- switch(_state.label){
390
- case 0:
391
- destroyCache();
392
- cache = createCache();
393
- context = {
394
- entry: "",
395
- pathname: "",
396
- query: {},
397
- headers: {}
398
- };
399
- content = "hello";
400
- cacheConfig = createCacheConfig({
401
- level: 1,
402
- includes: {
403
- query: [
404
- "name"
405
- ]
406
- }
407
- });
408
- return [
409
- 4,
410
- cache.set(context, content, cacheConfig, true)
411
- ];
412
- case 1:
413
- _state.sent();
414
- context_req = {
415
- entry: "",
416
- pathname: "",
417
- query: {
418
- name: "zll"
419
- },
420
- headers: {}
421
- };
422
- return [
423
- 4,
424
- cache.get(context_req)
425
- ];
426
- case 2:
427
- cacheResult = _state.sent();
428
- expect(cacheResult).toBe(null);
429
- return [
430
- 2
431
- ];
522
+ } finally {
523
+ if (_didIteratorError) {
524
+ throw _iteratorError;
432
525
  }
433
- });
434
- }));
435
- it("should get cache correctly", /*#__PURE__*/ _asyncToGenerator(function() {
436
- var cache, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, cacheable, context, cacheConfig, cacheResult, err;
437
- return __generator(this, function(_state) {
438
- switch(_state.label){
439
- case 0:
440
- destroyCache();
441
- cache = createCache();
442
- _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
443
- _state.label = 1;
444
- case 1:
445
- _state.trys.push([
446
- 1,
447
- 7,
448
- 8,
449
- 9
450
- ]);
451
- _iterator = cacheabelAry[Symbol.iterator]();
452
- _state.label = 2;
453
- case 2:
454
- if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
455
- 3,
456
- 6
457
- ];
458
- cacheable = _step.value;
459
- context = {
460
- entry: "",
461
- pathname: cacheable.requestOpt.url,
462
- query: cacheable.requestOpt.query || {},
463
- headers: cacheable.requestOpt.headers || {}
464
- };
465
- cacheConfig = createCacheConfig(cacheable.cacheConfig || {});
466
- return [
467
- 4,
468
- cache.set(context, cacheable.content, cacheConfig, true)
469
- ];
470
- case 3:
471
- _state.sent();
472
- return [
473
- 4,
474
- cache.get(context)
475
- ];
476
- case 4:
477
- cacheResult = _state.sent();
478
- expect(cacheResult === null || cacheResult === void 0 ? void 0 : cacheResult.content).toBe(cacheable.content);
479
- _state.label = 5;
480
- case 5:
481
- _iteratorNormalCompletion = true;
482
- return [
483
- 3,
484
- 2
485
- ];
486
- case 6:
487
- return [
488
- 3,
489
- 9
490
- ];
491
- case 7:
492
- err = _state.sent();
493
- _didIteratorError = true;
494
- _iteratorError = err;
495
- return [
496
- 3,
497
- 9
498
- ];
499
- case 8:
500
- try {
501
- if (!_iteratorNormalCompletion && _iterator.return != null) {
502
- _iterator.return();
503
- }
504
- } finally{
505
- if (_didIteratorError) {
506
- throw _iteratorError;
507
- }
508
- }
509
- return [
510
- 7
511
- ];
512
- case 9:
513
- return [
514
- 2
515
- ];
526
+ }
527
+ return [
528
+ 7
529
+ ];
530
+ case 9:
531
+ return [
532
+ 2
533
+ ];
534
+ }
535
+ });
536
+ }));
537
+ it("should match cache correctly", /* @__PURE__ */ _async_to_generator(function() {
538
+ var cache, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, cacheable, _cacheable, baseCacheable, matchOne, other, _baseCacheable_requestOpt, requestOpt, cacheConfig, content, context, matchContext, cacheResult, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, notMatch, notMatchContext, nothing, err, err;
539
+ return __generator(this, function(_state) {
540
+ switch (_state.label) {
541
+ case 0:
542
+ destroyCache();
543
+ cache = createCache();
544
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
545
+ _state.label = 1;
546
+ case 1:
547
+ _state.trys.push([
548
+ 1,
549
+ 14,
550
+ 15,
551
+ 16
552
+ ]);
553
+ _iterator = matchedCacheableAry[Symbol.iterator]();
554
+ _state.label = 2;
555
+ case 2:
556
+ if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done))
557
+ return [
558
+ 3,
559
+ 13
560
+ ];
561
+ cacheable = _step.value;
562
+ _cacheable = _to_array(cacheable), baseCacheable = _cacheable[0], matchOne = _cacheable[1], other = _cacheable.slice(2);
563
+ _baseCacheable_requestOpt = baseCacheable.requestOpt, requestOpt = _baseCacheable_requestOpt === void 0 ? {} : _baseCacheable_requestOpt, cacheConfig = baseCacheable.cacheConfig, content = baseCacheable.content;
564
+ context = {
565
+ entry: "",
566
+ pathname: requestOpt.url,
567
+ query: requestOpt.query,
568
+ headers: requestOpt.headers
569
+ };
570
+ return [
571
+ 4,
572
+ cache.set(context, content, createCacheConfig(cacheConfig), true)
573
+ ];
574
+ case 3:
575
+ _state.sent();
576
+ matchContext = {
577
+ entry: "",
578
+ pathname: matchOne.url,
579
+ query: matchOne.query,
580
+ headers: matchOne.headers
581
+ };
582
+ return [
583
+ 4,
584
+ cache.get(matchContext)
585
+ ];
586
+ case 4:
587
+ cacheResult = _state.sent();
588
+ expect(cacheResult === null || cacheResult === void 0 ? void 0 : cacheResult.content).toBe(content);
589
+ _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;
590
+ _state.label = 5;
591
+ case 5:
592
+ _state.trys.push([
593
+ 5,
594
+ 10,
595
+ 11,
596
+ 12
597
+ ]);
598
+ _iterator1 = other[Symbol.iterator]();
599
+ _state.label = 6;
600
+ case 6:
601
+ if (!!(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done))
602
+ return [
603
+ 3,
604
+ 9
605
+ ];
606
+ notMatch = _step1.value;
607
+ notMatchContext = {
608
+ entry: "",
609
+ pathname: notMatch.url,
610
+ query: notMatch.query,
611
+ headers: notMatch.headers
612
+ };
613
+ return [
614
+ 4,
615
+ cache.get(notMatchContext)
616
+ ];
617
+ case 7:
618
+ nothing = _state.sent();
619
+ expect(nothing).toBe(null);
620
+ _state.label = 8;
621
+ case 8:
622
+ _iteratorNormalCompletion1 = true;
623
+ return [
624
+ 3,
625
+ 6
626
+ ];
627
+ case 9:
628
+ return [
629
+ 3,
630
+ 12
631
+ ];
632
+ case 10:
633
+ err = _state.sent();
634
+ _didIteratorError1 = true;
635
+ _iteratorError1 = err;
636
+ return [
637
+ 3,
638
+ 12
639
+ ];
640
+ case 11:
641
+ try {
642
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
643
+ _iterator1.return();
516
644
  }
517
- });
518
- }));
519
- it("should match cache correctly", /*#__PURE__*/ _asyncToGenerator(function() {
520
- var cache, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, cacheable, _cacheable, baseCacheable, matchOne, other, _baseCacheable_requestOpt, requestOpt, cacheConfig, content, context, matchContext, cacheResult, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, notMatch, notMatchContext, nothing, err, err;
521
- return __generator(this, function(_state) {
522
- switch(_state.label){
523
- case 0:
524
- destroyCache();
525
- cache = createCache();
526
- _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
527
- _state.label = 1;
528
- case 1:
529
- _state.trys.push([
530
- 1,
531
- 14,
532
- 15,
533
- 16
534
- ]);
535
- _iterator = matchedCacheableAry[Symbol.iterator]();
536
- _state.label = 2;
537
- case 2:
538
- if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
539
- 3,
540
- 13
541
- ];
542
- cacheable = _step.value;
543
- _cacheable = _toArray(cacheable), baseCacheable = _cacheable[0], matchOne = _cacheable[1], other = _cacheable.slice(2);
544
- _baseCacheable_requestOpt = baseCacheable.requestOpt, requestOpt = _baseCacheable_requestOpt === void 0 ? {} : _baseCacheable_requestOpt, cacheConfig = baseCacheable.cacheConfig, content = baseCacheable.content;
545
- context = {
546
- entry: "",
547
- pathname: requestOpt.url,
548
- query: requestOpt.query,
549
- headers: requestOpt.headers
550
- };
551
- return [
552
- 4,
553
- cache.set(context, content, createCacheConfig(cacheConfig), true)
554
- ];
555
- case 3:
556
- _state.sent();
557
- matchContext = {
558
- entry: "",
559
- pathname: matchOne.url,
560
- query: matchOne.query,
561
- headers: matchOne.headers
562
- };
563
- return [
564
- 4,
565
- cache.get(matchContext)
566
- ];
567
- case 4:
568
- cacheResult = _state.sent();
569
- expect(cacheResult === null || cacheResult === void 0 ? void 0 : cacheResult.content).toBe(content);
570
- _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
571
- _state.label = 5;
572
- case 5:
573
- _state.trys.push([
574
- 5,
575
- 10,
576
- 11,
577
- 12
578
- ]);
579
- _iterator1 = other[Symbol.iterator]();
580
- _state.label = 6;
581
- case 6:
582
- if (!!(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done)) return [
583
- 3,
584
- 9
585
- ];
586
- notMatch = _step1.value;
587
- notMatchContext = {
588
- entry: "",
589
- pathname: notMatch.url,
590
- query: notMatch.query,
591
- headers: notMatch.headers
592
- };
593
- return [
594
- 4,
595
- cache.get(notMatchContext)
596
- ];
597
- case 7:
598
- nothing = _state.sent();
599
- expect(nothing).toBe(null);
600
- _state.label = 8;
601
- case 8:
602
- _iteratorNormalCompletion1 = true;
603
- return [
604
- 3,
605
- 6
606
- ];
607
- case 9:
608
- return [
609
- 3,
610
- 12
611
- ];
612
- case 10:
613
- err = _state.sent();
614
- _didIteratorError1 = true;
615
- _iteratorError1 = err;
616
- return [
617
- 3,
618
- 12
619
- ];
620
- case 11:
621
- try {
622
- if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
623
- _iterator1.return();
624
- }
625
- } finally{
626
- if (_didIteratorError1) {
627
- throw _iteratorError1;
628
- }
629
- }
630
- return [
631
- 7
632
- ];
633
- case 12:
634
- _iteratorNormalCompletion = true;
635
- return [
636
- 3,
637
- 2
638
- ];
639
- case 13:
640
- return [
641
- 3,
642
- 16
643
- ];
644
- case 14:
645
- err = _state.sent();
646
- _didIteratorError = true;
647
- _iteratorError = err;
648
- return [
649
- 3,
650
- 16
651
- ];
652
- case 15:
653
- try {
654
- if (!_iteratorNormalCompletion && _iterator.return != null) {
655
- _iterator.return();
656
- }
657
- } finally{
658
- if (_didIteratorError) {
659
- throw _iteratorError;
660
- }
661
- }
662
- return [
663
- 7
664
- ];
665
- case 16:
666
- return [
667
- 2
668
- ];
645
+ } finally {
646
+ if (_didIteratorError1) {
647
+ throw _iteratorError1;
669
648
  }
670
- });
671
- }));
672
- it("should stale cache correctly", /*#__PURE__*/ _asyncToGenerator(function() {
673
- var cache, context, config, content, shouldCache, freshResult, staleResult;
674
- return __generator(this, function(_state) {
675
- switch(_state.label){
676
- case 0:
677
- destroyCache();
678
- cache = createCache();
679
- context = {
680
- entry: "",
681
- pathname: "",
682
- query: {},
683
- headers: {}
684
- };
685
- config = createCacheConfig({
686
- interval: 5
687
- });
688
- content = "hello";
689
- return [
690
- 4,
691
- cache.set(context, content, config, true)
692
- ];
693
- case 1:
694
- shouldCache = _state.sent();
695
- expect(shouldCache.value).toBe(true);
696
- return [
697
- 4,
698
- cache.get(context)
699
- ];
700
- case 2:
701
- freshResult = _state.sent();
702
- expect(freshResult === null || freshResult === void 0 ? void 0 : freshResult.isStale).toBe(false);
703
- return [
704
- 4,
705
- new Promise(function(resolve) {
706
- setTimeout(function() {
707
- resolve();
708
- }, 6e3);
709
- })
710
- ];
711
- case 3:
712
- _state.sent();
713
- return [
714
- 4,
715
- cache.get(context)
716
- ];
717
- case 4:
718
- staleResult = _state.sent();
719
- expect(staleResult === null || staleResult === void 0 ? void 0 : staleResult.isStale).toBe(true);
720
- return [
721
- 2
722
- ];
649
+ }
650
+ return [
651
+ 7
652
+ ];
653
+ case 12:
654
+ _iteratorNormalCompletion = true;
655
+ return [
656
+ 3,
657
+ 2
658
+ ];
659
+ case 13:
660
+ return [
661
+ 3,
662
+ 16
663
+ ];
664
+ case 14:
665
+ err = _state.sent();
666
+ _didIteratorError = true;
667
+ _iteratorError = err;
668
+ return [
669
+ 3,
670
+ 16
671
+ ];
672
+ case 15:
673
+ try {
674
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
675
+ _iterator.return();
723
676
  }
724
- });
725
- }));
726
- it("should garbage cache correctly", /*#__PURE__*/ _asyncToGenerator(function() {
727
- var cache, context, config, content, shouldCache, freshResult, staleResult;
728
- return __generator(this, function(_state) {
729
- switch(_state.label){
730
- case 0:
731
- destroyCache();
732
- cache = createCache();
733
- context = {
734
- entry: "",
735
- pathname: "",
736
- query: {},
737
- headers: {}
738
- };
739
- config = createCacheConfig({
740
- interval: 3,
741
- staleLimit: 8
742
- });
743
- content = "hello";
744
- return [
745
- 4,
746
- cache.set(context, content, config, true)
747
- ];
748
- case 1:
749
- shouldCache = _state.sent();
750
- expect(shouldCache.value).toBe(true);
751
- return [
752
- 4,
753
- cache.get(context)
754
- ];
755
- case 2:
756
- freshResult = _state.sent();
757
- expect(freshResult === null || freshResult === void 0 ? void 0 : freshResult.isGarbage).toBe(false);
758
- return [
759
- 4,
760
- new Promise(function(resolve) {
761
- setTimeout(function() {
762
- resolve();
763
- }, 1e4);
764
- })
765
- ];
766
- case 3:
767
- _state.sent();
768
- return [
769
- 4,
770
- cache.get(context)
771
- ];
772
- case 4:
773
- staleResult = _state.sent();
774
- expect(staleResult === null || staleResult === void 0 ? void 0 : staleResult.isGarbage).toBe(true);
775
- return [
776
- 2
777
- ];
677
+ } finally {
678
+ if (_didIteratorError) {
679
+ throw _iteratorError;
778
680
  }
779
- });
780
- }));
681
+ }
682
+ return [
683
+ 7
684
+ ];
685
+ case 16:
686
+ return [
687
+ 2
688
+ ];
689
+ }
690
+ });
691
+ }));
692
+ it("should stale cache correctly", /* @__PURE__ */ _async_to_generator(function() {
693
+ var cache, context, config, content, shouldCache, freshResult, staleResult;
694
+ return __generator(this, function(_state) {
695
+ switch (_state.label) {
696
+ case 0:
697
+ destroyCache();
698
+ cache = createCache();
699
+ context = {
700
+ entry: "",
701
+ pathname: "",
702
+ query: {},
703
+ headers: {}
704
+ };
705
+ config = createCacheConfig({
706
+ interval: 5
707
+ });
708
+ content = "hello";
709
+ return [
710
+ 4,
711
+ cache.set(context, content, config, true)
712
+ ];
713
+ case 1:
714
+ shouldCache = _state.sent();
715
+ expect(shouldCache.value).toBe(true);
716
+ return [
717
+ 4,
718
+ cache.get(context)
719
+ ];
720
+ case 2:
721
+ freshResult = _state.sent();
722
+ expect(freshResult === null || freshResult === void 0 ? void 0 : freshResult.isStale).toBe(false);
723
+ return [
724
+ 4,
725
+ new Promise(function(resolve) {
726
+ setTimeout(function() {
727
+ resolve();
728
+ }, 6e3);
729
+ })
730
+ ];
731
+ case 3:
732
+ _state.sent();
733
+ return [
734
+ 4,
735
+ cache.get(context)
736
+ ];
737
+ case 4:
738
+ staleResult = _state.sent();
739
+ expect(staleResult === null || staleResult === void 0 ? void 0 : staleResult.isStale).toBe(true);
740
+ return [
741
+ 2
742
+ ];
743
+ }
744
+ });
745
+ }));
746
+ it("should garbage cache correctly", /* @__PURE__ */ _async_to_generator(function() {
747
+ var cache, context, config, content, shouldCache, freshResult, staleResult;
748
+ return __generator(this, function(_state) {
749
+ switch (_state.label) {
750
+ case 0:
751
+ destroyCache();
752
+ cache = createCache();
753
+ context = {
754
+ entry: "",
755
+ pathname: "",
756
+ query: {},
757
+ headers: {}
758
+ };
759
+ config = createCacheConfig({
760
+ interval: 3,
761
+ staleLimit: 8
762
+ });
763
+ content = "hello";
764
+ return [
765
+ 4,
766
+ cache.set(context, content, config, true)
767
+ ];
768
+ case 1:
769
+ shouldCache = _state.sent();
770
+ expect(shouldCache.value).toBe(true);
771
+ return [
772
+ 4,
773
+ cache.get(context)
774
+ ];
775
+ case 2:
776
+ freshResult = _state.sent();
777
+ expect(freshResult === null || freshResult === void 0 ? void 0 : freshResult.isGarbage).toBe(false);
778
+ return [
779
+ 4,
780
+ new Promise(function(resolve) {
781
+ setTimeout(function() {
782
+ resolve();
783
+ }, 1e4);
784
+ })
785
+ ];
786
+ case 3:
787
+ _state.sent();
788
+ return [
789
+ 4,
790
+ cache.get(context)
791
+ ];
792
+ case 4:
793
+ staleResult = _state.sent();
794
+ expect(staleResult === null || staleResult === void 0 ? void 0 : staleResult.isGarbage).toBe(true);
795
+ return [
796
+ 2
797
+ ];
798
+ }
799
+ });
800
+ }));
781
801
  });