@modern-js/prod-server 2.9.1-alpha.0 → 2.11.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 (139) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/dist/cjs/libs/hook-api/index.js +7 -26
  3. package/dist/cjs/libs/render/index.js +2 -1
  4. package/dist/cjs/libs/render/ssr.js +7 -5
  5. package/dist/{js/node/libs/metrics.js → cjs/libs/render/utils.js} +25 -12
  6. package/dist/cjs/server/index.js +1 -1
  7. package/dist/cjs/server/modernServer.js +75 -80
  8. package/dist/esm/libs/hook-api/index.js +9 -37
  9. package/dist/esm/libs/render/index.js +2 -1
  10. package/dist/esm/libs/render/ssr.js +6 -4
  11. package/dist/esm/libs/render/utils.js +12 -0
  12. package/dist/esm/server/index.js +2 -2
  13. package/dist/esm/server/modernServer.js +108 -103
  14. package/dist/esm-node/libs/hook-api/index.js +7 -26
  15. package/dist/esm-node/libs/render/index.js +2 -1
  16. package/dist/esm-node/libs/render/ssr.js +7 -7
  17. package/dist/esm-node/libs/render/utils.js +23 -0
  18. package/dist/esm-node/server/index.js +1 -1
  19. package/dist/esm-node/server/modernServer.js +75 -80
  20. package/dist/types/libs/context/context.d.ts +1 -1
  21. package/dist/types/libs/render/utils.d.ts +5 -0
  22. package/dist/types/server/index.d.ts +2 -1
  23. package/dist/types/server/modernServer.d.ts +4 -4
  24. package/dist/types/type.d.ts +1 -1
  25. package/dist/types/utils.d.ts +1 -1
  26. package/package.json +9 -7
  27. package/dist/js/modern/constants.js +0 -35
  28. package/dist/js/modern/index.js +0 -18
  29. package/dist/js/modern/libs/context/context.js +0 -160
  30. package/dist/js/modern/libs/context/index.js +0 -6
  31. package/dist/js/modern/libs/hook-api/index.js +0 -134
  32. package/dist/js/modern/libs/hook-api/route.js +0 -20
  33. package/dist/js/modern/libs/hook-api/template.js +0 -73
  34. package/dist/js/modern/libs/loadConfig.js +0 -62
  35. package/dist/js/modern/libs/logger.js +0 -111
  36. package/dist/js/modern/libs/metrics.js +0 -11
  37. package/dist/js/modern/libs/proxy.js +0 -92
  38. package/dist/js/modern/libs/render/cache/__tests__/cache.fun.test.js +0 -114
  39. package/dist/js/modern/libs/render/cache/__tests__/cache.test.js +0 -254
  40. package/dist/js/modern/libs/render/cache/__tests__/cacheable.js +0 -47
  41. package/dist/js/modern/libs/render/cache/__tests__/error-configuration.js +0 -37
  42. package/dist/js/modern/libs/render/cache/__tests__/matched-cache.js +0 -91
  43. package/dist/js/modern/libs/render/cache/index.js +0 -115
  44. package/dist/js/modern/libs/render/cache/page-caches/index.js +0 -32
  45. package/dist/js/modern/libs/render/cache/page-caches/lru.js +0 -29
  46. package/dist/js/modern/libs/render/cache/spr.js +0 -248
  47. package/dist/js/modern/libs/render/cache/type.js +0 -0
  48. package/dist/js/modern/libs/render/cache/util.js +0 -102
  49. package/dist/js/modern/libs/render/index.js +0 -86
  50. package/dist/js/modern/libs/render/measure.js +0 -68
  51. package/dist/js/modern/libs/render/reader.js +0 -107
  52. package/dist/js/modern/libs/render/ssr.js +0 -100
  53. package/dist/js/modern/libs/render/static.js +0 -60
  54. package/dist/js/modern/libs/render/type.js +0 -9
  55. package/dist/js/modern/libs/route/index.js +0 -54
  56. package/dist/js/modern/libs/route/matcher.js +0 -87
  57. package/dist/js/modern/libs/route/route.js +0 -16
  58. package/dist/js/modern/libs/serve-file.js +0 -67
  59. package/dist/js/modern/server/index.js +0 -208
  60. package/dist/js/modern/server/modern-server-split.js +0 -74
  61. package/dist/js/modern/server/modern-server.js +0 -554
  62. package/dist/js/modern/type.js +0 -0
  63. package/dist/js/modern/utils.js +0 -136
  64. package/dist/js/modern/worker-server.js +0 -89
  65. package/dist/js/node/constants.js +0 -62
  66. package/dist/js/node/index.js +0 -44
  67. package/dist/js/node/libs/context/context.js +0 -189
  68. package/dist/js/node/libs/context/index.js +0 -30
  69. package/dist/js/node/libs/hook-api/index.js +0 -164
  70. package/dist/js/node/libs/hook-api/route.js +0 -43
  71. package/dist/js/node/libs/hook-api/template.js +0 -97
  72. package/dist/js/node/libs/loadConfig.js +0 -91
  73. package/dist/js/node/libs/logger.js +0 -133
  74. package/dist/js/node/libs/proxy.js +0 -114
  75. package/dist/js/node/libs/render/cache/__tests__/cache.fun.test.js +0 -115
  76. package/dist/js/node/libs/render/cache/__tests__/cache.test.js +0 -245
  77. package/dist/js/node/libs/render/cache/__tests__/cacheable.js +0 -70
  78. package/dist/js/node/libs/render/cache/__tests__/error-configuration.js +0 -60
  79. package/dist/js/node/libs/render/cache/__tests__/matched-cache.js +0 -114
  80. package/dist/js/node/libs/render/cache/index.js +0 -134
  81. package/dist/js/node/libs/render/cache/page-caches/index.js +0 -55
  82. package/dist/js/node/libs/render/cache/page-caches/lru.js +0 -58
  83. package/dist/js/node/libs/render/cache/spr.js +0 -270
  84. package/dist/js/node/libs/render/cache/type.js +0 -15
  85. package/dist/js/node/libs/render/cache/util.js +0 -138
  86. package/dist/js/node/libs/render/index.js +0 -115
  87. package/dist/js/node/libs/render/measure.js +0 -90
  88. package/dist/js/node/libs/render/reader.js +0 -140
  89. package/dist/js/node/libs/render/ssr.js +0 -123
  90. package/dist/js/node/libs/render/static.js +0 -89
  91. package/dist/js/node/libs/render/type.js +0 -32
  92. package/dist/js/node/libs/route/index.js +0 -78
  93. package/dist/js/node/libs/route/matcher.js +0 -106
  94. package/dist/js/node/libs/route/route.js +0 -39
  95. package/dist/js/node/libs/serve-file.js +0 -97
  96. package/dist/js/node/server/index.js +0 -219
  97. package/dist/js/node/server/modern-server-split.js +0 -97
  98. package/dist/js/node/server/modern-server.js +0 -559
  99. package/dist/js/node/type.js +0 -15
  100. package/dist/js/node/utils.js +0 -166
  101. package/dist/js/node/worker-server.js +0 -113
  102. package/dist/js/treeshaking/constants.js +0 -29
  103. package/dist/js/treeshaking/index.js +0 -13
  104. package/dist/js/treeshaking/libs/context/context.js +0 -274
  105. package/dist/js/treeshaking/libs/context/index.js +0 -5
  106. package/dist/js/treeshaking/libs/hook-api/index.js +0 -281
  107. package/dist/js/treeshaking/libs/hook-api/route.js +0 -68
  108. package/dist/js/treeshaking/libs/hook-api/template.js +0 -127
  109. package/dist/js/treeshaking/libs/loadConfig.js +0 -82
  110. package/dist/js/treeshaking/libs/logger.js +0 -205
  111. package/dist/js/treeshaking/libs/metrics.js +0 -6
  112. package/dist/js/treeshaking/libs/proxy.js +0 -244
  113. package/dist/js/treeshaking/libs/render/cache/__tests__/cache.fun.test.js +0 -291
  114. package/dist/js/treeshaking/libs/render/cache/__tests__/cache.test.js +0 -781
  115. package/dist/js/treeshaking/libs/render/cache/__tests__/cacheable.js +0 -67
  116. package/dist/js/treeshaking/libs/render/cache/__tests__/error-configuration.js +0 -45
  117. package/dist/js/treeshaking/libs/render/cache/__tests__/matched-cache.js +0 -147
  118. package/dist/js/treeshaking/libs/render/cache/index.js +0 -346
  119. package/dist/js/treeshaking/libs/render/cache/page-caches/index.js +0 -154
  120. package/dist/js/treeshaking/libs/render/cache/page-caches/lru.js +0 -84
  121. package/dist/js/treeshaking/libs/render/cache/spr.js +0 -492
  122. package/dist/js/treeshaking/libs/render/cache/type.js +0 -1
  123. package/dist/js/treeshaking/libs/render/cache/util.js +0 -280
  124. package/dist/js/treeshaking/libs/render/index.js +0 -234
  125. package/dist/js/treeshaking/libs/render/measure.js +0 -146
  126. package/dist/js/treeshaking/libs/render/reader.js +0 -339
  127. package/dist/js/treeshaking/libs/render/ssr.js +0 -223
  128. package/dist/js/treeshaking/libs/render/static.js +0 -216
  129. package/dist/js/treeshaking/libs/render/type.js +0 -7
  130. package/dist/js/treeshaking/libs/route/index.js +0 -130
  131. package/dist/js/treeshaking/libs/route/matcher.js +0 -143
  132. package/dist/js/treeshaking/libs/route/route.js +0 -40
  133. package/dist/js/treeshaking/libs/serve-file.js +0 -184
  134. package/dist/js/treeshaking/server/index.js +0 -505
  135. package/dist/js/treeshaking/server/modern-server-split.js +0 -360
  136. package/dist/js/treeshaking/server/modern-server.js +0 -1089
  137. package/dist/js/treeshaking/type.js +0 -1
  138. package/dist/js/treeshaking/utils.js +0 -147
  139. package/dist/js/treeshaking/worker-server.js +0 -233
@@ -1,781 +0,0 @@
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;
5
- }
6
- function _arrayWithHoles(arr) {
7
- if (Array.isArray(arr)) return arr;
8
- }
9
- 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
- }
22
- }
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
- };
37
- }
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;
50
- }
51
- function _iterableToArray(iter) {
52
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
53
- }
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.");
56
- }
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
- });
69
- }
70
- return target;
71
- }
72
- function _toArray(arr) {
73
- return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest();
74
- }
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);
82
- }
83
- 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: []
92
- };
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) {
163
- op = [
164
- 6,
165
- e
166
- ];
167
- y = 0;
168
- } finally{
169
- f = t = 0;
170
- }
171
- if (op[0] & 5) throw op[1];
172
- return {
173
- value: op[0] ? op[1] : void 0,
174
- done: true
175
- };
176
- }
177
- };
178
- import { createCache, destroyCache } from "../spr";
179
- import { errorConfiguration } from "./error-configuration";
180
- import { cacheabelAry } from "./cacheable";
181
- import { matchedCacheableAry } from "./matched-cache";
182
- 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);
193
- };
194
- jest.setTimeout(6e4);
195
- 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
- ];
228
- }
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
- ];
256
- }
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
- ];
336
- }
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
- ];
383
- }
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
- ];
432
- }
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
- ];
516
- }
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
- ];
669
- }
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
- ];
723
- }
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
- ];
778
- }
779
- });
780
- }));
781
- });