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