@modern-js/prod-server 1.21.5 → 2.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +91 -10
- package/dist/js/modern/constants.js +0 -2
- package/dist/js/modern/index.js +0 -1
- package/dist/js/modern/libs/context/context.js +10 -56
- package/dist/js/modern/libs/hook-api/index.js +125 -0
- package/dist/js/modern/libs/hook-api/route.js +13 -36
- package/dist/js/modern/libs/hook-api/template.js +38 -15
- package/dist/js/modern/libs/loadConfig.js +3 -10
- package/dist/js/modern/libs/metrics.js +6 -6
- package/dist/js/modern/libs/proxy.js +7 -12
- package/dist/js/modern/libs/render/cache/__tests__/cache.fun.test.js +0 -1
- package/dist/js/modern/libs/render/cache/__tests__/cache.test.js +0 -9
- package/dist/js/modern/libs/render/cache/index.js +37 -28
- package/dist/js/modern/libs/render/cache/page-caches/lru.js +0 -10
- package/dist/js/modern/libs/render/cache/spr.js +12 -62
- package/dist/js/modern/libs/render/cache/util.js +0 -6
- package/dist/js/modern/libs/render/index.js +6 -11
- package/dist/js/modern/libs/render/measure.js +7 -10
- package/dist/js/modern/libs/render/modern/index.js +2 -13
- package/dist/js/modern/libs/render/reader.js +13 -24
- package/dist/js/modern/libs/render/ssr.js +24 -12
- package/dist/js/modern/libs/render/static.js +6 -9
- package/dist/js/modern/libs/render/type.js +0 -1
- package/dist/js/modern/libs/route/index.js +8 -19
- package/dist/js/modern/libs/route/matcher.js +21 -29
- package/dist/js/modern/libs/route/route.js +0 -13
- package/dist/js/modern/libs/serve-file.js +13 -6
- package/dist/js/modern/server/index.js +27 -43
- package/dist/js/modern/server/modern-server-split.js +5 -55
- package/dist/js/modern/server/modern-server.js +179 -250
- package/dist/js/modern/utils.js +2 -21
- package/dist/js/modern/worker-server.js +34 -0
- package/dist/js/node/constants.js +0 -2
- package/dist/js/node/index.js +0 -10
- package/dist/js/node/libs/context/context.js +10 -65
- package/dist/js/node/libs/context/index.js +0 -3
- package/dist/js/node/libs/hook-api/index.js +136 -0
- package/dist/js/node/libs/hook-api/route.js +13 -38
- package/dist/js/node/libs/hook-api/template.js +40 -18
- package/dist/js/node/libs/loadConfig.js +3 -22
- package/dist/js/node/libs/metrics.js +6 -6
- package/dist/js/node/libs/proxy.js +7 -17
- package/dist/js/node/libs/render/cache/__tests__/cache.fun.test.js +0 -5
- package/dist/js/node/libs/render/cache/__tests__/cache.test.js +0 -12
- package/dist/js/node/libs/render/cache/index.js +37 -33
- package/dist/js/node/libs/render/cache/page-caches/index.js +0 -2
- package/dist/js/node/libs/render/cache/page-caches/lru.js +0 -14
- package/dist/js/node/libs/render/cache/spr.js +12 -71
- package/dist/js/node/libs/render/cache/util.js +0 -18
- package/dist/js/node/libs/render/index.js +6 -26
- package/dist/js/node/libs/render/measure.js +5 -15
- package/dist/js/node/libs/render/modern/index.js +2 -20
- package/dist/js/node/libs/render/reader.js +12 -39
- package/dist/js/node/libs/render/ssr.js +23 -22
- package/dist/js/node/libs/render/static.js +6 -18
- package/dist/js/node/libs/render/type.js +0 -1
- package/dist/js/node/libs/route/index.js +8 -22
- package/dist/js/node/libs/route/matcher.js +18 -34
- package/dist/js/node/libs/route/route.js +0 -15
- package/dist/js/node/libs/serve-file.js +15 -12
- package/dist/js/node/server/index.js +26 -62
- package/dist/js/node/server/modern-server-split.js +5 -58
- package/dist/js/node/server/modern-server.js +178 -280
- package/dist/js/node/utils.js +3 -46
- package/dist/js/node/worker-server.js +41 -0
- package/dist/js/treeshaking/constants.js +28 -0
- package/dist/js/treeshaking/index.js +13 -0
- package/dist/js/treeshaking/libs/context/context.js +243 -0
- package/dist/js/treeshaking/libs/context/index.js +5 -0
- package/dist/js/treeshaking/libs/hook-api/index.js +157 -0
- package/dist/js/treeshaking/libs/hook-api/route.js +33 -0
- package/dist/js/treeshaking/libs/hook-api/template.js +91 -0
- package/dist/js/treeshaking/libs/loadConfig.js +39 -0
- package/dist/js/treeshaking/libs/metrics.js +12 -0
- package/dist/js/treeshaking/libs/proxy.js +80 -0
- package/dist/js/treeshaking/libs/render/cache/__tests__/cache.fun.test.js +124 -0
- package/dist/js/treeshaking/libs/render/cache/__tests__/cache.test.js +464 -0
- package/dist/js/treeshaking/libs/render/cache/__tests__/cacheable.js +53 -0
- package/dist/js/treeshaking/libs/render/cache/__tests__/error-configuration.js +35 -0
- package/dist/js/treeshaking/libs/render/cache/__tests__/matched-cache.js +121 -0
- package/dist/js/treeshaking/libs/render/cache/index.js +184 -0
- package/dist/js/treeshaking/libs/render/cache/page-caches/index.js +30 -0
- package/dist/js/treeshaking/libs/render/cache/page-caches/lru.js +46 -0
- package/dist/js/treeshaking/libs/render/cache/spr.js +362 -0
- package/dist/js/treeshaking/libs/render/cache/type.js +1 -0
- package/dist/js/treeshaking/libs/render/cache/util.js +101 -0
- package/dist/js/treeshaking/libs/render/index.js +100 -0
- package/dist/js/treeshaking/libs/render/measure.js +61 -0
- package/dist/js/treeshaking/libs/render/modern/browser-list.js +7 -0
- package/dist/js/treeshaking/libs/render/modern/index.js +39 -0
- package/dist/js/treeshaking/libs/render/reader.js +191 -0
- package/dist/js/treeshaking/libs/render/ssr.js +98 -0
- package/dist/js/treeshaking/libs/render/static.js +84 -0
- package/dist/js/treeshaking/libs/render/type.js +6 -0
- package/dist/js/treeshaking/libs/route/index.js +94 -0
- package/dist/js/treeshaking/libs/route/matcher.js +113 -0
- package/dist/js/treeshaking/libs/route/route.js +26 -0
- package/dist/js/treeshaking/libs/serve-file.js +75 -0
- package/dist/js/treeshaking/server/index.js +343 -0
- package/dist/js/treeshaking/server/modern-server-split.js +152 -0
- package/dist/js/treeshaking/server/modern-server.js +945 -0
- package/dist/js/treeshaking/type.js +1 -0
- package/dist/js/treeshaking/utils.js +87 -0
- package/dist/js/treeshaking/worker-server.js +56 -0
- package/dist/types/index.d.ts +0 -2
- package/dist/types/libs/context/context.d.ts +0 -3
- package/dist/types/libs/hook-api/index.d.ts +5 -0
- package/dist/types/libs/hook-api/route.d.ts +9 -14
- package/dist/types/libs/hook-api/template.d.ts +19 -9
- package/dist/types/libs/loadConfig.d.ts +0 -1
- package/dist/types/libs/render/cache/index.d.ts +4 -4
- package/dist/types/libs/render/cache/spr.d.ts +0 -2
- package/dist/types/libs/render/type.d.ts +3 -1
- package/dist/types/libs/serve-file.d.ts +2 -1
- package/dist/types/server/index.d.ts +2 -3
- package/dist/types/server/modern-server.d.ts +11 -11
- package/dist/types/type.d.ts +8 -10
- package/dist/types/utils.d.ts +0 -1
- package/dist/types/worker-server.d.ts +16 -0
- package/package.json +28 -35
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
import _toArray from "@babel/runtime/helpers/esm/toArray";
|
|
2
|
+
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
3
|
+
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
4
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
5
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
6
|
+
import { createCache, destroyCache } from "../spr";
|
|
7
|
+
import { errorConfiguration } from "./error-configuration";
|
|
8
|
+
import { cacheabelAry } from "./cacheable";
|
|
9
|
+
import { matchedCacheableAry } from "./matched-cache";
|
|
10
|
+
var createCacheConfig = function createCacheConfig() {
|
|
11
|
+
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
12
|
+
return _objectSpread({
|
|
13
|
+
excludes: null,
|
|
14
|
+
includes: null,
|
|
15
|
+
interval: 10,
|
|
16
|
+
staleLimit: false,
|
|
17
|
+
level: 0,
|
|
18
|
+
fallback: false,
|
|
19
|
+
matches: null
|
|
20
|
+
}, config);
|
|
21
|
+
};
|
|
22
|
+
jest.setTimeout(60000);
|
|
23
|
+
describe('cache', function () {
|
|
24
|
+
it('should cache correctly', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
25
|
+
var cache, context, content, cacheConfig, cacheResult;
|
|
26
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
27
|
+
while (1) {
|
|
28
|
+
switch (_context.prev = _context.next) {
|
|
29
|
+
case 0:
|
|
30
|
+
destroyCache();
|
|
31
|
+
cache = createCache();
|
|
32
|
+
context = {
|
|
33
|
+
entry: '',
|
|
34
|
+
pathname: '',
|
|
35
|
+
query: {},
|
|
36
|
+
headers: {}
|
|
37
|
+
};
|
|
38
|
+
content = 'hello';
|
|
39
|
+
cacheConfig = createCacheConfig();
|
|
40
|
+
_context.next = 7;
|
|
41
|
+
return cache.set(context, content, cacheConfig, true);
|
|
42
|
+
case 7:
|
|
43
|
+
_context.next = 9;
|
|
44
|
+
return cache.get(context);
|
|
45
|
+
case 9:
|
|
46
|
+
cacheResult = _context.sent;
|
|
47
|
+
expect(cacheResult).not.toBe(null);
|
|
48
|
+
expect(cacheResult === null || cacheResult === void 0 ? void 0 : cacheResult.content).toBe('hello');
|
|
49
|
+
case 12:
|
|
50
|
+
case "end":
|
|
51
|
+
return _context.stop();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}, _callee);
|
|
55
|
+
})));
|
|
56
|
+
it('should ignore cache set when cache config not exist', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
57
|
+
var cache, context, content, shouldCache;
|
|
58
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
59
|
+
while (1) {
|
|
60
|
+
switch (_context2.prev = _context2.next) {
|
|
61
|
+
case 0:
|
|
62
|
+
destroyCache();
|
|
63
|
+
destroyCache();
|
|
64
|
+
cache = createCache();
|
|
65
|
+
context = {
|
|
66
|
+
entry: '',
|
|
67
|
+
pathname: '',
|
|
68
|
+
query: {},
|
|
69
|
+
headers: {}
|
|
70
|
+
};
|
|
71
|
+
content = 'hello';
|
|
72
|
+
_context2.next = 7;
|
|
73
|
+
return cache.set(context, content, null, true);
|
|
74
|
+
case 7:
|
|
75
|
+
shouldCache = _context2.sent;
|
|
76
|
+
expect(shouldCache).toBe(false);
|
|
77
|
+
case 9:
|
|
78
|
+
case "end":
|
|
79
|
+
return _context2.stop();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}, _callee2);
|
|
83
|
+
})));
|
|
84
|
+
it('should calcual cache key error', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
85
|
+
var cache, content, _iterator, _step, config, cacheConfig, tmpEntry, context, shouldCache;
|
|
86
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
87
|
+
while (1) {
|
|
88
|
+
switch (_context3.prev = _context3.next) {
|
|
89
|
+
case 0:
|
|
90
|
+
destroyCache();
|
|
91
|
+
cache = createCache();
|
|
92
|
+
content = 'hello';
|
|
93
|
+
_iterator = _createForOfIteratorHelper(errorConfiguration);
|
|
94
|
+
_context3.prev = 4;
|
|
95
|
+
_iterator.s();
|
|
96
|
+
case 6:
|
|
97
|
+
if ((_step = _iterator.n()).done) {
|
|
98
|
+
_context3.next = 17;
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
config = _step.value;
|
|
102
|
+
cacheConfig = createCacheConfig(config);
|
|
103
|
+
tmpEntry = Math.random().toString();
|
|
104
|
+
context = {
|
|
105
|
+
entry: tmpEntry,
|
|
106
|
+
pathname: '',
|
|
107
|
+
query: {},
|
|
108
|
+
headers: {}
|
|
109
|
+
};
|
|
110
|
+
_context3.next = 13;
|
|
111
|
+
return cache.set(context, content, cacheConfig);
|
|
112
|
+
case 13:
|
|
113
|
+
shouldCache = _context3.sent;
|
|
114
|
+
expect(shouldCache).toBe(false);
|
|
115
|
+
case 15:
|
|
116
|
+
_context3.next = 6;
|
|
117
|
+
break;
|
|
118
|
+
case 17:
|
|
119
|
+
_context3.next = 22;
|
|
120
|
+
break;
|
|
121
|
+
case 19:
|
|
122
|
+
_context3.prev = 19;
|
|
123
|
+
_context3.t0 = _context3["catch"](4);
|
|
124
|
+
_iterator.e(_context3.t0);
|
|
125
|
+
case 22:
|
|
126
|
+
_context3.prev = 22;
|
|
127
|
+
_iterator.f();
|
|
128
|
+
return _context3.finish(22);
|
|
129
|
+
case 25:
|
|
130
|
+
case "end":
|
|
131
|
+
return _context3.stop();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}, _callee3, null, [[4, 19, 22, 25]]);
|
|
135
|
+
})));
|
|
136
|
+
it('should get nothing for diff requestKey', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
137
|
+
var cache, context, content, cacheConfig, context_req, cacheResult;
|
|
138
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
139
|
+
while (1) {
|
|
140
|
+
switch (_context4.prev = _context4.next) {
|
|
141
|
+
case 0:
|
|
142
|
+
destroyCache();
|
|
143
|
+
cache = createCache();
|
|
144
|
+
context = {
|
|
145
|
+
entry: '',
|
|
146
|
+
pathname: '',
|
|
147
|
+
query: {},
|
|
148
|
+
headers: {}
|
|
149
|
+
};
|
|
150
|
+
content = 'hello';
|
|
151
|
+
cacheConfig = createCacheConfig({
|
|
152
|
+
level: 1,
|
|
153
|
+
includes: {
|
|
154
|
+
query: ['name']
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
_context4.next = 7;
|
|
158
|
+
return cache.set(context, content, cacheConfig, true);
|
|
159
|
+
case 7:
|
|
160
|
+
context_req = {
|
|
161
|
+
entry: '',
|
|
162
|
+
pathname: '/home',
|
|
163
|
+
query: {},
|
|
164
|
+
headers: {}
|
|
165
|
+
};
|
|
166
|
+
_context4.next = 10;
|
|
167
|
+
return cache.get(context_req);
|
|
168
|
+
case 10:
|
|
169
|
+
cacheResult = _context4.sent;
|
|
170
|
+
expect(cacheResult).toBe(null);
|
|
171
|
+
case 12:
|
|
172
|
+
case "end":
|
|
173
|
+
return _context4.stop();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}, _callee4);
|
|
177
|
+
})));
|
|
178
|
+
it('should get nothing for diff cacheHash', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
179
|
+
var cache, context, content, cacheConfig, context_req, cacheResult;
|
|
180
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
181
|
+
while (1) {
|
|
182
|
+
switch (_context5.prev = _context5.next) {
|
|
183
|
+
case 0:
|
|
184
|
+
destroyCache();
|
|
185
|
+
cache = createCache();
|
|
186
|
+
context = {
|
|
187
|
+
entry: '',
|
|
188
|
+
pathname: '',
|
|
189
|
+
query: {},
|
|
190
|
+
headers: {}
|
|
191
|
+
};
|
|
192
|
+
content = 'hello';
|
|
193
|
+
cacheConfig = createCacheConfig({
|
|
194
|
+
level: 1,
|
|
195
|
+
includes: {
|
|
196
|
+
query: ['name']
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
_context5.next = 7;
|
|
200
|
+
return cache.set(context, content, cacheConfig, true);
|
|
201
|
+
case 7:
|
|
202
|
+
context_req = {
|
|
203
|
+
entry: '',
|
|
204
|
+
pathname: '',
|
|
205
|
+
query: {
|
|
206
|
+
name: 'zll'
|
|
207
|
+
},
|
|
208
|
+
headers: {}
|
|
209
|
+
};
|
|
210
|
+
_context5.next = 10;
|
|
211
|
+
return cache.get(context_req);
|
|
212
|
+
case 10:
|
|
213
|
+
cacheResult = _context5.sent;
|
|
214
|
+
expect(cacheResult).toBe(null);
|
|
215
|
+
case 12:
|
|
216
|
+
case "end":
|
|
217
|
+
return _context5.stop();
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}, _callee5);
|
|
221
|
+
})));
|
|
222
|
+
it('should get cache correctly', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
223
|
+
var cache, _iterator2, _step2, cacheable, context, cacheConfig, cacheResult;
|
|
224
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
225
|
+
while (1) {
|
|
226
|
+
switch (_context6.prev = _context6.next) {
|
|
227
|
+
case 0:
|
|
228
|
+
destroyCache();
|
|
229
|
+
cache = createCache();
|
|
230
|
+
_iterator2 = _createForOfIteratorHelper(cacheabelAry);
|
|
231
|
+
_context6.prev = 3;
|
|
232
|
+
_iterator2.s();
|
|
233
|
+
case 5:
|
|
234
|
+
if ((_step2 = _iterator2.n()).done) {
|
|
235
|
+
_context6.next = 17;
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
cacheable = _step2.value;
|
|
239
|
+
context = {
|
|
240
|
+
entry: '',
|
|
241
|
+
pathname: cacheable.requestOpt.url,
|
|
242
|
+
query: cacheable.requestOpt.query || {},
|
|
243
|
+
headers: cacheable.requestOpt.headers || {}
|
|
244
|
+
};
|
|
245
|
+
cacheConfig = createCacheConfig(cacheable.cacheConfig || {});
|
|
246
|
+
_context6.next = 11;
|
|
247
|
+
return cache.set(context, cacheable.content, cacheConfig, true);
|
|
248
|
+
case 11:
|
|
249
|
+
_context6.next = 13;
|
|
250
|
+
return cache.get(context);
|
|
251
|
+
case 13:
|
|
252
|
+
cacheResult = _context6.sent;
|
|
253
|
+
expect(cacheResult === null || cacheResult === void 0 ? void 0 : cacheResult.content).toBe(cacheable.content);
|
|
254
|
+
case 15:
|
|
255
|
+
_context6.next = 5;
|
|
256
|
+
break;
|
|
257
|
+
case 17:
|
|
258
|
+
_context6.next = 22;
|
|
259
|
+
break;
|
|
260
|
+
case 19:
|
|
261
|
+
_context6.prev = 19;
|
|
262
|
+
_context6.t0 = _context6["catch"](3);
|
|
263
|
+
_iterator2.e(_context6.t0);
|
|
264
|
+
case 22:
|
|
265
|
+
_context6.prev = 22;
|
|
266
|
+
_iterator2.f();
|
|
267
|
+
return _context6.finish(22);
|
|
268
|
+
case 25:
|
|
269
|
+
case "end":
|
|
270
|
+
return _context6.stop();
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}, _callee6, null, [[3, 19, 22, 25]]);
|
|
274
|
+
})));
|
|
275
|
+
it('should match cache correctly', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
276
|
+
var cache, _iterator3, _step3, _cacheResult, cacheable, _cacheable, baseCacheable, matchOne, other, _baseCacheable$reques, requestOpt, cacheConfig, content, context, matchContext, cacheResult, _iterator4, _step4, notMatch, notMatchContext, nothing;
|
|
277
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
278
|
+
while (1) {
|
|
279
|
+
switch (_context7.prev = _context7.next) {
|
|
280
|
+
case 0:
|
|
281
|
+
destroyCache();
|
|
282
|
+
cache = createCache();
|
|
283
|
+
_iterator3 = _createForOfIteratorHelper(matchedCacheableAry);
|
|
284
|
+
_context7.prev = 3;
|
|
285
|
+
_iterator3.s();
|
|
286
|
+
case 5:
|
|
287
|
+
if ((_step3 = _iterator3.n()).done) {
|
|
288
|
+
_context7.next = 39;
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
cacheable = _step3.value;
|
|
292
|
+
_cacheable = _toArray(cacheable), baseCacheable = _cacheable[0], matchOne = _cacheable[1], other = _cacheable.slice(2);
|
|
293
|
+
_baseCacheable$reques = baseCacheable.requestOpt, requestOpt = _baseCacheable$reques === void 0 ? {} : _baseCacheable$reques, cacheConfig = baseCacheable.cacheConfig, content = baseCacheable.content;
|
|
294
|
+
context = {
|
|
295
|
+
entry: '',
|
|
296
|
+
pathname: requestOpt.url,
|
|
297
|
+
query: requestOpt.query,
|
|
298
|
+
headers: requestOpt.headers
|
|
299
|
+
};
|
|
300
|
+
_context7.next = 12;
|
|
301
|
+
return cache.set(context, content, createCacheConfig(cacheConfig), true);
|
|
302
|
+
case 12:
|
|
303
|
+
matchContext = {
|
|
304
|
+
entry: '',
|
|
305
|
+
pathname: matchOne.url,
|
|
306
|
+
query: matchOne.query,
|
|
307
|
+
headers: matchOne.headers
|
|
308
|
+
};
|
|
309
|
+
_context7.next = 15;
|
|
310
|
+
return cache.get(matchContext);
|
|
311
|
+
case 15:
|
|
312
|
+
cacheResult = _context7.sent;
|
|
313
|
+
expect((_cacheResult = cacheResult) === null || _cacheResult === void 0 ? void 0 : _cacheResult.content).toBe(content);
|
|
314
|
+
_iterator4 = _createForOfIteratorHelper(other);
|
|
315
|
+
_context7.prev = 18;
|
|
316
|
+
_iterator4.s();
|
|
317
|
+
case 20:
|
|
318
|
+
if ((_step4 = _iterator4.n()).done) {
|
|
319
|
+
_context7.next = 29;
|
|
320
|
+
break;
|
|
321
|
+
}
|
|
322
|
+
notMatch = _step4.value;
|
|
323
|
+
notMatchContext = {
|
|
324
|
+
entry: '',
|
|
325
|
+
pathname: notMatch.url,
|
|
326
|
+
query: notMatch.query,
|
|
327
|
+
headers: notMatch.headers
|
|
328
|
+
};
|
|
329
|
+
_context7.next = 25;
|
|
330
|
+
return cache.get(notMatchContext);
|
|
331
|
+
case 25:
|
|
332
|
+
nothing = _context7.sent;
|
|
333
|
+
expect(nothing).toBe(null);
|
|
334
|
+
case 27:
|
|
335
|
+
_context7.next = 20;
|
|
336
|
+
break;
|
|
337
|
+
case 29:
|
|
338
|
+
_context7.next = 34;
|
|
339
|
+
break;
|
|
340
|
+
case 31:
|
|
341
|
+
_context7.prev = 31;
|
|
342
|
+
_context7.t0 = _context7["catch"](18);
|
|
343
|
+
_iterator4.e(_context7.t0);
|
|
344
|
+
case 34:
|
|
345
|
+
_context7.prev = 34;
|
|
346
|
+
_iterator4.f();
|
|
347
|
+
return _context7.finish(34);
|
|
348
|
+
case 37:
|
|
349
|
+
_context7.next = 5;
|
|
350
|
+
break;
|
|
351
|
+
case 39:
|
|
352
|
+
_context7.next = 44;
|
|
353
|
+
break;
|
|
354
|
+
case 41:
|
|
355
|
+
_context7.prev = 41;
|
|
356
|
+
_context7.t1 = _context7["catch"](3);
|
|
357
|
+
_iterator3.e(_context7.t1);
|
|
358
|
+
case 44:
|
|
359
|
+
_context7.prev = 44;
|
|
360
|
+
_iterator3.f();
|
|
361
|
+
return _context7.finish(44);
|
|
362
|
+
case 47:
|
|
363
|
+
case "end":
|
|
364
|
+
return _context7.stop();
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}, _callee7, null, [[3, 41, 44, 47], [18, 31, 34, 37]]);
|
|
368
|
+
})));
|
|
369
|
+
it('should stale cache correctly', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
|
|
370
|
+
var cache, context, config, content, shouldCache, freshResult, staleResult;
|
|
371
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
372
|
+
while (1) {
|
|
373
|
+
switch (_context8.prev = _context8.next) {
|
|
374
|
+
case 0:
|
|
375
|
+
destroyCache();
|
|
376
|
+
cache = createCache();
|
|
377
|
+
context = {
|
|
378
|
+
entry: '',
|
|
379
|
+
pathname: '',
|
|
380
|
+
query: {},
|
|
381
|
+
headers: {}
|
|
382
|
+
};
|
|
383
|
+
config = createCacheConfig({
|
|
384
|
+
interval: 5
|
|
385
|
+
});
|
|
386
|
+
content = 'hello';
|
|
387
|
+
_context8.next = 7;
|
|
388
|
+
return cache.set(context, content, config, true);
|
|
389
|
+
case 7:
|
|
390
|
+
shouldCache = _context8.sent;
|
|
391
|
+
expect(shouldCache.value).toBe(true);
|
|
392
|
+
_context8.next = 11;
|
|
393
|
+
return cache.get(context);
|
|
394
|
+
case 11:
|
|
395
|
+
freshResult = _context8.sent;
|
|
396
|
+
expect(freshResult === null || freshResult === void 0 ? void 0 : freshResult.isStale).toBe(false);
|
|
397
|
+
_context8.next = 15;
|
|
398
|
+
return new Promise(function (resolve) {
|
|
399
|
+
setTimeout(function () {
|
|
400
|
+
resolve();
|
|
401
|
+
}, 6000);
|
|
402
|
+
});
|
|
403
|
+
case 15:
|
|
404
|
+
_context8.next = 17;
|
|
405
|
+
return cache.get(context);
|
|
406
|
+
case 17:
|
|
407
|
+
staleResult = _context8.sent;
|
|
408
|
+
expect(staleResult === null || staleResult === void 0 ? void 0 : staleResult.isStale).toBe(true);
|
|
409
|
+
case 19:
|
|
410
|
+
case "end":
|
|
411
|
+
return _context8.stop();
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}, _callee8);
|
|
415
|
+
})));
|
|
416
|
+
it('should garbage cache correctly', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
|
|
417
|
+
var cache, context, config, content, shouldCache, freshResult, staleResult;
|
|
418
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
419
|
+
while (1) {
|
|
420
|
+
switch (_context9.prev = _context9.next) {
|
|
421
|
+
case 0:
|
|
422
|
+
destroyCache();
|
|
423
|
+
cache = createCache();
|
|
424
|
+
context = {
|
|
425
|
+
entry: '',
|
|
426
|
+
pathname: '',
|
|
427
|
+
query: {},
|
|
428
|
+
headers: {}
|
|
429
|
+
};
|
|
430
|
+
config = createCacheConfig({
|
|
431
|
+
interval: 3,
|
|
432
|
+
staleLimit: 8
|
|
433
|
+
});
|
|
434
|
+
content = 'hello';
|
|
435
|
+
_context9.next = 7;
|
|
436
|
+
return cache.set(context, content, config, true);
|
|
437
|
+
case 7:
|
|
438
|
+
shouldCache = _context9.sent;
|
|
439
|
+
expect(shouldCache.value).toBe(true);
|
|
440
|
+
_context9.next = 11;
|
|
441
|
+
return cache.get(context);
|
|
442
|
+
case 11:
|
|
443
|
+
freshResult = _context9.sent;
|
|
444
|
+
expect(freshResult === null || freshResult === void 0 ? void 0 : freshResult.isGarbage).toBe(false);
|
|
445
|
+
_context9.next = 15;
|
|
446
|
+
return new Promise(function (resolve) {
|
|
447
|
+
setTimeout(function () {
|
|
448
|
+
resolve();
|
|
449
|
+
}, 10000);
|
|
450
|
+
});
|
|
451
|
+
case 15:
|
|
452
|
+
_context9.next = 17;
|
|
453
|
+
return cache.get(context);
|
|
454
|
+
case 17:
|
|
455
|
+
staleResult = _context9.sent;
|
|
456
|
+
expect(staleResult === null || staleResult === void 0 ? void 0 : staleResult.isGarbage).toBe(true);
|
|
457
|
+
case 19:
|
|
458
|
+
case "end":
|
|
459
|
+
return _context9.stop();
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}, _callee9);
|
|
463
|
+
})));
|
|
464
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export var cacheabelAry = [{
|
|
2
|
+
requestOpt: {
|
|
3
|
+
url: '/'
|
|
4
|
+
},
|
|
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'
|
|
40
|
+
},
|
|
41
|
+
headers: {
|
|
42
|
+
age: '18'
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
cacheConfig: {
|
|
46
|
+
level: 3,
|
|
47
|
+
includes: {
|
|
48
|
+
query: ['name'],
|
|
49
|
+
header: ['age']
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
content: 'level3'
|
|
53
|
+
}];
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export var errorConfiguration = [{
|
|
2
|
+
level: 1
|
|
3
|
+
}, {
|
|
4
|
+
level: 1,
|
|
5
|
+
includes: {}
|
|
6
|
+
}, {
|
|
7
|
+
level: 1,
|
|
8
|
+
includes: {
|
|
9
|
+
query: []
|
|
10
|
+
}
|
|
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
|
+
}];
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
export var matchedCacheableAry = [[{
|
|
2
|
+
requestOpt: {
|
|
3
|
+
url: '/level-one',
|
|
4
|
+
headers: {},
|
|
5
|
+
query: {
|
|
6
|
+
name: 'byted'
|
|
7
|
+
}
|
|
8
|
+
},
|
|
9
|
+
cacheConfig: {
|
|
10
|
+
level: 1,
|
|
11
|
+
includes: {
|
|
12
|
+
query: ['name']
|
|
13
|
+
},
|
|
14
|
+
matches: {
|
|
15
|
+
query: {
|
|
16
|
+
name: {
|
|
17
|
+
weixin: '^byted'
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
content: 'level1'
|
|
23
|
+
}, {
|
|
24
|
+
url: '/level-one',
|
|
25
|
+
headers: {},
|
|
26
|
+
query: {
|
|
27
|
+
name: 'byted_likely'
|
|
28
|
+
}
|
|
29
|
+
}, {
|
|
30
|
+
url: '/level-one',
|
|
31
|
+
headers: {},
|
|
32
|
+
query: {
|
|
33
|
+
name: 'not_byted'
|
|
34
|
+
}
|
|
35
|
+
}], [{
|
|
36
|
+
requestOpt: {
|
|
37
|
+
url: '/level-two',
|
|
38
|
+
query: {},
|
|
39
|
+
headers: {
|
|
40
|
+
age: '17'
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
cacheConfig: {
|
|
44
|
+
level: 2,
|
|
45
|
+
includes: {
|
|
46
|
+
header: ['age']
|
|
47
|
+
},
|
|
48
|
+
matches: {
|
|
49
|
+
header: {
|
|
50
|
+
age: {
|
|
51
|
+
one: '^1'
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
content: 'level2'
|
|
57
|
+
}, {
|
|
58
|
+
url: '/level-two',
|
|
59
|
+
query: {},
|
|
60
|
+
headers: {
|
|
61
|
+
age: '11'
|
|
62
|
+
}
|
|
63
|
+
}, {
|
|
64
|
+
url: '/level-two',
|
|
65
|
+
query: {},
|
|
66
|
+
headers: {
|
|
67
|
+
age: '22'
|
|
68
|
+
}
|
|
69
|
+
}], [{
|
|
70
|
+
requestOpt: {
|
|
71
|
+
url: '/level-three',
|
|
72
|
+
headers: {
|
|
73
|
+
age: '17'
|
|
74
|
+
},
|
|
75
|
+
query: {
|
|
76
|
+
name: 'byted'
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
cacheConfig: {
|
|
80
|
+
level: 3,
|
|
81
|
+
includes: {
|
|
82
|
+
query: ['name'],
|
|
83
|
+
header: ['age']
|
|
84
|
+
},
|
|
85
|
+
matches: {
|
|
86
|
+
query: {
|
|
87
|
+
name: {
|
|
88
|
+
weixin: '^byted'
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
header: {
|
|
92
|
+
age: {
|
|
93
|
+
one: '^1'
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
content: 'level3'
|
|
99
|
+
}, {
|
|
100
|
+
url: '/level-three',
|
|
101
|
+
query: {
|
|
102
|
+
name: 'byted_likely'
|
|
103
|
+
},
|
|
104
|
+
headers: {
|
|
105
|
+
age: '19'
|
|
106
|
+
}
|
|
107
|
+
}, {
|
|
108
|
+
url: '/level-three',
|
|
109
|
+
query: {
|
|
110
|
+
name: 'byted_likely'
|
|
111
|
+
},
|
|
112
|
+
headers: {}
|
|
113
|
+
}, {
|
|
114
|
+
url: '/level-three',
|
|
115
|
+
query: {
|
|
116
|
+
name: 'not_byted'
|
|
117
|
+
},
|
|
118
|
+
headers: {
|
|
119
|
+
age: '19'
|
|
120
|
+
}
|
|
121
|
+
}]];
|