@modern-js/prod-server 2.14.0 → 2.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/dist/cjs/constants.js +15 -31
- package/dist/cjs/index.js +35 -37
- package/dist/cjs/libs/context/context.js +53 -66
- package/dist/cjs/libs/context/index.js +15 -28
- package/dist/cjs/libs/hook-api/index.js +59 -54
- package/dist/cjs/libs/hook-api/route.js +28 -30
- package/dist/cjs/libs/hook-api/template.js +30 -34
- package/dist/cjs/libs/loadConfig.js +74 -65
- package/dist/cjs/libs/logger.js +46 -37
- package/dist/cjs/libs/metrics.js +7 -25
- package/dist/cjs/libs/proxy.js +29 -46
- package/dist/cjs/libs/render/cache/__tests__/cache.fun.test.js +48 -64
- package/dist/cjs/libs/render/cache/__tests__/cache.test.js +53 -37
- package/dist/cjs/libs/render/cache/__tests__/cacheable.js +38 -34
- package/dist/cjs/libs/render/cache/__tests__/error-configuration.js +22 -30
- package/dist/cjs/libs/render/cache/__tests__/matched-cache.js +86 -46
- package/dist/cjs/libs/render/cache/index.js +17 -37
- package/dist/cjs/libs/render/cache/page-caches/index.js +12 -28
- package/dist/cjs/libs/render/cache/page-caches/lru.js +32 -40
- package/dist/cjs/libs/render/cache/spr.js +104 -111
- package/dist/cjs/libs/render/cache/type.js +4 -15
- package/dist/cjs/libs/render/cache/util.js +29 -53
- package/dist/cjs/libs/render/index.js +75 -73
- package/dist/cjs/libs/render/measure.js +19 -34
- package/dist/cjs/libs/render/reader.js +52 -61
- package/dist/cjs/libs/render/ssr.js +34 -66
- package/dist/cjs/libs/render/static.js +22 -45
- package/dist/cjs/libs/render/type.js +10 -28
- package/dist/cjs/libs/render/utils.js +17 -38
- package/dist/cjs/libs/route/index.js +32 -31
- package/dist/cjs/libs/route/matcher.js +38 -38
- package/dist/cjs/libs/route/route.js +29 -26
- package/dist/cjs/libs/serveFile.js +23 -41
- package/dist/cjs/server/index.js +101 -107
- package/dist/cjs/server/modernServer.js +191 -171
- package/dist/cjs/server/modernServerSplit.js +12 -30
- package/dist/cjs/type.js +4 -15
- package/dist/cjs/utils.js +50 -50
- package/dist/cjs/workerServer.js +26 -36
- package/dist/esm/constants.js +24 -25
- package/dist/esm/index.js +11 -10
- package/dist/esm/libs/context/context.js +271 -264
- package/dist/esm/libs/context/index.js +3 -3
- package/dist/esm/libs/hook-api/index.js +237 -223
- package/dist/esm/libs/hook-api/route.js +62 -60
- package/dist/esm/libs/hook-api/template.js +117 -115
- package/dist/esm/libs/loadConfig.js +68 -69
- package/dist/esm/libs/logger.js +188 -174
- package/dist/esm/libs/metrics.js +6 -3
- package/dist/esm/libs/proxy.js +236 -221
- package/dist/esm/libs/render/cache/__tests__/cache.fun.test.js +286 -267
- package/dist/esm/libs/render/cache/__tests__/cache.test.js +765 -745
- package/dist/esm/libs/render/cache/__tests__/cacheable.js +62 -63
- package/dist/esm/libs/render/cache/__tests__/error-configuration.js +42 -43
- package/dist/esm/libs/render/cache/__tests__/matched-cache.js +134 -135
- package/dist/esm/libs/render/cache/index.js +337 -326
- package/dist/esm/libs/render/cache/page-caches/index.js +147 -141
- package/dist/esm/libs/render/cache/page-caches/lru.js +78 -76
- package/dist/esm/libs/render/cache/spr.js +465 -456
- package/dist/esm/libs/render/cache/type.js +1 -1
- package/dist/esm/libs/render/cache/util.js +266 -246
- package/dist/esm/libs/render/index.js +226 -218
- package/dist/esm/libs/render/measure.js +136 -128
- package/dist/esm/libs/render/reader.js +315 -304
- package/dist/esm/libs/render/ssr.js +214 -209
- package/dist/esm/libs/render/static.js +208 -198
- package/dist/esm/libs/render/type.js +6 -7
- package/dist/esm/libs/render/utils.js +8 -9
- package/dist/esm/libs/route/index.js +134 -123
- package/dist/esm/libs/route/matcher.js +140 -130
- package/dist/esm/libs/route/route.js +36 -37
- package/dist/esm/libs/serveFile.js +177 -168
- package/dist/esm/server/index.js +578 -549
- package/dist/esm/server/modernServer.js +1137 -1074
- package/dist/esm/server/modernServerSplit.js +344 -328
- package/dist/esm/type.js +1 -1
- package/dist/esm/utils.js +133 -124
- package/dist/esm/workerServer.js +226 -220
- package/dist/esm-node/constants.js +7 -14
- package/dist/esm-node/index.js +4 -9
- package/dist/esm-node/libs/context/context.js +32 -25
- package/dist/esm-node/libs/context/index.js +2 -5
- package/dist/esm-node/libs/hook-api/index.js +40 -21
- package/dist/esm-node/libs/hook-api/route.js +21 -8
- package/dist/esm-node/libs/hook-api/template.js +19 -14
- package/dist/esm-node/libs/loadConfig.js +11 -28
- package/dist/esm-node/libs/logger.js +37 -17
- package/dist/esm-node/libs/metrics.js +1 -3
- package/dist/esm-node/libs/proxy.js +14 -22
- package/dist/esm-node/libs/render/cache/__tests__/cache.fun.test.js +25 -36
- package/dist/esm-node/libs/render/cache/__tests__/cache.test.js +23 -11
- package/dist/esm-node/libs/render/cache/__tests__/cacheable.js +32 -13
- package/dist/esm-node/libs/render/cache/__tests__/error-configuration.js +16 -9
- package/dist/esm-node/libs/render/cache/__tests__/matched-cache.js +80 -25
- package/dist/esm-node/libs/render/cache/index.js +3 -10
- package/dist/esm-node/libs/render/cache/page-caches/index.js +4 -5
- package/dist/esm-node/libs/render/cache/page-caches/lru.js +20 -8
- package/dist/esm-node/libs/render/cache/spr.js +79 -80
- package/dist/esm-node/libs/render/cache/type.js +1 -0
- package/dist/esm-node/libs/render/cache/util.js +13 -23
- package/dist/esm-node/libs/render/index.js +10 -28
- package/dist/esm-node/libs/render/measure.js +7 -13
- package/dist/esm-node/libs/render/reader.js +31 -26
- package/dist/esm-node/libs/render/ssr.js +5 -21
- package/dist/esm-node/libs/render/static.js +1 -4
- package/dist/esm-node/libs/render/type.js +3 -6
- package/dist/esm-node/libs/render/utils.js +6 -18
- package/dist/esm-node/libs/route/index.js +20 -9
- package/dist/esm-node/libs/route/matcher.js +28 -17
- package/dist/esm-node/libs/route/route.js +23 -5
- package/dist/esm-node/libs/serveFile.js +2 -6
- package/dist/esm-node/server/index.js +72 -75
- package/dist/esm-node/server/modernServer.js +102 -130
- package/dist/esm-node/server/modernServerSplit.js +1 -4
- package/dist/esm-node/type.js +1 -0
- package/dist/esm-node/utils.js +41 -32
- package/dist/esm-node/workerServer.js +9 -10
- package/dist/types/libs/context/context.d.ts +1 -1
- package/dist/types/server/modernServer.d.ts +1 -1
- package/dist/types/utils.d.ts +1 -1
- package/package.json +12 -8
|
@@ -1,158 +1,168 @@
|
|
|
1
1
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
try {
|
|
3
|
+
var info = gen[key](arg);
|
|
4
|
+
var value = info.value;
|
|
5
|
+
} catch (error) {
|
|
6
|
+
reject(error);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (info.done) {
|
|
10
|
+
resolve(value);
|
|
11
|
+
} else {
|
|
12
|
+
Promise.resolve(value).then(_next, _throw);
|
|
13
|
+
}
|
|
14
14
|
}
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
15
|
+
function _async_to_generator(fn) {
|
|
16
|
+
return function() {
|
|
17
|
+
var self = this, args = arguments;
|
|
18
|
+
return new Promise(function(resolve, reject) {
|
|
19
|
+
var gen = fn.apply(self, args);
|
|
20
|
+
function _next(value) {
|
|
21
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
+
}
|
|
23
|
+
function _throw(err) {
|
|
24
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
+
}
|
|
26
|
+
_next(void 0);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
29
|
}
|
|
30
|
-
function
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
function _class_call_check(instance, Constructor) {
|
|
31
|
+
if (!(instance instanceof Constructor)) {
|
|
32
|
+
throw new TypeError("Cannot call a class as a function");
|
|
33
|
+
}
|
|
34
34
|
}
|
|
35
35
|
function _defineProperties(target, props) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
36
|
+
for (var i = 0; i < props.length; i++) {
|
|
37
|
+
var descriptor = props[i];
|
|
38
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
39
|
+
descriptor.configurable = true;
|
|
40
|
+
if ("value" in descriptor)
|
|
41
|
+
descriptor.writable = true;
|
|
42
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
43
|
+
}
|
|
43
44
|
}
|
|
44
|
-
function
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
46
|
+
if (protoProps)
|
|
47
|
+
_defineProperties(Constructor.prototype, protoProps);
|
|
48
|
+
if (staticProps)
|
|
49
|
+
_defineProperties(Constructor, staticProps);
|
|
50
|
+
return Constructor;
|
|
48
51
|
}
|
|
49
|
-
function
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
52
|
+
function _define_property(obj, key, value) {
|
|
53
|
+
if (key in obj) {
|
|
54
|
+
Object.defineProperty(obj, key, {
|
|
55
|
+
value,
|
|
56
|
+
enumerable: true,
|
|
57
|
+
configurable: true,
|
|
58
|
+
writable: true
|
|
59
|
+
});
|
|
60
|
+
} else {
|
|
61
|
+
obj[key] = value;
|
|
62
|
+
}
|
|
63
|
+
return obj;
|
|
61
64
|
}
|
|
62
|
-
var __generator =
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
var __generator = function(thisArg, body) {
|
|
66
|
+
var f, y, t, g, _ = {
|
|
67
|
+
label: 0,
|
|
68
|
+
sent: function() {
|
|
69
|
+
if (t[0] & 1)
|
|
70
|
+
throw t[1];
|
|
71
|
+
return t[1];
|
|
72
|
+
},
|
|
73
|
+
trys: [],
|
|
74
|
+
ops: []
|
|
75
|
+
};
|
|
76
|
+
return g = {
|
|
77
|
+
next: verb(0),
|
|
78
|
+
"throw": verb(1),
|
|
79
|
+
"return": verb(2)
|
|
80
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
81
|
+
return this;
|
|
82
|
+
}), g;
|
|
83
|
+
function verb(n) {
|
|
84
|
+
return function(v) {
|
|
85
|
+
return step([
|
|
86
|
+
n,
|
|
87
|
+
v
|
|
88
|
+
]);
|
|
71
89
|
};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
break;
|
|
100
|
-
case 4:
|
|
101
|
-
_.label++;
|
|
102
|
-
return {
|
|
103
|
-
value: op[1],
|
|
104
|
-
done: false
|
|
105
|
-
};
|
|
106
|
-
case 5:
|
|
107
|
-
_.label++;
|
|
108
|
-
y = op[1];
|
|
109
|
-
op = [
|
|
110
|
-
0
|
|
111
|
-
];
|
|
112
|
-
continue;
|
|
113
|
-
case 7:
|
|
114
|
-
op = _.ops.pop();
|
|
115
|
-
_.trys.pop();
|
|
116
|
-
continue;
|
|
117
|
-
default:
|
|
118
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
119
|
-
_ = 0;
|
|
120
|
-
continue;
|
|
121
|
-
}
|
|
122
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
123
|
-
_.label = op[1];
|
|
124
|
-
break;
|
|
125
|
-
}
|
|
126
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
127
|
-
_.label = t[1];
|
|
128
|
-
t = op;
|
|
129
|
-
break;
|
|
130
|
-
}
|
|
131
|
-
if (t && _.label < t[2]) {
|
|
132
|
-
_.label = t[2];
|
|
133
|
-
_.ops.push(op);
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
if (t[2]) _.ops.pop();
|
|
137
|
-
_.trys.pop();
|
|
138
|
-
continue;
|
|
139
|
-
}
|
|
140
|
-
op = body.call(thisArg, _);
|
|
141
|
-
} catch (e) {
|
|
90
|
+
}
|
|
91
|
+
function step(op) {
|
|
92
|
+
if (f)
|
|
93
|
+
throw new TypeError("Generator is already executing.");
|
|
94
|
+
while (_)
|
|
95
|
+
try {
|
|
96
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
|
|
97
|
+
return t;
|
|
98
|
+
if (y = 0, t)
|
|
99
|
+
op = [
|
|
100
|
+
op[0] & 2,
|
|
101
|
+
t.value
|
|
102
|
+
];
|
|
103
|
+
switch (op[0]) {
|
|
104
|
+
case 0:
|
|
105
|
+
case 1:
|
|
106
|
+
t = op;
|
|
107
|
+
break;
|
|
108
|
+
case 4:
|
|
109
|
+
_.label++;
|
|
110
|
+
return {
|
|
111
|
+
value: op[1],
|
|
112
|
+
done: false
|
|
113
|
+
};
|
|
114
|
+
case 5:
|
|
115
|
+
_.label++;
|
|
116
|
+
y = op[1];
|
|
142
117
|
op = [
|
|
143
|
-
|
|
144
|
-
e
|
|
118
|
+
0
|
|
145
119
|
];
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
120
|
+
continue;
|
|
121
|
+
case 7:
|
|
122
|
+
op = _.ops.pop();
|
|
123
|
+
_.trys.pop();
|
|
124
|
+
continue;
|
|
125
|
+
default:
|
|
126
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
127
|
+
_ = 0;
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
131
|
+
_.label = op[1];
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
135
|
+
_.label = t[1];
|
|
136
|
+
t = op;
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
if (t && _.label < t[2]) {
|
|
140
|
+
_.label = t[2];
|
|
141
|
+
_.ops.push(op);
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
if (t[2])
|
|
145
|
+
_.ops.pop();
|
|
146
|
+
_.trys.pop();
|
|
147
|
+
continue;
|
|
149
148
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
149
|
+
op = body.call(thisArg, _);
|
|
150
|
+
} catch (e) {
|
|
151
|
+
op = [
|
|
152
|
+
6,
|
|
153
|
+
e
|
|
154
|
+
];
|
|
155
|
+
y = 0;
|
|
156
|
+
} finally {
|
|
157
|
+
f = t = 0;
|
|
158
|
+
}
|
|
159
|
+
if (op[0] & 5)
|
|
160
|
+
throw op[1];
|
|
161
|
+
return {
|
|
162
|
+
value: op[0] ? op[1] : void 0,
|
|
163
|
+
done: true
|
|
164
|
+
};
|
|
165
|
+
}
|
|
156
166
|
};
|
|
157
167
|
import crypto from "crypto";
|
|
158
168
|
import LRUCache from "lru-cache";
|
|
@@ -165,329 +175,328 @@ var BASE_LEVEL = 0;
|
|
|
165
175
|
var QUERY_LEVEL = 1;
|
|
166
176
|
var HEADER_LEVEL = 2;
|
|
167
177
|
var QUERY_HEADER_LEVEL = 3;
|
|
168
|
-
var CacheManager =
|
|
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
|
-
|
|
178
|
+
var CacheManager = /* @__PURE__ */ function() {
|
|
179
|
+
"use strict";
|
|
180
|
+
function CacheManager2(cacheOptions) {
|
|
181
|
+
var _this = this;
|
|
182
|
+
_class_call_check(this, CacheManager2);
|
|
183
|
+
_define_property(this, "cache", void 0);
|
|
184
|
+
_define_property(this, "cacheOptions", void 0);
|
|
185
|
+
_define_property(this, "find", function() {
|
|
186
|
+
{
|
|
187
|
+
var _this1 = _this;
|
|
188
|
+
var _obj;
|
|
189
|
+
return _obj = {}, _define_property(_obj, fname(BASE_LEVEL), function(context, cacheKey) {
|
|
190
|
+
return _this1.md5(cacheKey);
|
|
191
|
+
}), _define_property(_obj, fname(QUERY_LEVEL), function(context, cacheKey, data) {
|
|
192
|
+
var queryFactor = _this1.queryFactor(context, data);
|
|
193
|
+
if (!queryFactor) {
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
return _this1.md5(connectFactor(cacheKey, queryFactor));
|
|
197
|
+
}), _define_property(_obj, fname(HEADER_LEVEL), function(context, cacheKey, data) {
|
|
198
|
+
var headerFactor = _this1.headerFactor(context, data);
|
|
199
|
+
if (!headerFactor) {
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
return _this1.md5(connectFactor(cacheKey, headerFactor));
|
|
203
|
+
}), _define_property(_obj, fname(QUERY_HEADER_LEVEL), function(context, cacheKey, data) {
|
|
204
|
+
var queryFactor = _this1.queryFactor(context, data);
|
|
205
|
+
var headerFactor = _this1.headerFactor(context, data);
|
|
206
|
+
if (!queryFactor || !headerFactor) {
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
return _this1.md5(connectFactor(cacheKey, headerFactor, queryFactor));
|
|
210
|
+
}), _obj;
|
|
211
|
+
}
|
|
212
|
+
}());
|
|
213
|
+
this.cacheOptions = cacheOptions;
|
|
214
|
+
this.cache = new LRUCache({
|
|
215
|
+
max: Math.min(MAX_SIZE_EACH_CLUSTER, 600) * 1024 * 1024,
|
|
216
|
+
length: function length(n) {
|
|
217
|
+
var len = n.caches.keys().reduce(function(total, cur) {
|
|
218
|
+
var _n_caches_peek;
|
|
219
|
+
return total + (((_n_caches_peek = n.caches.peek(cur)) === null || _n_caches_peek === void 0 ? void 0 : _n_caches_peek.size) || 0);
|
|
220
|
+
}, 1);
|
|
221
|
+
return len;
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
_create_class(CacheManager2, [
|
|
226
|
+
{
|
|
227
|
+
key: "md5",
|
|
228
|
+
value: function md5(content) {
|
|
229
|
+
var md52 = crypto.createHash("md5");
|
|
230
|
+
return md52.update(content).digest("hex");
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
key: "generateRequestKey",
|
|
235
|
+
value: function generateRequestKey(context) {
|
|
236
|
+
var pathname = context.pathname, entry = context.entry;
|
|
237
|
+
return this.md5("".concat(pathname, "_").concat(entry));
|
|
238
|
+
}
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
key: "replaceValue",
|
|
242
|
+
value: function replaceValue(value, matcher) {
|
|
243
|
+
var final = value;
|
|
244
|
+
Object.keys(matcher).some(function(replacer) {
|
|
245
|
+
var reg = new RegExp(matcher[replacer]);
|
|
246
|
+
if (reg.test(value)) {
|
|
247
|
+
final = replacer;
|
|
248
|
+
return true;
|
|
249
|
+
}
|
|
250
|
+
return false;
|
|
214
251
|
});
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
key
|
|
233
|
-
value
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
252
|
+
return final;
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
key: "factor",
|
|
257
|
+
value: function factor(keys, obj) {
|
|
258
|
+
var matches = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
259
|
+
var _this = this;
|
|
260
|
+
keys.sort();
|
|
261
|
+
var getValue = valueFactory(obj);
|
|
262
|
+
var factorAry = keys.reduce(function(ary, key) {
|
|
263
|
+
var value = getValue(key) || "";
|
|
264
|
+
var matcher = matches[key];
|
|
265
|
+
if (matcher) {
|
|
266
|
+
value = _this.replaceValue(value, matcher);
|
|
267
|
+
}
|
|
268
|
+
return ary.concat([
|
|
269
|
+
key,
|
|
270
|
+
value
|
|
271
|
+
]);
|
|
272
|
+
}, []);
|
|
273
|
+
return factorAry.join(",");
|
|
274
|
+
}
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
key: "queryFactor",
|
|
278
|
+
value: function queryFactor(context, data) {
|
|
279
|
+
var _data_includes, _data_matches;
|
|
280
|
+
var queryKeys = (_data_includes = data.includes) === null || _data_includes === void 0 ? void 0 : _data_includes.query;
|
|
281
|
+
var queryMatches = (_data_matches = data.matches) === null || _data_matches === void 0 ? void 0 : _data_matches.query;
|
|
282
|
+
if (!queryKeys || queryKeys.length === 0) {
|
|
283
|
+
return null;
|
|
284
|
+
}
|
|
285
|
+
var requestQuery = context.query;
|
|
286
|
+
var queryFactor2 = this.factor(queryKeys, requestQuery, queryMatches);
|
|
287
|
+
return queryFactor2;
|
|
288
|
+
}
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
key: "headerFactor",
|
|
292
|
+
value: function headerFactor(context, data) {
|
|
293
|
+
var _data_includes, _data_matches;
|
|
294
|
+
var headerKeys = (_data_includes = data.includes) === null || _data_includes === void 0 ? void 0 : _data_includes.header;
|
|
295
|
+
var headerMatches = (_data_matches = data.matches) === null || _data_matches === void 0 ? void 0 : _data_matches.header;
|
|
296
|
+
if (!headerKeys || headerKeys.length === 0) {
|
|
297
|
+
return null;
|
|
298
|
+
}
|
|
299
|
+
var requestHeader = context.headers;
|
|
300
|
+
var headerFactor2 = this.factor(headerKeys, requestHeader, headerMatches);
|
|
301
|
+
return headerFactor2;
|
|
302
|
+
}
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
key: "best",
|
|
306
|
+
value: function best(context, cacheKey, data) {
|
|
307
|
+
var _this = this;
|
|
308
|
+
return _async_to_generator(function() {
|
|
309
|
+
var level, cacheHash;
|
|
310
|
+
return __generator(this, function(_state) {
|
|
311
|
+
level = data.level;
|
|
312
|
+
cacheHash = _this.find[fname(level)](context, cacheKey, data);
|
|
313
|
+
if (!cacheHash) {
|
|
314
|
+
return [
|
|
315
|
+
2,
|
|
316
|
+
null
|
|
317
|
+
];
|
|
265
318
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
319
|
+
return [
|
|
320
|
+
2,
|
|
321
|
+
data.caches.get(cacheHash)
|
|
322
|
+
];
|
|
323
|
+
});
|
|
324
|
+
})();
|
|
325
|
+
}
|
|
326
|
+
},
|
|
327
|
+
{
|
|
328
|
+
key: "createCacheContent",
|
|
329
|
+
value: function createCacheContent(config, caches) {
|
|
330
|
+
return {
|
|
331
|
+
level: config.level,
|
|
332
|
+
interval: config.interval,
|
|
333
|
+
includes: config.includes || null,
|
|
334
|
+
limit: config.staleLimit,
|
|
335
|
+
matches: config.matches || null,
|
|
336
|
+
caches
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
},
|
|
340
|
+
{
|
|
341
|
+
key: "get",
|
|
342
|
+
value: function get(context) {
|
|
343
|
+
var _this = this;
|
|
344
|
+
return _async_to_generator(function() {
|
|
345
|
+
var cacheKey, data, dest, expireTime, limitTime, html, cacheHash, isStale, isGarbage;
|
|
346
|
+
return __generator(this, function(_state) {
|
|
347
|
+
switch (_state.label) {
|
|
348
|
+
case 0:
|
|
349
|
+
cacheKey = _this.generateRequestKey(context);
|
|
350
|
+
data = _this.cache.get(cacheKey);
|
|
351
|
+
if (!data) {
|
|
352
|
+
return [
|
|
353
|
+
2,
|
|
354
|
+
null
|
|
355
|
+
];
|
|
275
356
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
if (!headerKeys || headerKeys.length === 0) {
|
|
288
|
-
return null;
|
|
357
|
+
return [
|
|
358
|
+
4,
|
|
359
|
+
_this.best(context, cacheKey, data)
|
|
360
|
+
];
|
|
361
|
+
case 1:
|
|
362
|
+
dest = _state.sent();
|
|
363
|
+
if (!dest) {
|
|
364
|
+
return [
|
|
365
|
+
2,
|
|
366
|
+
null
|
|
367
|
+
];
|
|
289
368
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
369
|
+
expireTime = dest.expireTime, limitTime = dest.limitTime, html = dest.html, cacheHash = dest.cacheHash;
|
|
370
|
+
isStale = Date.now() - expireTime > 0;
|
|
371
|
+
isGarbage = limitTime ? Date.now() - limitTime > 0 : false;
|
|
372
|
+
return [
|
|
373
|
+
2,
|
|
374
|
+
{
|
|
375
|
+
content: html || "",
|
|
376
|
+
contentType: mime.contentType("html"),
|
|
377
|
+
isStale,
|
|
378
|
+
isGarbage,
|
|
379
|
+
hash: cacheHash
|
|
380
|
+
}
|
|
381
|
+
];
|
|
293
382
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
383
|
+
});
|
|
384
|
+
})();
|
|
385
|
+
}
|
|
386
|
+
},
|
|
387
|
+
{
|
|
388
|
+
key: "set",
|
|
389
|
+
value: function set(context, html, cacheConfig) {
|
|
390
|
+
var sync = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : false;
|
|
391
|
+
var _this = this;
|
|
392
|
+
return _async_to_generator(function() {
|
|
393
|
+
var cacheKey, data, caches, cacheHash, cacheSyncOrAsync, doCache;
|
|
394
|
+
return __generator(this, function(_state) {
|
|
395
|
+
switch (_state.label) {
|
|
396
|
+
case 0:
|
|
397
|
+
if (!cacheConfig) {
|
|
398
|
+
return [
|
|
399
|
+
2,
|
|
400
|
+
false
|
|
401
|
+
];
|
|
402
|
+
}
|
|
403
|
+
cacheKey = _this.generateRequestKey(context);
|
|
404
|
+
data = _this.cache.get(cacheKey);
|
|
405
|
+
if (!!data)
|
|
406
|
+
return [
|
|
407
|
+
3,
|
|
408
|
+
2
|
|
409
|
+
];
|
|
410
|
+
return [
|
|
411
|
+
4,
|
|
412
|
+
createPageCaches(MAX_CACHE_EACH_REQ)
|
|
413
|
+
];
|
|
414
|
+
case 1:
|
|
415
|
+
caches = _state.sent();
|
|
416
|
+
data = _this.createCacheContent(cacheConfig, caches);
|
|
417
|
+
_state.label = 2;
|
|
418
|
+
case 2:
|
|
419
|
+
cacheHash = _this.find[fname(cacheConfig.level)](context, cacheKey, data);
|
|
420
|
+
if (!cacheHash) {
|
|
421
|
+
return [
|
|
422
|
+
2,
|
|
423
|
+
false
|
|
424
|
+
];
|
|
425
|
+
}
|
|
426
|
+
cacheSyncOrAsync = function() {
|
|
427
|
+
var _ref = _async_to_generator(function() {
|
|
428
|
+
var next, limit, storeHTML, size;
|
|
429
|
+
return __generator(this, function(_state2) {
|
|
430
|
+
switch (_state2.label) {
|
|
431
|
+
case 0:
|
|
432
|
+
next = data;
|
|
433
|
+
limit = cacheConfig.staleLimit;
|
|
434
|
+
storeHTML = cacheAddition(html, cacheHash);
|
|
435
|
+
size = storeHTML.length;
|
|
436
|
+
return [
|
|
437
|
+
4,
|
|
438
|
+
next.caches.set(cacheHash, {
|
|
439
|
+
expireTime: Date.now() + cacheConfig.interval * 1e3,
|
|
440
|
+
limitTime: typeof limit === "number" ? Date.now() + limit * 1e3 : null,
|
|
441
|
+
cacheHash,
|
|
442
|
+
html: storeHTML,
|
|
443
|
+
size
|
|
444
|
+
})
|
|
445
|
+
];
|
|
446
|
+
case 1:
|
|
447
|
+
_state2.sent();
|
|
448
|
+
_this.cache.set(cacheKey, next);
|
|
449
|
+
return [
|
|
311
450
|
2,
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
})();
|
|
316
|
-
}
|
|
317
|
-
},
|
|
318
|
-
{
|
|
319
|
-
key: "createCacheContent",
|
|
320
|
-
value: function createCacheContent(config, caches) {
|
|
321
|
-
return {
|
|
322
|
-
level: config.level,
|
|
323
|
-
interval: config.interval,
|
|
324
|
-
includes: config.includes || null,
|
|
325
|
-
limit: config.staleLimit,
|
|
326
|
-
matches: config.matches || null,
|
|
327
|
-
caches: caches
|
|
328
|
-
};
|
|
329
|
-
}
|
|
330
|
-
},
|
|
331
|
-
{
|
|
332
|
-
key: "get",
|
|
333
|
-
value: function get(context) {
|
|
334
|
-
var _this = this;
|
|
335
|
-
return _asyncToGenerator(function() {
|
|
336
|
-
var cacheKey, data, dest, expireTime, limitTime, html, cacheHash, isStale, isGarbage;
|
|
337
|
-
return __generator(this, function(_state) {
|
|
338
|
-
switch(_state.label){
|
|
339
|
-
case 0:
|
|
340
|
-
cacheKey = _this.generateRequestKey(context);
|
|
341
|
-
data = _this.cache.get(cacheKey);
|
|
342
|
-
if (!data) {
|
|
343
|
-
return [
|
|
344
|
-
2,
|
|
345
|
-
null
|
|
346
|
-
];
|
|
347
|
-
}
|
|
348
|
-
return [
|
|
349
|
-
4,
|
|
350
|
-
_this.best(context, cacheKey, data)
|
|
351
|
-
];
|
|
352
|
-
case 1:
|
|
353
|
-
dest = _state.sent();
|
|
354
|
-
if (!dest) {
|
|
355
|
-
return [
|
|
356
|
-
2,
|
|
357
|
-
null
|
|
358
|
-
];
|
|
359
|
-
}
|
|
360
|
-
expireTime = dest.expireTime, limitTime = dest.limitTime, html = dest.html, cacheHash = dest.cacheHash;
|
|
361
|
-
isStale = Date.now() - expireTime > 0;
|
|
362
|
-
isGarbage = limitTime ? Date.now() - limitTime > 0 : false;
|
|
363
|
-
return [
|
|
364
|
-
2,
|
|
365
|
-
{
|
|
366
|
-
content: html || "",
|
|
367
|
-
contentType: mime.contentType("html"),
|
|
368
|
-
isStale: isStale,
|
|
369
|
-
isGarbage: isGarbage,
|
|
370
|
-
hash: cacheHash
|
|
371
|
-
}
|
|
372
|
-
];
|
|
373
|
-
}
|
|
374
|
-
});
|
|
375
|
-
})();
|
|
376
|
-
}
|
|
377
|
-
},
|
|
378
|
-
{
|
|
379
|
-
key: "set",
|
|
380
|
-
value: function set(context, html, cacheConfig) {
|
|
381
|
-
var sync = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : false;
|
|
382
|
-
var _this = this;
|
|
383
|
-
return _asyncToGenerator(function() {
|
|
384
|
-
var cacheKey, data, caches, cacheHash, cacheSyncOrAsync, doCache;
|
|
385
|
-
return __generator(this, function(_state) {
|
|
386
|
-
switch(_state.label){
|
|
387
|
-
case 0:
|
|
388
|
-
if (!cacheConfig) {
|
|
389
|
-
return [
|
|
390
|
-
2,
|
|
391
|
-
false
|
|
392
|
-
];
|
|
393
|
-
}
|
|
394
|
-
cacheKey = _this.generateRequestKey(context);
|
|
395
|
-
data = _this.cache.get(cacheKey);
|
|
396
|
-
if (!!data) return [
|
|
397
|
-
3,
|
|
398
|
-
2
|
|
399
|
-
];
|
|
400
|
-
return [
|
|
401
|
-
4,
|
|
402
|
-
createPageCaches(MAX_CACHE_EACH_REQ)
|
|
403
|
-
];
|
|
404
|
-
case 1:
|
|
405
|
-
caches = _state.sent();
|
|
406
|
-
data = _this.createCacheContent(cacheConfig, caches);
|
|
407
|
-
_state.label = 2;
|
|
408
|
-
case 2:
|
|
409
|
-
cacheHash = _this.find[fname(cacheConfig.level)](context, cacheKey, data);
|
|
410
|
-
if (!cacheHash) {
|
|
411
|
-
return [
|
|
412
|
-
2,
|
|
413
|
-
false
|
|
414
|
-
];
|
|
415
|
-
}
|
|
416
|
-
cacheSyncOrAsync = function() {
|
|
417
|
-
var _ref = _asyncToGenerator(function() {
|
|
418
|
-
var next, limit, storeHTML, size;
|
|
419
|
-
return __generator(this, function(_state) {
|
|
420
|
-
switch(_state.label){
|
|
421
|
-
case 0:
|
|
422
|
-
next = data;
|
|
423
|
-
limit = cacheConfig.staleLimit;
|
|
424
|
-
storeHTML = cacheAddition(html, cacheHash);
|
|
425
|
-
size = storeHTML.length;
|
|
426
|
-
return [
|
|
427
|
-
4,
|
|
428
|
-
next.caches.set(cacheHash, {
|
|
429
|
-
expireTime: Date.now() + cacheConfig.interval * 1e3,
|
|
430
|
-
limitTime: typeof limit === "number" ? Date.now() + limit * 1e3 : null,
|
|
431
|
-
cacheHash: cacheHash,
|
|
432
|
-
html: storeHTML,
|
|
433
|
-
size: size
|
|
434
|
-
})
|
|
435
|
-
];
|
|
436
|
-
case 1:
|
|
437
|
-
_state.sent();
|
|
438
|
-
_this.cache.set(cacheKey, next);
|
|
439
|
-
return [
|
|
440
|
-
2,
|
|
441
|
-
true
|
|
442
|
-
];
|
|
443
|
-
}
|
|
444
|
-
});
|
|
445
|
-
});
|
|
446
|
-
return function cacheSyncOrAsync() {
|
|
447
|
-
return _ref.apply(this, arguments);
|
|
448
|
-
};
|
|
449
|
-
}();
|
|
450
|
-
doCache = withCoalescedInvoke(cacheSyncOrAsync).bind(null, namespaceHash("stream", cacheHash), []);
|
|
451
|
-
return [
|
|
452
|
-
2,
|
|
453
|
-
maybeSync(doCache)(sync)
|
|
454
|
-
];
|
|
455
|
-
}
|
|
456
|
-
});
|
|
457
|
-
})();
|
|
458
|
-
}
|
|
459
|
-
},
|
|
460
|
-
{
|
|
461
|
-
key: "del",
|
|
462
|
-
value: function del(context, cacheHash) {
|
|
463
|
-
var _this = this;
|
|
464
|
-
return _asyncToGenerator(function() {
|
|
465
|
-
var cacheKey, data;
|
|
466
|
-
return __generator(this, function(_state) {
|
|
467
|
-
cacheKey = _this.generateRequestKey(context);
|
|
468
|
-
data = _this.cache.get(cacheKey);
|
|
469
|
-
data === null || data === void 0 ? void 0 : data.caches.del(cacheHash);
|
|
470
|
-
return [
|
|
471
|
-
2
|
|
472
|
-
];
|
|
451
|
+
true
|
|
452
|
+
];
|
|
453
|
+
}
|
|
473
454
|
});
|
|
474
|
-
|
|
455
|
+
});
|
|
456
|
+
return function cacheSyncOrAsync2() {
|
|
457
|
+
return _ref.apply(this, arguments);
|
|
458
|
+
};
|
|
459
|
+
}();
|
|
460
|
+
doCache = withCoalescedInvoke(cacheSyncOrAsync).bind(null, namespaceHash("stream", cacheHash), []);
|
|
461
|
+
return [
|
|
462
|
+
2,
|
|
463
|
+
maybeSync(doCache)(sync)
|
|
464
|
+
];
|
|
475
465
|
}
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
466
|
+
});
|
|
467
|
+
})();
|
|
468
|
+
}
|
|
469
|
+
},
|
|
470
|
+
{
|
|
471
|
+
key: "del",
|
|
472
|
+
value: function del(context, cacheHash) {
|
|
473
|
+
var _this = this;
|
|
474
|
+
return _async_to_generator(function() {
|
|
475
|
+
var cacheKey, data;
|
|
476
|
+
return __generator(this, function(_state) {
|
|
477
|
+
cacheKey = _this.generateRequestKey(context);
|
|
478
|
+
data = _this.cache.get(cacheKey);
|
|
479
|
+
data === null || data === void 0 ? void 0 : data.caches.del(cacheHash);
|
|
480
|
+
return [
|
|
481
|
+
2
|
|
482
|
+
];
|
|
483
|
+
});
|
|
484
|
+
})();
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
]);
|
|
488
|
+
return CacheManager2;
|
|
479
489
|
}();
|
|
480
490
|
var manager;
|
|
481
|
-
function createCache() {
|
|
482
|
-
|
|
483
|
-
return manager;
|
|
484
|
-
}
|
|
485
|
-
manager = new CacheManager({
|
|
486
|
-
max: 0
|
|
487
|
-
});
|
|
491
|
+
export function createCache() {
|
|
492
|
+
if (manager) {
|
|
488
493
|
return manager;
|
|
494
|
+
}
|
|
495
|
+
manager = new CacheManager({
|
|
496
|
+
max: 0
|
|
497
|
+
});
|
|
498
|
+
return manager;
|
|
489
499
|
}
|
|
490
|
-
function destroyCache() {
|
|
491
|
-
|
|
500
|
+
export function destroyCache() {
|
|
501
|
+
manager = null;
|
|
492
502
|
}
|
|
493
|
-
export { createCache, destroyCache };
|