@modern-js/prod-server 1.22.1 → 2.0.0-alpha.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 +271 -17
- package/dist/js/modern/constants.js +32 -27
- package/dist/js/modern/index.js +11 -7
- package/dist/js/modern/libs/context/context.js +54 -132
- package/dist/js/modern/libs/context/index.js +5 -2
- package/dist/js/modern/libs/hook-api/index.js +134 -0
- package/dist/js/modern/libs/hook-api/route.js +13 -37
- package/dist/js/modern/libs/hook-api/template.js +41 -32
- package/dist/js/modern/libs/loadConfig.js +46 -32
- package/dist/js/modern/libs/metrics.js +6 -7
- package/dist/js/modern/libs/proxy.js +70 -44
- package/dist/js/modern/libs/render/cache/__tests__/cache.fun.test.js +112 -68
- package/dist/js/modern/libs/render/cache/__tests__/cache.test.js +246 -225
- 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 +93 -50
- 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 -16
- package/dist/js/modern/libs/render/cache/spr.js +133 -167
- package/dist/js/modern/libs/render/cache/type.js +0 -1
- package/dist/js/modern/libs/render/cache/util.js +71 -45
- package/dist/js/modern/libs/render/index.js +76 -61
- package/dist/js/modern/libs/render/measure.js +42 -34
- package/dist/js/modern/libs/render/reader.js +68 -76
- package/dist/js/modern/libs/render/ssr.js +63 -33
- package/dist/js/modern/libs/render/static.js +51 -37
- package/dist/js/modern/libs/render/type.js +9 -7
- package/dist/js/modern/libs/route/index.js +12 -30
- package/dist/js/modern/libs/route/matcher.js +28 -50
- package/dist/js/modern/libs/route/route.js +9 -31
- package/dist/js/modern/libs/serve-file.js +40 -20
- package/dist/js/modern/server/index.js +152 -168
- package/dist/js/modern/server/modern-server-split.js +44 -60
- package/dist/js/modern/server/modern-server.js +416 -526
- package/dist/js/modern/type.js +0 -1
- package/dist/js/modern/utils.js +62 -58
- package/dist/js/modern/worker-server.js +54 -0
- package/dist/js/node/constants.js +53 -32
- package/dist/js/node/index.js +37 -67
- package/dist/js/node/libs/context/context.js +84 -150
- package/dist/js/node/libs/context/index.js +28 -16
- package/dist/js/node/libs/hook-api/index.js +164 -0
- package/dist/js/node/libs/hook-api/route.js +35 -45
- package/dist/js/node/libs/hook-api/template.js +64 -40
- package/dist/js/node/libs/loadConfig.js +74 -55
- package/dist/js/node/libs/metrics.js +28 -12
- package/dist/js/node/libs/proxy.js +90 -55
- package/dist/js/node/libs/render/cache/__tests__/cache.fun.test.js +99 -61
- package/dist/js/node/libs/render/cache/__tests__/cache.test.js +147 -140
- 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 +115 -65
- package/dist/js/node/libs/render/cache/page-caches/index.js +54 -16
- package/dist/js/node/libs/render/cache/page-caches/lru.js +33 -26
- package/dist/js/node/libs/render/cache/spr.js +161 -188
- package/dist/js/node/libs/render/cache/type.js +15 -5
- package/dist/js/node/libs/render/cache/util.js +99 -63
- package/dist/js/node/libs/render/index.js +106 -87
- package/dist/js/node/libs/render/measure.js +61 -44
- package/dist/js/node/libs/render/reader.js +98 -100
- package/dist/js/node/libs/render/ssr.js +92 -58
- package/dist/js/node/libs/render/static.js +80 -53
- package/dist/js/node/libs/render/type.js +31 -13
- package/dist/js/node/libs/route/index.js +35 -44
- package/dist/js/node/libs/route/matcher.js +48 -65
- package/dist/js/node/libs/route/route.js +29 -37
- package/dist/js/node/libs/serve-file.js +74 -37
- package/dist/js/node/server/index.js +170 -203
- package/dist/js/node/server/modern-server-split.js +70 -73
- package/dist/js/node/server/modern-server.js +432 -577
- package/dist/js/node/type.js +15 -3
- package/dist/js/node/utils.js +87 -93
- package/dist/js/node/worker-server.js +77 -0
- package/dist/js/treeshaking/constants.js +29 -0
- package/dist/js/treeshaking/index.js +13 -0
- package/dist/js/treeshaking/libs/context/context.js +274 -0
- package/dist/js/treeshaking/libs/context/index.js +5 -0
- package/dist/js/treeshaking/libs/hook-api/index.js +281 -0
- package/dist/js/treeshaking/libs/hook-api/route.js +68 -0
- package/dist/js/treeshaking/libs/hook-api/template.js +127 -0
- package/dist/js/treeshaking/libs/loadConfig.js +82 -0
- package/dist/js/treeshaking/libs/metrics.js +6 -0
- package/dist/js/treeshaking/libs/proxy.js +244 -0
- package/dist/js/treeshaking/libs/render/cache/__tests__/cache.fun.test.js +291 -0
- package/dist/js/treeshaking/libs/render/cache/__tests__/cache.test.js +781 -0
- package/dist/js/treeshaking/libs/render/cache/__tests__/cacheable.js +67 -0
- package/dist/js/treeshaking/libs/render/cache/__tests__/error-configuration.js +45 -0
- package/dist/js/treeshaking/libs/render/cache/__tests__/matched-cache.js +147 -0
- package/dist/js/treeshaking/libs/render/cache/index.js +346 -0
- package/dist/js/treeshaking/libs/render/cache/page-caches/index.js +154 -0
- package/dist/js/treeshaking/libs/render/cache/page-caches/lru.js +84 -0
- package/dist/js/treeshaking/libs/render/cache/spr.js +492 -0
- package/dist/js/treeshaking/libs/render/cache/type.js +1 -0
- package/dist/js/treeshaking/libs/render/cache/util.js +280 -0
- package/dist/js/treeshaking/libs/render/index.js +233 -0
- package/dist/js/treeshaking/libs/render/measure.js +146 -0
- package/dist/js/treeshaking/libs/render/reader.js +339 -0
- package/dist/js/treeshaking/libs/render/ssr.js +223 -0
- package/dist/js/treeshaking/libs/render/static.js +216 -0
- package/dist/js/treeshaking/libs/render/type.js +7 -0
- package/dist/js/treeshaking/libs/route/index.js +130 -0
- package/dist/js/treeshaking/libs/route/matcher.js +138 -0
- package/dist/js/treeshaking/libs/route/route.js +40 -0
- package/dist/js/treeshaking/libs/serve-file.js +184 -0
- package/dist/js/treeshaking/server/index.js +505 -0
- package/dist/js/treeshaking/server/modern-server-split.js +360 -0
- package/dist/js/treeshaking/server/modern-server.js +1083 -0
- package/dist/js/treeshaking/type.js +1 -0
- package/dist/js/treeshaking/utils.js +147 -0
- package/dist/js/treeshaking/worker-server.js +177 -0
- package/dist/types/libs/context/context.d.ts +1 -1
- 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/render/cache/index.d.ts +4 -2
- package/dist/types/libs/render/type.d.ts +3 -1
- package/dist/types/libs/route/route.d.ts +0 -1
- package/dist/types/libs/serve-file.d.ts +2 -1
- package/dist/types/server/index.d.ts +2 -0
- package/dist/types/server/modern-server.d.ts +11 -11
- package/dist/types/type.d.ts +8 -10
- package/dist/types/utils.d.ts +3 -4
- package/dist/types/worker-server.d.ts +15 -0
- package/package.json +31 -45
- package/dist/js/modern/libs/render/modern/browser-list.js +0 -7
- package/dist/js/modern/libs/render/modern/index.js +0 -48
- package/dist/js/node/libs/render/modern/browser-list.js +0 -14
- package/dist/js/node/libs/render/modern/index.js +0 -64
- package/dist/types/libs/render/modern/browser-list.d.ts +0 -1
- package/dist/types/libs/render/modern/index.d.ts +0 -3
|
@@ -1,12 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
import crypto from "crypto";
|
|
22
|
+
import LRUCache from "lru-cache";
|
|
23
|
+
import { mime } from "@modern-js/utils";
|
|
24
|
+
import {
|
|
25
|
+
cacheAddition,
|
|
26
|
+
connectFactor,
|
|
27
|
+
fname,
|
|
28
|
+
maybeSync,
|
|
29
|
+
namespaceHash,
|
|
30
|
+
valueFactory,
|
|
31
|
+
withCoalescedInvoke
|
|
32
|
+
} from "./util";
|
|
10
33
|
import { createPageCaches } from "./page-caches";
|
|
11
34
|
const MAX_CACHE_EACH_REQ = Number(process.env.ROUTE_CACHE_LIMIT) || 10;
|
|
12
35
|
const MAX_SIZE_EACH_CLUSTER = Number(process.env.CLUSTER_CACHE_LIMIT) || 100;
|
|
@@ -14,164 +37,117 @@ const BASE_LEVEL = 0;
|
|
|
14
37
|
const QUERY_LEVEL = 1;
|
|
15
38
|
const HEADER_LEVEL = 2;
|
|
16
39
|
const QUERY_HEADER_LEVEL = 3;
|
|
17
|
-
|
|
18
40
|
class CacheManager {
|
|
19
41
|
constructor(cacheOptions) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
_defineProperty(this, "cacheOptions", void 0);
|
|
23
|
-
|
|
24
|
-
_defineProperty(this, "find", (() => {
|
|
42
|
+
this.find = (() => {
|
|
25
43
|
{
|
|
26
|
-
// eslint-disable-next-line consistent-this,@typescript-eslint/no-this-alias
|
|
27
44
|
const _this = this;
|
|
28
|
-
|
|
29
45
|
return {
|
|
30
|
-
[fname(BASE_LEVEL)](context, cacheKey
|
|
31
|
-
) {
|
|
46
|
+
[fname(BASE_LEVEL)](context, cacheKey) {
|
|
32
47
|
return _this.md5(cacheKey);
|
|
33
48
|
},
|
|
34
|
-
|
|
35
49
|
[fname(QUERY_LEVEL)](context, cacheKey, data) {
|
|
36
50
|
const queryFactor = _this.queryFactor(context, data);
|
|
37
|
-
|
|
38
51
|
if (!queryFactor) {
|
|
39
52
|
return null;
|
|
40
53
|
}
|
|
41
|
-
|
|
42
54
|
return _this.md5(connectFactor(cacheKey, queryFactor));
|
|
43
55
|
},
|
|
44
|
-
|
|
45
56
|
[fname(HEADER_LEVEL)](context, cacheKey, data) {
|
|
46
57
|
const headerFactor = _this.headerFactor(context, data);
|
|
47
|
-
|
|
48
58
|
if (!headerFactor) {
|
|
49
59
|
return null;
|
|
50
60
|
}
|
|
51
|
-
|
|
52
61
|
return _this.md5(connectFactor(cacheKey, headerFactor));
|
|
53
62
|
},
|
|
54
|
-
|
|
55
63
|
[fname(QUERY_HEADER_LEVEL)](context, cacheKey, data) {
|
|
56
64
|
const queryFactor = _this.queryFactor(context, data);
|
|
57
|
-
|
|
58
65
|
const headerFactor = _this.headerFactor(context, data);
|
|
59
|
-
|
|
60
66
|
if (!queryFactor || !headerFactor) {
|
|
61
67
|
return null;
|
|
62
68
|
}
|
|
63
|
-
|
|
64
69
|
return _this.md5(connectFactor(cacheKey, headerFactor, queryFactor));
|
|
65
70
|
}
|
|
66
|
-
|
|
67
71
|
};
|
|
68
72
|
}
|
|
69
|
-
})()
|
|
70
|
-
|
|
73
|
+
})();
|
|
71
74
|
this.cacheOptions = cacheOptions;
|
|
72
75
|
this.cache = new LRUCache({
|
|
73
76
|
max: Math.min(MAX_SIZE_EACH_CLUSTER, 600) * 1024 * 1024,
|
|
74
|
-
|
|
75
|
-
// 默认存 100M,最大 600M
|
|
76
77
|
length(n) {
|
|
77
78
|
const len = n.caches.keys().reduce((total, cur) => {
|
|
78
|
-
var
|
|
79
|
-
|
|
80
|
-
return total + (((_n$caches$peek = n.caches.peek(cur)) === null || _n$caches$peek === void 0 ? void 0 : _n$caches$peek.size) || 0);
|
|
79
|
+
var _a;
|
|
80
|
+
return total + (((_a = n.caches.peek(cur)) == null ? void 0 : _a.size) || 0);
|
|
81
81
|
}, 1);
|
|
82
82
|
return len;
|
|
83
83
|
}
|
|
84
|
-
|
|
85
84
|
});
|
|
86
85
|
}
|
|
87
|
-
|
|
88
86
|
md5(content) {
|
|
89
|
-
const md5 = crypto.createHash(
|
|
90
|
-
return md5.update(content).digest(
|
|
87
|
+
const md5 = crypto.createHash("md5");
|
|
88
|
+
return md5.update(content).digest("hex");
|
|
91
89
|
}
|
|
92
|
-
|
|
93
90
|
generateRequestKey(context) {
|
|
94
|
-
const {
|
|
95
|
-
pathname,
|
|
96
|
-
entry
|
|
97
|
-
} = context;
|
|
91
|
+
const { pathname, entry } = context;
|
|
98
92
|
return this.md5(`${pathname}_${entry}`);
|
|
99
93
|
}
|
|
100
|
-
|
|
101
94
|
replaceValue(value, matcher) {
|
|
102
95
|
let final = value;
|
|
103
|
-
Object.keys(matcher).some(replacer => {
|
|
96
|
+
Object.keys(matcher).some((replacer) => {
|
|
104
97
|
const reg = new RegExp(matcher[replacer]);
|
|
105
|
-
|
|
106
98
|
if (reg.test(value)) {
|
|
107
99
|
final = replacer;
|
|
108
100
|
return true;
|
|
109
101
|
}
|
|
110
|
-
|
|
111
102
|
return false;
|
|
112
103
|
});
|
|
113
104
|
return final;
|
|
114
105
|
}
|
|
115
|
-
|
|
116
106
|
factor(keys, obj, matches = {}) {
|
|
117
107
|
keys.sort();
|
|
118
108
|
const getValue = valueFactory(obj);
|
|
119
109
|
const factorAry = keys.reduce((ary, key) => {
|
|
120
|
-
let value = getValue(key) ||
|
|
110
|
+
let value = getValue(key) || "";
|
|
121
111
|
const matcher = matches[key];
|
|
122
|
-
|
|
123
112
|
if (matcher) {
|
|
124
113
|
value = this.replaceValue(value, matcher);
|
|
125
114
|
}
|
|
126
|
-
|
|
127
115
|
return ary.concat([key, value]);
|
|
128
116
|
}, []);
|
|
129
|
-
return factorAry.join(
|
|
117
|
+
return factorAry.join(",");
|
|
130
118
|
}
|
|
131
|
-
|
|
132
119
|
queryFactor(context, data) {
|
|
133
|
-
var
|
|
134
|
-
|
|
135
|
-
const
|
|
136
|
-
const queryMatches = (_data$matches = data.matches) === null || _data$matches === void 0 ? void 0 : _data$matches.query;
|
|
137
|
-
|
|
120
|
+
var _a, _b;
|
|
121
|
+
const queryKeys = (_a = data.includes) == null ? void 0 : _a.query;
|
|
122
|
+
const queryMatches = (_b = data.matches) == null ? void 0 : _b.query;
|
|
138
123
|
if (!queryKeys || queryKeys.length === 0) {
|
|
139
124
|
return null;
|
|
140
125
|
}
|
|
141
|
-
|
|
142
126
|
const requestQuery = context.query;
|
|
143
127
|
const queryFactor = this.factor(queryKeys, requestQuery, queryMatches);
|
|
144
128
|
return queryFactor;
|
|
145
129
|
}
|
|
146
|
-
|
|
147
130
|
headerFactor(context, data) {
|
|
148
|
-
var
|
|
149
|
-
|
|
150
|
-
const
|
|
151
|
-
const headerMatches = (_data$matches2 = data.matches) === null || _data$matches2 === void 0 ? void 0 : _data$matches2.header;
|
|
152
|
-
|
|
131
|
+
var _a, _b;
|
|
132
|
+
const headerKeys = (_a = data.includes) == null ? void 0 : _a.header;
|
|
133
|
+
const headerMatches = (_b = data.matches) == null ? void 0 : _b.header;
|
|
153
134
|
if (!headerKeys || headerKeys.length === 0) {
|
|
154
135
|
return null;
|
|
155
136
|
}
|
|
156
|
-
|
|
157
137
|
const requestHeader = context.headers;
|
|
158
138
|
const headerFactor = this.factor(headerKeys, requestHeader, headerMatches);
|
|
159
139
|
return headerFactor;
|
|
160
140
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
level
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
return data.caches.get(cacheHash);
|
|
141
|
+
best(context, cacheKey, data) {
|
|
142
|
+
return __async(this, null, function* () {
|
|
143
|
+
const { level } = data;
|
|
144
|
+
const cacheHash = this.find[fname(level)](context, cacheKey, data);
|
|
145
|
+
if (!cacheHash) {
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
return data.caches.get(cacheHash);
|
|
149
|
+
});
|
|
173
150
|
}
|
|
174
|
-
|
|
175
151
|
createCacheContent(config, caches) {
|
|
176
152
|
return {
|
|
177
153
|
level: config.level,
|
|
@@ -182,101 +158,91 @@ class CacheManager {
|
|
|
182
158
|
caches
|
|
183
159
|
};
|
|
184
160
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
const isGarbage = limitTime ? Date.now() - limitTime > 0 : false;
|
|
208
|
-
return {
|
|
209
|
-
content: html || '',
|
|
210
|
-
contentType: mime.contentType('html'),
|
|
211
|
-
isStale,
|
|
212
|
-
isGarbage,
|
|
213
|
-
hash: cacheHash
|
|
214
|
-
};
|
|
161
|
+
get(context) {
|
|
162
|
+
return __async(this, null, function* () {
|
|
163
|
+
const cacheKey = this.generateRequestKey(context);
|
|
164
|
+
const data = this.cache.get(cacheKey);
|
|
165
|
+
if (!data) {
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
const dest = yield this.best(context, cacheKey, data);
|
|
169
|
+
if (!dest) {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
const { expireTime, limitTime, html, cacheHash } = dest;
|
|
173
|
+
const isStale = Date.now() - expireTime > 0;
|
|
174
|
+
const isGarbage = limitTime ? Date.now() - limitTime > 0 : false;
|
|
175
|
+
return {
|
|
176
|
+
content: html || "",
|
|
177
|
+
contentType: mime.contentType("html"),
|
|
178
|
+
isStale,
|
|
179
|
+
isGarbage,
|
|
180
|
+
hash: cacheHash
|
|
181
|
+
};
|
|
182
|
+
});
|
|
215
183
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
184
|
+
set(context, html, cacheConfig, sync = false) {
|
|
185
|
+
return __async(this, null, function* () {
|
|
186
|
+
if (!cacheConfig) {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
const cacheKey = this.generateRequestKey(context);
|
|
190
|
+
let data = this.cache.get(cacheKey);
|
|
191
|
+
if (!data) {
|
|
192
|
+
const caches = yield createPageCaches(MAX_CACHE_EACH_REQ);
|
|
193
|
+
data = this.createCacheContent(cacheConfig, caches);
|
|
194
|
+
}
|
|
195
|
+
const cacheHash = this.find[fname(cacheConfig.level)](
|
|
196
|
+
context,
|
|
197
|
+
cacheKey,
|
|
198
|
+
data
|
|
199
|
+
);
|
|
200
|
+
if (!cacheHash) {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
const cacheSyncOrAsync = () => __async(this, null, function* () {
|
|
204
|
+
const next = data;
|
|
205
|
+
const limit = cacheConfig.staleLimit;
|
|
206
|
+
const storeHTML = cacheAddition(html, cacheHash);
|
|
207
|
+
const size = storeHTML.length;
|
|
208
|
+
yield next.caches.set(cacheHash, {
|
|
209
|
+
expireTime: Date.now() + cacheConfig.interval * 1e3,
|
|
210
|
+
limitTime: typeof limit === "number" ? Date.now() + limit * 1e3 : null,
|
|
211
|
+
cacheHash,
|
|
212
|
+
html: storeHTML,
|
|
213
|
+
size
|
|
214
|
+
});
|
|
215
|
+
this.cache.set(cacheKey, next);
|
|
216
|
+
return true;
|
|
248
217
|
});
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
218
|
+
const doCache = withCoalescedInvoke(cacheSyncOrAsync).bind(
|
|
219
|
+
null,
|
|
220
|
+
namespaceHash("stream", cacheHash),
|
|
221
|
+
[]
|
|
222
|
+
);
|
|
223
|
+
return maybeSync(doCache)(sync);
|
|
224
|
+
});
|
|
256
225
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
226
|
+
del(context, cacheHash) {
|
|
227
|
+
return __async(this, null, function* () {
|
|
228
|
+
const cacheKey = this.generateRequestKey(context);
|
|
229
|
+
const data = this.cache.get(cacheKey);
|
|
230
|
+
data == null ? void 0 : data.caches.del(cacheHash);
|
|
231
|
+
});
|
|
262
232
|
}
|
|
263
|
-
|
|
264
233
|
}
|
|
265
|
-
|
|
266
234
|
let manager;
|
|
267
|
-
|
|
235
|
+
function createCache() {
|
|
268
236
|
if (manager) {
|
|
269
237
|
return manager;
|
|
270
238
|
}
|
|
271
|
-
|
|
272
|
-
manager = new CacheManager({
|
|
273
|
-
max: 0
|
|
274
|
-
});
|
|
239
|
+
manager = new CacheManager({ max: 0 });
|
|
275
240
|
return manager;
|
|
276
241
|
}
|
|
277
|
-
|
|
242
|
+
function destroyCache() {
|
|
278
243
|
manager = null;
|
|
279
244
|
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
245
|
+
export {
|
|
246
|
+
createCache,
|
|
247
|
+
destroyCache
|
|
248
|
+
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,71 +1,87 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
import url from "url";
|
|
22
|
+
function namespaceHash(namespace, hash) {
|
|
3
23
|
return `${namespace}/${hash}`;
|
|
4
24
|
}
|
|
5
|
-
|
|
25
|
+
function fname(lv) {
|
|
6
26
|
return `f${lv}`;
|
|
7
27
|
}
|
|
8
|
-
|
|
9
|
-
return args.join(
|
|
28
|
+
function connectFactor(...args) {
|
|
29
|
+
return args.join("-");
|
|
10
30
|
}
|
|
11
|
-
|
|
31
|
+
function valueFactory(obj) {
|
|
12
32
|
if (obj instanceof url.URLSearchParams) {
|
|
13
|
-
return function
|
|
33
|
+
return function(key) {
|
|
14
34
|
return obj.get(key);
|
|
15
35
|
};
|
|
16
36
|
} else {
|
|
17
|
-
return function
|
|
37
|
+
return function(key) {
|
|
18
38
|
const value = obj[key];
|
|
19
|
-
|
|
20
39
|
if (Array.isArray(value)) {
|
|
21
|
-
return value.join(
|
|
40
|
+
return value.join(",");
|
|
22
41
|
}
|
|
23
|
-
|
|
24
42
|
return value;
|
|
25
43
|
};
|
|
26
44
|
}
|
|
27
45
|
}
|
|
28
|
-
|
|
46
|
+
function getTime([s, ns]) {
|
|
29
47
|
return Math.floor(s * 1e3 + ns / 1e6);
|
|
30
48
|
}
|
|
31
49
|
const RE_START_IN_HEAD = /<head>/;
|
|
32
|
-
|
|
33
|
-
const additionHtml = html.replace(
|
|
50
|
+
function cacheAddition(html, hash) {
|
|
51
|
+
const additionHtml = html.replace(
|
|
52
|
+
RE_START_IN_HEAD,
|
|
53
|
+
`<head><meta name="x-moden-spr" content="${hash}">`
|
|
54
|
+
);
|
|
34
55
|
return additionHtml;
|
|
35
56
|
}
|
|
36
|
-
const globalInvokeCache = new Map();
|
|
37
|
-
|
|
38
|
-
return
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
globalInvokeCache.delete(key);
|
|
60
|
-
throw err;
|
|
57
|
+
const globalInvokeCache = /* @__PURE__ */ new Map();
|
|
58
|
+
function withCoalescedInvoke(func) {
|
|
59
|
+
return function(key, args) {
|
|
60
|
+
return __async(this, null, function* () {
|
|
61
|
+
const entry = globalInvokeCache.get(key);
|
|
62
|
+
if (entry) {
|
|
63
|
+
return entry.then((res) => ({
|
|
64
|
+
isOrigin: false,
|
|
65
|
+
value: res.value
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
function __wrapper() {
|
|
69
|
+
return func(...args);
|
|
70
|
+
}
|
|
71
|
+
const future = __wrapper().then((res) => {
|
|
72
|
+
globalInvokeCache.delete(key);
|
|
73
|
+
return { isOrigin: true, value: res };
|
|
74
|
+
}).catch((err) => {
|
|
75
|
+
globalInvokeCache.delete(key);
|
|
76
|
+
throw err;
|
|
77
|
+
});
|
|
78
|
+
globalInvokeCache.set(key, future);
|
|
79
|
+
return future;
|
|
61
80
|
});
|
|
62
|
-
|
|
63
|
-
globalInvokeCache.set(key, future);
|
|
64
|
-
return future;
|
|
65
81
|
};
|
|
66
82
|
}
|
|
67
|
-
|
|
68
|
-
return sync => {
|
|
83
|
+
function maybeSync(fn) {
|
|
84
|
+
return (sync) => {
|
|
69
85
|
if (sync) {
|
|
70
86
|
return fn();
|
|
71
87
|
} else {
|
|
@@ -73,4 +89,14 @@ export function maybeSync(fn) {
|
|
|
73
89
|
return Promise.resolve();
|
|
74
90
|
}
|
|
75
91
|
};
|
|
76
|
-
}
|
|
92
|
+
}
|
|
93
|
+
export {
|
|
94
|
+
cacheAddition,
|
|
95
|
+
connectFactor,
|
|
96
|
+
fname,
|
|
97
|
+
getTime,
|
|
98
|
+
maybeSync,
|
|
99
|
+
namespaceHash,
|
|
100
|
+
valueFactory,
|
|
101
|
+
withCoalescedInvoke
|
|
102
|
+
};
|