@modern-js/prod-server 2.0.0-beta.3 → 2.0.0-beta.6

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 (130) hide show
  1. package/CHANGELOG.md +139 -0
  2. package/dist/js/modern/constants.js +32 -25
  3. package/dist/js/modern/index.js +11 -6
  4. package/dist/js/modern/libs/context/context.js +52 -84
  5. package/dist/js/modern/libs/context/index.js +5 -2
  6. package/dist/js/modern/libs/hook-api/index.js +44 -35
  7. package/dist/js/modern/libs/hook-api/route.js +6 -7
  8. package/dist/js/modern/libs/hook-api/template.js +20 -34
  9. package/dist/js/modern/libs/loadConfig.js +45 -24
  10. package/dist/js/modern/libs/metrics.js +3 -4
  11. package/dist/js/modern/libs/proxy.js +68 -37
  12. package/dist/js/modern/libs/render/cache/__tests__/cache.fun.test.js +112 -67
  13. package/dist/js/modern/libs/render/cache/__tests__/cache.test.js +246 -216
  14. package/dist/js/modern/libs/render/cache/__tests__/cacheable.js +43 -49
  15. package/dist/js/modern/libs/render/cache/__tests__/error-configuration.js +36 -34
  16. package/dist/js/modern/libs/render/cache/__tests__/matched-cache.js +83 -113
  17. package/dist/js/modern/libs/render/cache/index.js +88 -54
  18. package/dist/js/modern/libs/render/cache/page-caches/index.js +31 -8
  19. package/dist/js/modern/libs/render/cache/page-caches/lru.js +6 -6
  20. package/dist/js/modern/libs/render/cache/spr.js +133 -117
  21. package/dist/js/modern/libs/render/cache/type.js +0 -1
  22. package/dist/js/modern/libs/render/cache/util.js +71 -39
  23. package/dist/js/modern/libs/render/index.js +76 -56
  24. package/dist/js/modern/libs/render/measure.js +38 -27
  25. package/dist/js/modern/libs/render/reader.js +65 -62
  26. package/dist/js/modern/libs/render/ssr.js +50 -32
  27. package/dist/js/modern/libs/render/static.js +50 -33
  28. package/dist/js/modern/libs/render/type.js +9 -6
  29. package/dist/js/modern/libs/route/index.js +8 -15
  30. package/dist/js/modern/libs/route/matcher.js +20 -34
  31. package/dist/js/modern/libs/route/route.js +9 -18
  32. package/dist/js/modern/libs/serve-file.js +33 -20
  33. package/dist/js/modern/server/index.js +150 -145
  34. package/dist/js/modern/server/modern-server-split.js +46 -12
  35. package/dist/js/modern/server/modern-server.js +384 -422
  36. package/dist/js/modern/type.js +0 -1
  37. package/dist/js/modern/utils.js +62 -43
  38. package/dist/js/modern/worker-server.js +34 -14
  39. package/dist/js/node/constants.js +53 -30
  40. package/dist/js/node/index.js +37 -57
  41. package/dist/js/node/libs/context/context.js +83 -94
  42. package/dist/js/node/libs/context/index.js +28 -13
  43. package/dist/js/node/libs/hook-api/index.js +76 -48
  44. package/dist/js/node/libs/hook-api/route.js +26 -11
  45. package/dist/js/node/libs/hook-api/template.js +41 -39
  46. package/dist/js/node/libs/loadConfig.js +73 -35
  47. package/dist/js/node/libs/metrics.js +25 -9
  48. package/dist/js/node/libs/proxy.js +89 -44
  49. package/dist/js/node/libs/render/cache/__tests__/cache.fun.test.js +99 -56
  50. package/dist/js/node/libs/render/cache/__tests__/cache.test.js +147 -128
  51. package/dist/js/node/libs/render/cache/__tests__/cacheable.js +65 -55
  52. package/dist/js/node/libs/render/cache/__tests__/error-configuration.js +58 -40
  53. package/dist/js/node/libs/render/cache/__tests__/matched-cache.js +105 -119
  54. package/dist/js/node/libs/render/cache/index.js +110 -64
  55. package/dist/js/node/libs/render/cache/page-caches/index.js +54 -14
  56. package/dist/js/node/libs/render/cache/page-caches/lru.js +33 -12
  57. package/dist/js/node/libs/render/cache/spr.js +161 -129
  58. package/dist/js/node/libs/render/cache/type.js +15 -5
  59. package/dist/js/node/libs/render/cache/util.js +99 -45
  60. package/dist/js/node/libs/render/index.js +106 -67
  61. package/dist/js/node/libs/render/measure.js +58 -31
  62. package/dist/js/node/libs/render/reader.js +95 -70
  63. package/dist/js/node/libs/render/ssr.js +80 -47
  64. package/dist/js/node/libs/render/static.js +79 -40
  65. package/dist/js/node/libs/render/type.js +31 -12
  66. package/dist/js/node/libs/route/index.js +31 -26
  67. package/dist/js/node/libs/route/matcher.js +40 -41
  68. package/dist/js/node/libs/route/route.js +29 -22
  69. package/dist/js/node/libs/serve-file.js +66 -32
  70. package/dist/js/node/server/index.js +168 -160
  71. package/dist/js/node/server/modern-server-split.js +72 -22
  72. package/dist/js/node/server/modern-server.js +403 -445
  73. package/dist/js/node/type.js +15 -3
  74. package/dist/js/node/utils.js +85 -52
  75. package/dist/js/node/worker-server.js +57 -21
  76. package/dist/js/treeshaking/constants.js +26 -25
  77. package/dist/js/treeshaking/index.js +10 -10
  78. package/dist/js/treeshaking/libs/context/context.js +268 -237
  79. package/dist/js/treeshaking/libs/context/index.js +3 -3
  80. package/dist/js/treeshaking/libs/hook-api/index.js +267 -143
  81. package/dist/js/treeshaking/libs/hook-api/route.js +65 -30
  82. package/dist/js/treeshaking/libs/hook-api/template.js +121 -85
  83. package/dist/js/treeshaking/libs/loadConfig.js +80 -37
  84. package/dist/js/treeshaking/libs/metrics.js +4 -10
  85. package/dist/js/treeshaking/libs/proxy.js +240 -76
  86. package/dist/js/treeshaking/libs/render/cache/__tests__/cache.fun.test.js +288 -121
  87. package/dist/js/treeshaking/libs/render/cache/__tests__/cache.test.js +772 -455
  88. package/dist/js/treeshaking/libs/render/cache/__tests__/cacheable.js +65 -51
  89. package/dist/js/treeshaking/libs/render/cache/__tests__/error-configuration.js +45 -35
  90. package/dist/js/treeshaking/libs/render/cache/__tests__/matched-cache.js +144 -118
  91. package/dist/js/treeshaking/libs/render/cache/index.js +337 -175
  92. package/dist/js/treeshaking/libs/render/cache/page-caches/index.js +151 -27
  93. package/dist/js/treeshaking/libs/render/cache/page-caches/lru.js +80 -42
  94. package/dist/js/treeshaking/libs/render/cache/spr.js +470 -340
  95. package/dist/js/treeshaking/libs/render/cache/type.js +1 -1
  96. package/dist/js/treeshaking/libs/render/cache/util.js +271 -92
  97. package/dist/js/treeshaking/libs/render/index.js +228 -95
  98. package/dist/js/treeshaking/libs/render/measure.js +142 -57
  99. package/dist/js/treeshaking/libs/render/reader.js +325 -177
  100. package/dist/js/treeshaking/libs/render/ssr.js +220 -95
  101. package/dist/js/treeshaking/libs/render/static.js +210 -78
  102. package/dist/js/treeshaking/libs/render/type.js +7 -6
  103. package/dist/js/treeshaking/libs/route/index.js +125 -89
  104. package/dist/js/treeshaking/libs/route/matcher.js +132 -107
  105. package/dist/js/treeshaking/libs/route/route.js +40 -26
  106. package/dist/js/treeshaking/libs/serve-file.js +177 -68
  107. package/dist/js/treeshaking/server/index.js +493 -327
  108. package/dist/js/treeshaking/server/modern-server-split.js +352 -144
  109. package/dist/js/treeshaking/server/modern-server.js +1048 -909
  110. package/dist/js/treeshaking/type.js +1 -1
  111. package/dist/js/treeshaking/utils.js +138 -81
  112. package/dist/js/treeshaking/worker-server.js +176 -55
  113. package/dist/types/index.d.ts +2 -0
  114. package/dist/types/libs/context/context.d.ts +4 -1
  115. package/dist/types/libs/loadConfig.d.ts +1 -0
  116. package/dist/types/libs/render/cache/index.d.ts +2 -0
  117. package/dist/types/libs/render/cache/spr.d.ts +2 -0
  118. package/dist/types/libs/route/route.d.ts +0 -1
  119. package/dist/types/server/index.d.ts +3 -0
  120. package/dist/types/utils.d.ts +1 -1
  121. package/dist/types/worker-server.d.ts +1 -2
  122. package/package.json +7 -14
  123. package/dist/js/modern/libs/render/modern/browser-list.js +0 -7
  124. package/dist/js/modern/libs/render/modern/index.js +0 -37
  125. package/dist/js/node/libs/render/modern/browser-list.js +0 -14
  126. package/dist/js/node/libs/render/modern/index.js +0 -46
  127. package/dist/js/treeshaking/libs/render/modern/browser-list.js +0 -7
  128. package/dist/js/treeshaking/libs/render/modern/index.js +0 -39
  129. package/dist/types/libs/render/modern/browser-list.d.ts +0 -1
  130. package/dist/types/libs/render/modern/index.d.ts +0 -3
@@ -1,224 +1,254 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
3
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
- import { createCache, destroyCache } from "../spr";
5
- import { errorConfiguration } from "./error-configuration";
6
- import { cacheabelAry } from "./cacheable";
7
- import { matchedCacheableAry } from "./matched-cache";
8
- const createCacheConfig = (config = {}) => _objectSpread({
9
- excludes: null,
10
- includes: null,
11
- interval: 10,
12
- staleLimit: false,
13
- level: 0,
14
- fallback: false,
15
- matches: null
16
- }, config);
17
- jest.setTimeout(60000);
18
- describe('cache', () => {
19
- it('should cache correctly', async () => {
20
- destroyCache();
21
- const cache = createCache();
22
- const context = {
23
- entry: '',
24
- pathname: '',
25
- query: {},
26
- headers: {}
27
- };
28
- const content = 'hello';
29
- const cacheConfig = createCacheConfig();
30
- await cache.set(context, content, cacheConfig, true);
31
- const cacheResult = await cache.get(context);
32
- expect(cacheResult).not.toBe(null);
33
- expect(cacheResult === null || cacheResult === void 0 ? void 0 : cacheResult.content).toBe('hello');
34
- });
35
- it('should ignore cache set when cache config not exist', async () => {
36
- destroyCache();
37
- destroyCache();
38
- const cache = createCache();
39
- const context = {
40
- entry: '',
41
- pathname: '',
42
- query: {},
43
- headers: {}
44
- };
45
- const content = 'hello';
46
- const shouldCache = await cache.set(context, content, null, true);
47
- expect(shouldCache).toBe(false);
48
- });
49
- it('should calcual cache key error', async () => {
50
- destroyCache();
51
- const cache = createCache();
52
- const content = 'hello';
53
- for (const config of errorConfiguration) {
54
- const cacheConfig = createCacheConfig(config);
55
- const tmpEntry = Math.random().toString();
56
- const context = {
57
- entry: tmpEntry,
58
- pathname: '',
59
- query: {},
60
- headers: {}
61
- };
62
- const shouldCache = await cache.set(context, content, cacheConfig);
63
- expect(shouldCache).toBe(false);
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
+ var __spreadValues = (a, b) => {
8
+ for (var prop in b || (b = {}))
9
+ if (__hasOwnProp.call(b, prop))
10
+ __defNormalProp(a, prop, b[prop]);
11
+ if (__getOwnPropSymbols)
12
+ for (var prop of __getOwnPropSymbols(b)) {
13
+ if (__propIsEnum.call(b, prop))
14
+ __defNormalProp(a, prop, b[prop]);
64
15
  }
65
- });
66
- it('should get nothing for diff requestKey', async () => {
67
- destroyCache();
68
- const cache = createCache();
69
- const context = {
70
- entry: '',
71
- pathname: '',
72
- query: {},
73
- headers: {}
74
- };
75
- const content = 'hello';
76
- const cacheConfig = createCacheConfig({
77
- level: 1,
78
- includes: {
79
- query: ['name']
16
+ return a;
17
+ };
18
+ var __commonJS = (cb, mod) => function __require() {
19
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
20
+ };
21
+ var __async = (__this, __arguments, generator) => {
22
+ return new Promise((resolve, reject) => {
23
+ var fulfilled = (value) => {
24
+ try {
25
+ step(generator.next(value));
26
+ } catch (e) {
27
+ reject(e);
80
28
  }
81
- });
82
- await cache.set(context, content, cacheConfig, true);
83
- const context_req = {
84
- entry: '',
85
- pathname: '/home',
86
- query: {},
87
- headers: {}
88
- };
89
- const cacheResult = await cache.get(context_req);
90
- expect(cacheResult).toBe(null);
91
- });
92
- it('should get nothing for diff cacheHash', async () => {
93
- destroyCache();
94
- const cache = createCache();
95
- const context = {
96
- entry: '',
97
- pathname: '',
98
- query: {},
99
- headers: {}
100
29
  };
101
- const content = 'hello';
102
- const cacheConfig = createCacheConfig({
103
- level: 1,
104
- includes: {
105
- query: ['name']
30
+ var rejected = (value) => {
31
+ try {
32
+ step(generator.throw(value));
33
+ } catch (e) {
34
+ reject(e);
106
35
  }
107
- });
108
- await cache.set(context, content, cacheConfig, true);
109
- const context_req = {
110
- entry: '',
111
- pathname: '',
112
- query: {
113
- name: 'zll'
114
- },
115
- headers: {}
116
36
  };
117
- const cacheResult = await cache.get(context_req);
118
- expect(cacheResult).toBe(null);
37
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
38
+ step((generator = generator.apply(__this, __arguments)).next());
119
39
  });
120
- it('should get cache correctly', async () => {
121
- destroyCache();
122
- const cache = createCache();
123
- for (const cacheable of cacheabelAry) {
124
- const context = {
125
- entry: '',
126
- pathname: cacheable.requestOpt.url,
127
- query: cacheable.requestOpt.query || {},
128
- headers: cacheable.requestOpt.headers || {}
129
- };
130
- const cacheConfig = createCacheConfig(cacheable.cacheConfig || {});
131
- await cache.set(context, cacheable.content, cacheConfig, true);
132
- const cacheResult = await cache.get(context);
133
- expect(cacheResult === null || cacheResult === void 0 ? void 0 : cacheResult.content).toBe(cacheable.content);
134
- }
135
- });
136
- it('should match cache correctly', async () => {
137
- destroyCache();
138
- const cache = createCache();
139
- for (const cacheable of matchedCacheableAry) {
140
- const [baseCacheable, matchOne, ...other] = cacheable;
141
- const {
142
- requestOpt = {},
143
- cacheConfig,
144
- content
145
- } = baseCacheable;
146
- const context = {
147
- entry: '',
148
- pathname: requestOpt.url,
149
- query: requestOpt.query,
150
- headers: requestOpt.headers
151
- };
152
- await cache.set(context, content, createCacheConfig(cacheConfig), true);
153
- const matchContext = {
154
- entry: '',
155
- pathname: matchOne.url,
156
- query: matchOne.query,
157
- headers: matchOne.headers
158
- };
159
- const cacheResult = await cache.get(matchContext);
160
- expect(cacheResult === null || cacheResult === void 0 ? void 0 : cacheResult.content).toBe(content);
161
- for (const notMatch of other) {
162
- const notMatchContext = {
163
- entry: '',
164
- pathname: notMatch.url,
165
- query: notMatch.query,
166
- headers: notMatch.headers
40
+ };
41
+ import { createCache, destroyCache } from "../spr";
42
+ import { errorConfiguration } from "./error-configuration";
43
+ import { cacheabelAry } from "./cacheable";
44
+ import { matchedCacheableAry } from "./matched-cache";
45
+ var require_cache_test = __commonJS({
46
+ "src/libs/render/cache/__tests__/cache.test.ts"(exports) {
47
+ const createCacheConfig = (config = {}) => __spreadValues({
48
+ excludes: null,
49
+ includes: null,
50
+ interval: 10,
51
+ staleLimit: false,
52
+ level: 0,
53
+ fallback: false,
54
+ matches: null
55
+ }, config);
56
+ jest.setTimeout(6e4);
57
+ describe("cache", () => {
58
+ it("should cache correctly", () => __async(exports, null, function* () {
59
+ destroyCache();
60
+ const cache = createCache();
61
+ const context = {
62
+ entry: "",
63
+ pathname: "",
64
+ query: {},
65
+ headers: {}
167
66
  };
168
- const nothing = await cache.get(notMatchContext);
169
- expect(nothing).toBe(null);
170
- }
171
- }
172
- });
173
- it('should stale cache correctly', async () => {
174
- destroyCache();
175
- const cache = createCache();
176
- const context = {
177
- entry: '',
178
- pathname: '',
179
- query: {},
180
- headers: {}
181
- };
182
- const config = createCacheConfig({
183
- interval: 5
184
- });
185
- const content = 'hello';
186
- const shouldCache = await cache.set(context, content, config, true);
187
- expect(shouldCache.value).toBe(true);
188
- const freshResult = await cache.get(context);
189
- expect(freshResult === null || freshResult === void 0 ? void 0 : freshResult.isStale).toBe(false);
190
- await new Promise(resolve => {
191
- setTimeout(() => {
192
- resolve();
193
- }, 6000);
194
- });
195
- const staleResult = await cache.get(context);
196
- expect(staleResult === null || staleResult === void 0 ? void 0 : staleResult.isStale).toBe(true);
197
- });
198
- it('should garbage cache correctly', async () => {
199
- destroyCache();
200
- const cache = createCache();
201
- const context = {
202
- entry: '',
203
- pathname: '',
204
- query: {},
205
- headers: {}
206
- };
207
- const config = createCacheConfig({
208
- interval: 3,
209
- staleLimit: 8
210
- });
211
- const content = 'hello';
212
- const shouldCache = await cache.set(context, content, config, true);
213
- expect(shouldCache.value).toBe(true);
214
- const freshResult = await cache.get(context);
215
- expect(freshResult === null || freshResult === void 0 ? void 0 : freshResult.isGarbage).toBe(false);
216
- await new Promise(resolve => {
217
- setTimeout(() => {
218
- resolve();
219
- }, 10000);
67
+ const content = "hello";
68
+ const cacheConfig = createCacheConfig();
69
+ yield cache.set(context, content, cacheConfig, true);
70
+ const cacheResult = yield cache.get(context);
71
+ expect(cacheResult).not.toBe(null);
72
+ expect(cacheResult == null ? void 0 : cacheResult.content).toBe("hello");
73
+ }));
74
+ it("should ignore cache set when cache config not exist", () => __async(exports, null, function* () {
75
+ destroyCache();
76
+ destroyCache();
77
+ const cache = createCache();
78
+ const context = {
79
+ entry: "",
80
+ pathname: "",
81
+ query: {},
82
+ headers: {}
83
+ };
84
+ const content = "hello";
85
+ const shouldCache = yield cache.set(context, content, null, true);
86
+ expect(shouldCache).toBe(false);
87
+ }));
88
+ it("should calcual cache key error", () => __async(exports, null, function* () {
89
+ destroyCache();
90
+ const cache = createCache();
91
+ const content = "hello";
92
+ for (const config of errorConfiguration) {
93
+ const cacheConfig = createCacheConfig(config);
94
+ const tmpEntry = Math.random().toString();
95
+ const context = {
96
+ entry: tmpEntry,
97
+ pathname: "",
98
+ query: {},
99
+ headers: {}
100
+ };
101
+ const shouldCache = yield cache.set(context, content, cacheConfig);
102
+ expect(shouldCache).toBe(false);
103
+ }
104
+ }));
105
+ it("should get nothing for diff requestKey", () => __async(exports, null, function* () {
106
+ destroyCache();
107
+ const cache = createCache();
108
+ const context = {
109
+ entry: "",
110
+ pathname: "",
111
+ query: {},
112
+ headers: {}
113
+ };
114
+ const content = "hello";
115
+ const cacheConfig = createCacheConfig({
116
+ level: 1,
117
+ includes: { query: ["name"] }
118
+ });
119
+ yield cache.set(context, content, cacheConfig, true);
120
+ const context_req = {
121
+ entry: "",
122
+ pathname: "/home",
123
+ query: {},
124
+ headers: {}
125
+ };
126
+ const cacheResult = yield cache.get(context_req);
127
+ expect(cacheResult).toBe(null);
128
+ }));
129
+ it("should get nothing for diff cacheHash", () => __async(exports, null, function* () {
130
+ destroyCache();
131
+ const cache = createCache();
132
+ const context = {
133
+ entry: "",
134
+ pathname: "",
135
+ query: {},
136
+ headers: {}
137
+ };
138
+ const content = "hello";
139
+ const cacheConfig = createCacheConfig({
140
+ level: 1,
141
+ includes: { query: ["name"] }
142
+ });
143
+ yield cache.set(context, content, cacheConfig, true);
144
+ const context_req = {
145
+ entry: "",
146
+ pathname: "",
147
+ query: { name: "zll" },
148
+ headers: {}
149
+ };
150
+ const cacheResult = yield cache.get(context_req);
151
+ expect(cacheResult).toBe(null);
152
+ }));
153
+ it("should get cache correctly", () => __async(exports, null, function* () {
154
+ destroyCache();
155
+ const cache = createCache();
156
+ for (const cacheable of cacheabelAry) {
157
+ const context = {
158
+ entry: "",
159
+ pathname: cacheable.requestOpt.url,
160
+ query: cacheable.requestOpt.query || {},
161
+ headers: cacheable.requestOpt.headers || {}
162
+ };
163
+ const cacheConfig = createCacheConfig(cacheable.cacheConfig || {});
164
+ yield cache.set(context, cacheable.content, cacheConfig, true);
165
+ const cacheResult = yield cache.get(context);
166
+ expect(cacheResult == null ? void 0 : cacheResult.content).toBe(cacheable.content);
167
+ }
168
+ }));
169
+ it("should match cache correctly", () => __async(exports, null, function* () {
170
+ destroyCache();
171
+ const cache = createCache();
172
+ for (const cacheable of matchedCacheableAry) {
173
+ const [baseCacheable, matchOne, ...other] = cacheable;
174
+ const { requestOpt = {}, cacheConfig, content } = baseCacheable;
175
+ const context = {
176
+ entry: "",
177
+ pathname: requestOpt.url,
178
+ query: requestOpt.query,
179
+ headers: requestOpt.headers
180
+ };
181
+ yield cache.set(context, content, createCacheConfig(cacheConfig), true);
182
+ const matchContext = {
183
+ entry: "",
184
+ pathname: matchOne.url,
185
+ query: matchOne.query,
186
+ headers: matchOne.headers
187
+ };
188
+ const cacheResult = yield cache.get(matchContext);
189
+ expect(cacheResult == null ? void 0 : cacheResult.content).toBe(content);
190
+ for (const notMatch of other) {
191
+ const notMatchContext = {
192
+ entry: "",
193
+ pathname: notMatch.url,
194
+ query: notMatch.query,
195
+ headers: notMatch.headers
196
+ };
197
+ const nothing = yield cache.get(notMatchContext);
198
+ expect(nothing).toBe(null);
199
+ }
200
+ }
201
+ }));
202
+ it("should stale cache correctly", () => __async(exports, null, function* () {
203
+ destroyCache();
204
+ const cache = createCache();
205
+ const context = {
206
+ entry: "",
207
+ pathname: "",
208
+ query: {},
209
+ headers: {}
210
+ };
211
+ const config = createCacheConfig({ interval: 5 });
212
+ const content = "hello";
213
+ const shouldCache = yield cache.set(context, content, config, true);
214
+ expect(shouldCache.value).toBe(true);
215
+ const freshResult = yield cache.get(context);
216
+ expect(freshResult == null ? void 0 : freshResult.isStale).toBe(false);
217
+ yield new Promise((resolve) => {
218
+ setTimeout(() => {
219
+ resolve();
220
+ }, 6e3);
221
+ });
222
+ const staleResult = yield cache.get(context);
223
+ expect(staleResult == null ? void 0 : staleResult.isStale).toBe(true);
224
+ }));
225
+ it("should garbage cache correctly", () => __async(exports, null, function* () {
226
+ destroyCache();
227
+ const cache = createCache();
228
+ const context = {
229
+ entry: "",
230
+ pathname: "",
231
+ query: {},
232
+ headers: {}
233
+ };
234
+ const config = createCacheConfig({
235
+ interval: 3,
236
+ staleLimit: 8
237
+ });
238
+ const content = "hello";
239
+ const shouldCache = yield cache.set(context, content, config, true);
240
+ expect(shouldCache.value).toBe(true);
241
+ const freshResult = yield cache.get(context);
242
+ expect(freshResult == null ? void 0 : freshResult.isGarbage).toBe(false);
243
+ yield new Promise((resolve) => {
244
+ setTimeout(() => {
245
+ resolve();
246
+ }, 1e4);
247
+ });
248
+ const staleResult = yield cache.get(context);
249
+ expect(staleResult == null ? void 0 : staleResult.isGarbage).toBe(true);
250
+ }));
220
251
  });
221
- const staleResult = await cache.get(context);
222
- expect(staleResult === null || staleResult === void 0 ? void 0 : staleResult.isGarbage).toBe(true);
223
- });
224
- });
252
+ }
253
+ });
254
+ export default require_cache_test();
@@ -1,53 +1,47 @@
1
- export const cacheabelAry = [{
2
- requestOpt: {
3
- url: '/'
1
+ const cacheabelAry = [
2
+ {
3
+ requestOpt: { url: "/" },
4
+ cacheConfig: {},
5
+ content: "level0"
4
6
  },
5
- cacheConfig: {},
6
- content: 'level0'
7
- }, {
8
- requestOpt: {
9
- url: '/level-one',
10
- query: {
11
- name: 'modern'
12
- }
13
- },
14
- cacheConfig: {
15
- level: 1,
16
- includes: {
17
- query: ['name']
18
- }
19
- },
20
- content: 'level1'
21
- }, {
22
- requestOpt: {
23
- url: '/level-two',
24
- headers: {
25
- age: '18'
26
- }
27
- },
28
- cacheConfig: {
29
- level: 2,
30
- includes: {
31
- header: ['age']
32
- }
33
- },
34
- content: 'level2'
35
- }, {
36
- requestOpt: {
37
- url: '/level-three',
38
- query: {
39
- name: 'modern'
7
+ {
8
+ requestOpt: {
9
+ url: "/level-one",
10
+ query: { name: "modern" }
11
+ },
12
+ cacheConfig: {
13
+ level: 1,
14
+ includes: { query: ["name"] }
40
15
  },
41
- headers: {
42
- age: '18'
43
- }
16
+ content: "level1"
44
17
  },
45
- cacheConfig: {
46
- level: 3,
47
- includes: {
48
- query: ['name'],
49
- header: ['age']
50
- }
18
+ {
19
+ requestOpt: {
20
+ url: "/level-two",
21
+ headers: { age: "18" }
22
+ },
23
+ cacheConfig: {
24
+ level: 2,
25
+ includes: { header: ["age"] }
26
+ },
27
+ content: "level2"
51
28
  },
52
- content: 'level3'
53
- }];
29
+ {
30
+ requestOpt: {
31
+ url: "/level-three",
32
+ query: { name: "modern" },
33
+ headers: { age: "18" }
34
+ },
35
+ cacheConfig: {
36
+ level: 3,
37
+ includes: {
38
+ query: ["name"],
39
+ header: ["age"]
40
+ }
41
+ },
42
+ content: "level3"
43
+ }
44
+ ];
45
+ export {
46
+ cacheabelAry
47
+ };
@@ -1,35 +1,37 @@
1
- export const errorConfiguration = [{
2
- level: 1
3
- }, {
4
- level: 1,
5
- includes: {}
6
- }, {
7
- level: 1,
8
- includes: {
9
- query: []
1
+ const errorConfiguration = [
2
+ { level: 1 },
3
+ {
4
+ level: 1,
5
+ includes: {}
6
+ },
7
+ {
8
+ level: 1,
9
+ includes: { query: [] }
10
+ },
11
+ {
12
+ level: 2,
13
+ includes: {}
14
+ },
15
+ {
16
+ level: 2,
17
+ includes: { header: [] }
18
+ },
19
+ {
20
+ level: 3,
21
+ includes: { header: [] }
22
+ },
23
+ {
24
+ level: 3,
25
+ includes: { query: [] }
26
+ },
27
+ {
28
+ level: 3,
29
+ includes: {
30
+ query: [],
31
+ header: []
32
+ }
10
33
  }
11
- }, {
12
- level: 2,
13
- includes: {}
14
- }, {
15
- level: 2,
16
- includes: {
17
- header: []
18
- }
19
- }, {
20
- level: 3,
21
- includes: {
22
- header: []
23
- }
24
- }, {
25
- level: 3,
26
- includes: {
27
- query: []
28
- }
29
- }, {
30
- level: 3,
31
- includes: {
32
- query: [],
33
- header: []
34
- }
35
- }];
34
+ ];
35
+ export {
36
+ errorConfiguration
37
+ };