@modern-js/prod-server 1.21.6 → 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 +274 -13
- 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,17 +1,55 @@
|
|
|
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 __async = (__this, __arguments, generator) => {
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
var fulfilled = (value) => {
|
|
21
|
+
try {
|
|
22
|
+
step(generator.next(value));
|
|
23
|
+
} catch (e) {
|
|
24
|
+
reject(e);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var rejected = (value) => {
|
|
28
|
+
try {
|
|
29
|
+
step(generator.throw(value));
|
|
30
|
+
} catch (e) {
|
|
31
|
+
reject(e);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
35
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
var page_caches_exports = {};
|
|
39
|
+
__export(page_caches_exports, {
|
|
40
|
+
createPageCaches: () => createPageCaches
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(page_caches_exports);
|
|
43
|
+
var import_lru = require("./lru");
|
|
44
|
+
function createPageCaches(max) {
|
|
45
|
+
return __async(this, null, function* () {
|
|
46
|
+
const constructorOptions = { max };
|
|
47
|
+
const cacheInstance = new import_lru.LRUCaches(constructorOptions);
|
|
48
|
+
yield cacheInstance.init();
|
|
49
|
+
return cacheInstance;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
53
|
+
0 && (module.exports = {
|
|
54
|
+
createPageCaches
|
|
5
55
|
});
|
|
6
|
-
exports.createPageCaches = createPageCaches;
|
|
7
|
-
|
|
8
|
-
var _lru = require("./lru");
|
|
9
|
-
|
|
10
|
-
async function createPageCaches(max) {
|
|
11
|
-
const constructorOptions = {
|
|
12
|
-
max
|
|
13
|
-
};
|
|
14
|
-
const cacheInstance = new _lru.LRUCaches(constructorOptions);
|
|
15
|
-
await cacheInstance.init();
|
|
16
|
-
return cacheInstance;
|
|
17
|
-
}
|
|
@@ -1,51 +1,58 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
var lru_exports = {};
|
|
25
|
+
__export(lru_exports, {
|
|
26
|
+
LRUCaches: () => LRUCaches
|
|
5
27
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
var _lruCache = _interopRequireDefault(require("lru-cache"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
13
|
-
|
|
28
|
+
module.exports = __toCommonJS(lru_exports);
|
|
29
|
+
var import_lru_cache = __toESM(require("lru-cache"));
|
|
14
30
|
class LRUCaches {
|
|
15
31
|
constructor(options) {
|
|
16
|
-
_defineProperty(this, "caches", void 0);
|
|
17
|
-
|
|
18
|
-
_defineProperty(this, "max", void 0);
|
|
19
|
-
|
|
20
32
|
this.max = options.max;
|
|
21
|
-
this.caches = new
|
|
33
|
+
this.caches = new import_lru_cache.default(this.max);
|
|
22
34
|
}
|
|
23
|
-
|
|
24
35
|
init() {
|
|
25
36
|
return Promise.resolve();
|
|
26
37
|
}
|
|
27
|
-
|
|
28
38
|
keys() {
|
|
29
39
|
return this.caches.keys();
|
|
30
40
|
}
|
|
31
|
-
|
|
32
41
|
get(key) {
|
|
33
42
|
return Promise.resolve(this.caches.get(key) || null);
|
|
34
43
|
}
|
|
35
|
-
|
|
36
44
|
peek(key) {
|
|
37
45
|
return this.caches.peek(key) || null;
|
|
38
46
|
}
|
|
39
|
-
|
|
40
47
|
set(key, cache) {
|
|
41
48
|
this.caches.set(key, cache);
|
|
42
49
|
return Promise.resolve();
|
|
43
50
|
}
|
|
44
|
-
|
|
45
51
|
del(key) {
|
|
46
52
|
this.caches.del(key);
|
|
47
53
|
}
|
|
48
|
-
|
|
49
54
|
}
|
|
50
|
-
|
|
51
|
-
exports
|
|
55
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
56
|
+
0 && (module.exports = {
|
|
57
|
+
LRUCaches
|
|
58
|
+
});
|
|
@@ -1,190 +1,174 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
var __async = (__this, __arguments, generator) => {
|
|
25
|
+
return new Promise((resolve, reject) => {
|
|
26
|
+
var fulfilled = (value) => {
|
|
27
|
+
try {
|
|
28
|
+
step(generator.next(value));
|
|
29
|
+
} catch (e) {
|
|
30
|
+
reject(e);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var rejected = (value) => {
|
|
34
|
+
try {
|
|
35
|
+
step(generator.throw(value));
|
|
36
|
+
} catch (e) {
|
|
37
|
+
reject(e);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
41
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
var spr_exports = {};
|
|
45
|
+
__export(spr_exports, {
|
|
46
|
+
createCache: () => createCache,
|
|
47
|
+
destroyCache: () => destroyCache
|
|
5
48
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
var _utils = require("@modern-js/utils");
|
|
14
|
-
|
|
15
|
-
var _util = require("./util");
|
|
16
|
-
|
|
17
|
-
var _pageCaches = require("./page-caches");
|
|
18
|
-
|
|
19
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
|
-
|
|
21
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
22
|
-
|
|
49
|
+
module.exports = __toCommonJS(spr_exports);
|
|
50
|
+
var import_crypto = __toESM(require("crypto"));
|
|
51
|
+
var import_lru_cache = __toESM(require("lru-cache"));
|
|
52
|
+
var import_utils = require("@modern-js/utils");
|
|
53
|
+
var import_util = require("./util");
|
|
54
|
+
var import_page_caches = require("./page-caches");
|
|
23
55
|
const MAX_CACHE_EACH_REQ = Number(process.env.ROUTE_CACHE_LIMIT) || 10;
|
|
24
56
|
const MAX_SIZE_EACH_CLUSTER = Number(process.env.CLUSTER_CACHE_LIMIT) || 100;
|
|
25
57
|
const BASE_LEVEL = 0;
|
|
26
58
|
const QUERY_LEVEL = 1;
|
|
27
59
|
const HEADER_LEVEL = 2;
|
|
28
60
|
const QUERY_HEADER_LEVEL = 3;
|
|
29
|
-
|
|
30
61
|
class CacheManager {
|
|
31
62
|
constructor(cacheOptions) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
_defineProperty(this, "cacheOptions", void 0);
|
|
35
|
-
|
|
36
|
-
_defineProperty(this, "find", (() => {
|
|
63
|
+
this.find = (() => {
|
|
37
64
|
{
|
|
38
|
-
// eslint-disable-next-line consistent-this,@typescript-eslint/no-this-alias
|
|
39
65
|
const _this = this;
|
|
40
|
-
|
|
41
66
|
return {
|
|
42
|
-
[(0,
|
|
43
|
-
) {
|
|
67
|
+
[(0, import_util.fname)(BASE_LEVEL)](context, cacheKey) {
|
|
44
68
|
return _this.md5(cacheKey);
|
|
45
69
|
},
|
|
46
|
-
|
|
47
|
-
[(0, _util.fname)(QUERY_LEVEL)](context, cacheKey, data) {
|
|
70
|
+
[(0, import_util.fname)(QUERY_LEVEL)](context, cacheKey, data) {
|
|
48
71
|
const queryFactor = _this.queryFactor(context, data);
|
|
49
|
-
|
|
50
72
|
if (!queryFactor) {
|
|
51
73
|
return null;
|
|
52
74
|
}
|
|
53
|
-
|
|
54
|
-
return _this.md5((0, _util.connectFactor)(cacheKey, queryFactor));
|
|
75
|
+
return _this.md5((0, import_util.connectFactor)(cacheKey, queryFactor));
|
|
55
76
|
},
|
|
56
|
-
|
|
57
|
-
[(0, _util.fname)(HEADER_LEVEL)](context, cacheKey, data) {
|
|
77
|
+
[(0, import_util.fname)(HEADER_LEVEL)](context, cacheKey, data) {
|
|
58
78
|
const headerFactor = _this.headerFactor(context, data);
|
|
59
|
-
|
|
60
79
|
if (!headerFactor) {
|
|
61
80
|
return null;
|
|
62
81
|
}
|
|
63
|
-
|
|
64
|
-
return _this.md5((0, _util.connectFactor)(cacheKey, headerFactor));
|
|
82
|
+
return _this.md5((0, import_util.connectFactor)(cacheKey, headerFactor));
|
|
65
83
|
},
|
|
66
|
-
|
|
67
|
-
[(0, _util.fname)(QUERY_HEADER_LEVEL)](context, cacheKey, data) {
|
|
84
|
+
[(0, import_util.fname)(QUERY_HEADER_LEVEL)](context, cacheKey, data) {
|
|
68
85
|
const queryFactor = _this.queryFactor(context, data);
|
|
69
|
-
|
|
70
86
|
const headerFactor = _this.headerFactor(context, data);
|
|
71
|
-
|
|
72
87
|
if (!queryFactor || !headerFactor) {
|
|
73
88
|
return null;
|
|
74
89
|
}
|
|
75
|
-
|
|
76
|
-
return _this.md5((0, _util.connectFactor)(cacheKey, headerFactor, queryFactor));
|
|
90
|
+
return _this.md5((0, import_util.connectFactor)(cacheKey, headerFactor, queryFactor));
|
|
77
91
|
}
|
|
78
|
-
|
|
79
92
|
};
|
|
80
93
|
}
|
|
81
|
-
})()
|
|
82
|
-
|
|
94
|
+
})();
|
|
83
95
|
this.cacheOptions = cacheOptions;
|
|
84
|
-
this.cache = new
|
|
96
|
+
this.cache = new import_lru_cache.default({
|
|
85
97
|
max: Math.min(MAX_SIZE_EACH_CLUSTER, 600) * 1024 * 1024,
|
|
86
|
-
|
|
87
|
-
// 默认存 100M,最大 600M
|
|
88
98
|
length(n) {
|
|
89
99
|
const len = n.caches.keys().reduce((total, cur) => {
|
|
90
|
-
var
|
|
91
|
-
|
|
92
|
-
return total + (((_n$caches$peek = n.caches.peek(cur)) === null || _n$caches$peek === void 0 ? void 0 : _n$caches$peek.size) || 0);
|
|
100
|
+
var _a;
|
|
101
|
+
return total + (((_a = n.caches.peek(cur)) == null ? void 0 : _a.size) || 0);
|
|
93
102
|
}, 1);
|
|
94
103
|
return len;
|
|
95
104
|
}
|
|
96
|
-
|
|
97
105
|
});
|
|
98
106
|
}
|
|
99
|
-
|
|
100
107
|
md5(content) {
|
|
101
|
-
const md5 =
|
|
102
|
-
|
|
103
|
-
return md5.update(content).digest('hex');
|
|
108
|
+
const md5 = import_crypto.default.createHash("md5");
|
|
109
|
+
return md5.update(content).digest("hex");
|
|
104
110
|
}
|
|
105
|
-
|
|
106
111
|
generateRequestKey(context) {
|
|
107
|
-
const {
|
|
108
|
-
pathname,
|
|
109
|
-
entry
|
|
110
|
-
} = context;
|
|
112
|
+
const { pathname, entry } = context;
|
|
111
113
|
return this.md5(`${pathname}_${entry}`);
|
|
112
114
|
}
|
|
113
|
-
|
|
114
115
|
replaceValue(value, matcher) {
|
|
115
116
|
let final = value;
|
|
116
|
-
Object.keys(matcher).some(replacer => {
|
|
117
|
+
Object.keys(matcher).some((replacer) => {
|
|
117
118
|
const reg = new RegExp(matcher[replacer]);
|
|
118
|
-
|
|
119
119
|
if (reg.test(value)) {
|
|
120
120
|
final = replacer;
|
|
121
121
|
return true;
|
|
122
122
|
}
|
|
123
|
-
|
|
124
123
|
return false;
|
|
125
124
|
});
|
|
126
125
|
return final;
|
|
127
126
|
}
|
|
128
|
-
|
|
129
127
|
factor(keys, obj, matches = {}) {
|
|
130
128
|
keys.sort();
|
|
131
|
-
const getValue = (0,
|
|
129
|
+
const getValue = (0, import_util.valueFactory)(obj);
|
|
132
130
|
const factorAry = keys.reduce((ary, key) => {
|
|
133
|
-
let value = getValue(key) ||
|
|
131
|
+
let value = getValue(key) || "";
|
|
134
132
|
const matcher = matches[key];
|
|
135
|
-
|
|
136
133
|
if (matcher) {
|
|
137
134
|
value = this.replaceValue(value, matcher);
|
|
138
135
|
}
|
|
139
|
-
|
|
140
136
|
return ary.concat([key, value]);
|
|
141
137
|
}, []);
|
|
142
|
-
return factorAry.join(
|
|
138
|
+
return factorAry.join(",");
|
|
143
139
|
}
|
|
144
|
-
|
|
145
140
|
queryFactor(context, data) {
|
|
146
|
-
var
|
|
147
|
-
|
|
148
|
-
const
|
|
149
|
-
const queryMatches = (_data$matches = data.matches) === null || _data$matches === void 0 ? void 0 : _data$matches.query;
|
|
150
|
-
|
|
141
|
+
var _a, _b;
|
|
142
|
+
const queryKeys = (_a = data.includes) == null ? void 0 : _a.query;
|
|
143
|
+
const queryMatches = (_b = data.matches) == null ? void 0 : _b.query;
|
|
151
144
|
if (!queryKeys || queryKeys.length === 0) {
|
|
152
145
|
return null;
|
|
153
146
|
}
|
|
154
|
-
|
|
155
147
|
const requestQuery = context.query;
|
|
156
148
|
const queryFactor = this.factor(queryKeys, requestQuery, queryMatches);
|
|
157
149
|
return queryFactor;
|
|
158
150
|
}
|
|
159
|
-
|
|
160
151
|
headerFactor(context, data) {
|
|
161
|
-
var
|
|
162
|
-
|
|
163
|
-
const
|
|
164
|
-
const headerMatches = (_data$matches2 = data.matches) === null || _data$matches2 === void 0 ? void 0 : _data$matches2.header;
|
|
165
|
-
|
|
152
|
+
var _a, _b;
|
|
153
|
+
const headerKeys = (_a = data.includes) == null ? void 0 : _a.header;
|
|
154
|
+
const headerMatches = (_b = data.matches) == null ? void 0 : _b.header;
|
|
166
155
|
if (!headerKeys || headerKeys.length === 0) {
|
|
167
156
|
return null;
|
|
168
157
|
}
|
|
169
|
-
|
|
170
158
|
const requestHeader = context.headers;
|
|
171
159
|
const headerFactor = this.factor(headerKeys, requestHeader, headerMatches);
|
|
172
160
|
return headerFactor;
|
|
173
161
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
level
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
return data.caches.get(cacheHash);
|
|
162
|
+
best(context, cacheKey, data) {
|
|
163
|
+
return __async(this, null, function* () {
|
|
164
|
+
const { level } = data;
|
|
165
|
+
const cacheHash = this.find[(0, import_util.fname)(level)](context, cacheKey, data);
|
|
166
|
+
if (!cacheHash) {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
return data.caches.get(cacheHash);
|
|
170
|
+
});
|
|
186
171
|
}
|
|
187
|
-
|
|
188
172
|
createCacheContent(config, caches) {
|
|
189
173
|
return {
|
|
190
174
|
level: config.level,
|
|
@@ -195,103 +179,92 @@ class CacheManager {
|
|
|
195
179
|
caches
|
|
196
180
|
};
|
|
197
181
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
const isGarbage = limitTime ? Date.now() - limitTime > 0 : false;
|
|
221
|
-
return {
|
|
222
|
-
content: html || '',
|
|
223
|
-
contentType: _utils.mime.contentType('html'),
|
|
224
|
-
isStale,
|
|
225
|
-
isGarbage,
|
|
226
|
-
hash: cacheHash
|
|
227
|
-
};
|
|
182
|
+
get(context) {
|
|
183
|
+
return __async(this, null, function* () {
|
|
184
|
+
const cacheKey = this.generateRequestKey(context);
|
|
185
|
+
const data = this.cache.get(cacheKey);
|
|
186
|
+
if (!data) {
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
const dest = yield this.best(context, cacheKey, data);
|
|
190
|
+
if (!dest) {
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
const { expireTime, limitTime, html, cacheHash } = dest;
|
|
194
|
+
const isStale = Date.now() - expireTime > 0;
|
|
195
|
+
const isGarbage = limitTime ? Date.now() - limitTime > 0 : false;
|
|
196
|
+
return {
|
|
197
|
+
content: html || "",
|
|
198
|
+
contentType: import_utils.mime.contentType("html"),
|
|
199
|
+
isStale,
|
|
200
|
+
isGarbage,
|
|
201
|
+
hash: cacheHash
|
|
202
|
+
};
|
|
203
|
+
});
|
|
228
204
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
const
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
205
|
+
set(context, html, cacheConfig, sync = false) {
|
|
206
|
+
return __async(this, null, function* () {
|
|
207
|
+
if (!cacheConfig) {
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
const cacheKey = this.generateRequestKey(context);
|
|
211
|
+
let data = this.cache.get(cacheKey);
|
|
212
|
+
if (!data) {
|
|
213
|
+
const caches = yield (0, import_page_caches.createPageCaches)(MAX_CACHE_EACH_REQ);
|
|
214
|
+
data = this.createCacheContent(cacheConfig, caches);
|
|
215
|
+
}
|
|
216
|
+
const cacheHash = this.find[(0, import_util.fname)(cacheConfig.level)](
|
|
217
|
+
context,
|
|
218
|
+
cacheKey,
|
|
219
|
+
data
|
|
220
|
+
);
|
|
221
|
+
if (!cacheHash) {
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
const cacheSyncOrAsync = () => __async(this, null, function* () {
|
|
225
|
+
const next = data;
|
|
226
|
+
const limit = cacheConfig.staleLimit;
|
|
227
|
+
const storeHTML = (0, import_util.cacheAddition)(html, cacheHash);
|
|
228
|
+
const size = storeHTML.length;
|
|
229
|
+
yield next.caches.set(cacheHash, {
|
|
230
|
+
expireTime: Date.now() + cacheConfig.interval * 1e3,
|
|
231
|
+
limitTime: typeof limit === "number" ? Date.now() + limit * 1e3 : null,
|
|
232
|
+
cacheHash,
|
|
233
|
+
html: storeHTML,
|
|
234
|
+
size
|
|
235
|
+
});
|
|
236
|
+
this.cache.set(cacheKey, next);
|
|
237
|
+
return true;
|
|
261
238
|
});
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
239
|
+
const doCache = (0, import_util.withCoalescedInvoke)(cacheSyncOrAsync).bind(
|
|
240
|
+
null,
|
|
241
|
+
(0, import_util.namespaceHash)("stream", cacheHash),
|
|
242
|
+
[]
|
|
243
|
+
);
|
|
244
|
+
return (0, import_util.maybeSync)(doCache)(sync);
|
|
245
|
+
});
|
|
269
246
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
247
|
+
del(context, cacheHash) {
|
|
248
|
+
return __async(this, null, function* () {
|
|
249
|
+
const cacheKey = this.generateRequestKey(context);
|
|
250
|
+
const data = this.cache.get(cacheKey);
|
|
251
|
+
data == null ? void 0 : data.caches.del(cacheHash);
|
|
252
|
+
});
|
|
275
253
|
}
|
|
276
|
-
|
|
277
254
|
}
|
|
278
|
-
|
|
279
255
|
let manager;
|
|
280
|
-
|
|
281
256
|
function createCache() {
|
|
282
257
|
if (manager) {
|
|
283
258
|
return manager;
|
|
284
259
|
}
|
|
285
|
-
|
|
286
|
-
manager = new CacheManager({
|
|
287
|
-
max: 0
|
|
288
|
-
});
|
|
260
|
+
manager = new CacheManager({ max: 0 });
|
|
289
261
|
return manager;
|
|
290
262
|
}
|
|
291
|
-
|
|
292
263
|
function destroyCache() {
|
|
293
264
|
manager = null;
|
|
294
265
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
266
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
267
|
+
0 && (module.exports = {
|
|
268
|
+
createCache,
|
|
269
|
+
destroyCache
|
|
270
|
+
});
|
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
var type_exports = {};
|
|
15
|
+
module.exports = __toCommonJS(type_exports);
|