@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.
- package/CHANGELOG.md +139 -0
- package/dist/js/modern/constants.js +32 -25
- package/dist/js/modern/index.js +11 -6
- package/dist/js/modern/libs/context/context.js +52 -84
- package/dist/js/modern/libs/context/index.js +5 -2
- package/dist/js/modern/libs/hook-api/index.js +44 -35
- package/dist/js/modern/libs/hook-api/route.js +6 -7
- package/dist/js/modern/libs/hook-api/template.js +20 -34
- package/dist/js/modern/libs/loadConfig.js +45 -24
- package/dist/js/modern/libs/metrics.js +3 -4
- package/dist/js/modern/libs/proxy.js +68 -37
- package/dist/js/modern/libs/render/cache/__tests__/cache.fun.test.js +112 -67
- package/dist/js/modern/libs/render/cache/__tests__/cache.test.js +246 -216
- package/dist/js/modern/libs/render/cache/__tests__/cacheable.js +43 -49
- package/dist/js/modern/libs/render/cache/__tests__/error-configuration.js +36 -34
- package/dist/js/modern/libs/render/cache/__tests__/matched-cache.js +83 -113
- package/dist/js/modern/libs/render/cache/index.js +88 -54
- package/dist/js/modern/libs/render/cache/page-caches/index.js +31 -8
- package/dist/js/modern/libs/render/cache/page-caches/lru.js +6 -6
- package/dist/js/modern/libs/render/cache/spr.js +133 -117
- package/dist/js/modern/libs/render/cache/type.js +0 -1
- package/dist/js/modern/libs/render/cache/util.js +71 -39
- package/dist/js/modern/libs/render/index.js +76 -56
- package/dist/js/modern/libs/render/measure.js +38 -27
- package/dist/js/modern/libs/render/reader.js +65 -62
- package/dist/js/modern/libs/render/ssr.js +50 -32
- package/dist/js/modern/libs/render/static.js +50 -33
- package/dist/js/modern/libs/render/type.js +9 -6
- package/dist/js/modern/libs/route/index.js +8 -15
- package/dist/js/modern/libs/route/matcher.js +20 -34
- package/dist/js/modern/libs/route/route.js +9 -18
- package/dist/js/modern/libs/serve-file.js +33 -20
- package/dist/js/modern/server/index.js +150 -145
- package/dist/js/modern/server/modern-server-split.js +46 -12
- package/dist/js/modern/server/modern-server.js +384 -422
- package/dist/js/modern/type.js +0 -1
- package/dist/js/modern/utils.js +62 -43
- package/dist/js/modern/worker-server.js +34 -14
- package/dist/js/node/constants.js +53 -30
- package/dist/js/node/index.js +37 -57
- package/dist/js/node/libs/context/context.js +83 -94
- package/dist/js/node/libs/context/index.js +28 -13
- package/dist/js/node/libs/hook-api/index.js +76 -48
- package/dist/js/node/libs/hook-api/route.js +26 -11
- package/dist/js/node/libs/hook-api/template.js +41 -39
- package/dist/js/node/libs/loadConfig.js +73 -35
- package/dist/js/node/libs/metrics.js +25 -9
- package/dist/js/node/libs/proxy.js +89 -44
- package/dist/js/node/libs/render/cache/__tests__/cache.fun.test.js +99 -56
- package/dist/js/node/libs/render/cache/__tests__/cache.test.js +147 -128
- package/dist/js/node/libs/render/cache/__tests__/cacheable.js +65 -55
- package/dist/js/node/libs/render/cache/__tests__/error-configuration.js +58 -40
- package/dist/js/node/libs/render/cache/__tests__/matched-cache.js +105 -119
- package/dist/js/node/libs/render/cache/index.js +110 -64
- package/dist/js/node/libs/render/cache/page-caches/index.js +54 -14
- package/dist/js/node/libs/render/cache/page-caches/lru.js +33 -12
- package/dist/js/node/libs/render/cache/spr.js +161 -129
- package/dist/js/node/libs/render/cache/type.js +15 -5
- package/dist/js/node/libs/render/cache/util.js +99 -45
- package/dist/js/node/libs/render/index.js +106 -67
- package/dist/js/node/libs/render/measure.js +58 -31
- package/dist/js/node/libs/render/reader.js +95 -70
- package/dist/js/node/libs/render/ssr.js +80 -47
- package/dist/js/node/libs/render/static.js +79 -40
- package/dist/js/node/libs/render/type.js +31 -12
- package/dist/js/node/libs/route/index.js +31 -26
- package/dist/js/node/libs/route/matcher.js +40 -41
- package/dist/js/node/libs/route/route.js +29 -22
- package/dist/js/node/libs/serve-file.js +66 -32
- package/dist/js/node/server/index.js +168 -160
- package/dist/js/node/server/modern-server-split.js +72 -22
- package/dist/js/node/server/modern-server.js +403 -445
- package/dist/js/node/type.js +15 -3
- package/dist/js/node/utils.js +85 -52
- package/dist/js/node/worker-server.js +57 -21
- package/dist/js/treeshaking/constants.js +26 -25
- package/dist/js/treeshaking/index.js +10 -10
- package/dist/js/treeshaking/libs/context/context.js +268 -237
- package/dist/js/treeshaking/libs/context/index.js +3 -3
- package/dist/js/treeshaking/libs/hook-api/index.js +267 -143
- package/dist/js/treeshaking/libs/hook-api/route.js +65 -30
- package/dist/js/treeshaking/libs/hook-api/template.js +121 -85
- package/dist/js/treeshaking/libs/loadConfig.js +80 -37
- package/dist/js/treeshaking/libs/metrics.js +4 -10
- package/dist/js/treeshaking/libs/proxy.js +240 -76
- package/dist/js/treeshaking/libs/render/cache/__tests__/cache.fun.test.js +288 -121
- package/dist/js/treeshaking/libs/render/cache/__tests__/cache.test.js +772 -455
- package/dist/js/treeshaking/libs/render/cache/__tests__/cacheable.js +65 -51
- package/dist/js/treeshaking/libs/render/cache/__tests__/error-configuration.js +45 -35
- package/dist/js/treeshaking/libs/render/cache/__tests__/matched-cache.js +144 -118
- package/dist/js/treeshaking/libs/render/cache/index.js +337 -175
- package/dist/js/treeshaking/libs/render/cache/page-caches/index.js +151 -27
- package/dist/js/treeshaking/libs/render/cache/page-caches/lru.js +80 -42
- package/dist/js/treeshaking/libs/render/cache/spr.js +470 -340
- package/dist/js/treeshaking/libs/render/cache/type.js +1 -1
- package/dist/js/treeshaking/libs/render/cache/util.js +271 -92
- package/dist/js/treeshaking/libs/render/index.js +228 -95
- package/dist/js/treeshaking/libs/render/measure.js +142 -57
- package/dist/js/treeshaking/libs/render/reader.js +325 -177
- package/dist/js/treeshaking/libs/render/ssr.js +220 -95
- package/dist/js/treeshaking/libs/render/static.js +210 -78
- package/dist/js/treeshaking/libs/render/type.js +7 -6
- package/dist/js/treeshaking/libs/route/index.js +125 -89
- package/dist/js/treeshaking/libs/route/matcher.js +132 -107
- package/dist/js/treeshaking/libs/route/route.js +40 -26
- package/dist/js/treeshaking/libs/serve-file.js +177 -68
- package/dist/js/treeshaking/server/index.js +493 -327
- package/dist/js/treeshaking/server/modern-server-split.js +352 -144
- package/dist/js/treeshaking/server/modern-server.js +1048 -909
- package/dist/js/treeshaking/type.js +1 -1
- package/dist/js/treeshaking/utils.js +138 -81
- package/dist/js/treeshaking/worker-server.js +176 -55
- package/dist/types/index.d.ts +2 -0
- package/dist/types/libs/context/context.d.ts +4 -1
- package/dist/types/libs/loadConfig.d.ts +1 -0
- package/dist/types/libs/render/cache/index.d.ts +2 -0
- package/dist/types/libs/render/cache/spr.d.ts +2 -0
- package/dist/types/libs/route/route.d.ts +0 -1
- package/dist/types/server/index.d.ts +3 -0
- package/dist/types/utils.d.ts +1 -1
- package/dist/types/worker-server.d.ts +1 -2
- package/package.json +7 -14
- package/dist/js/modern/libs/render/modern/browser-list.js +0 -7
- package/dist/js/modern/libs/render/modern/index.js +0 -37
- package/dist/js/node/libs/render/modern/browser-list.js +0 -14
- package/dist/js/node/libs/render/modern/index.js +0 -46
- package/dist/js/treeshaking/libs/render/modern/browser-list.js +0 -7
- package/dist/js/treeshaking/libs/render/modern/index.js +0 -39
- package/dist/types/libs/render/modern/browser-list.d.ts +0 -1
- package/dist/types/libs/render/modern/index.d.ts +0 -3
|
@@ -1,224 +1,254 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
|
|
118
|
-
|
|
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
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
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
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
});
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
export default require_cache_test();
|
|
@@ -1,53 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
url:
|
|
1
|
+
const cacheabelAry = [
|
|
2
|
+
{
|
|
3
|
+
requestOpt: { url: "/" },
|
|
4
|
+
cacheConfig: {},
|
|
5
|
+
content: "level0"
|
|
4
6
|
},
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
42
|
-
age: '18'
|
|
43
|
-
}
|
|
16
|
+
content: "level1"
|
|
44
17
|
},
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2
|
-
level: 1
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
},
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
13
|
-
|
|
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
|
+
};
|