@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,42 +1,56 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
includes: {
|
|
15
|
-
query: []
|
|
16
|
-
}
|
|
17
|
-
}, {
|
|
18
|
-
level: 2,
|
|
19
|
-
includes: {}
|
|
20
|
-
}, {
|
|
21
|
-
level: 2,
|
|
22
|
-
includes: {
|
|
23
|
-
header: []
|
|
24
|
-
}
|
|
25
|
-
}, {
|
|
26
|
-
level: 3,
|
|
27
|
-
includes: {
|
|
28
|
-
header: []
|
|
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 });
|
|
29
14
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var stdin_exports = {};
|
|
19
|
+
__export(stdin_exports, {
|
|
20
|
+
errorConfiguration: () => errorConfiguration
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(stdin_exports);
|
|
23
|
+
const errorConfiguration = [
|
|
24
|
+
{ level: 1 },
|
|
25
|
+
{
|
|
26
|
+
level: 1,
|
|
27
|
+
includes: {}
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
level: 1,
|
|
31
|
+
includes: { query: [] }
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
level: 2,
|
|
35
|
+
includes: {}
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
level: 2,
|
|
39
|
+
includes: { header: [] }
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
level: 3,
|
|
43
|
+
includes: { header: [] }
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
level: 3,
|
|
47
|
+
includes: { query: [] }
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
level: 3,
|
|
51
|
+
includes: {
|
|
52
|
+
query: [],
|
|
53
|
+
header: []
|
|
54
|
+
}
|
|
40
55
|
}
|
|
41
|
-
|
|
42
|
-
exports.errorConfiguration = errorConfiguration;
|
|
56
|
+
];
|
|
@@ -1,128 +1,110 @@
|
|
|
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
|
+
matchedCacheableAry: () => matchedCacheableAry
|
|
5
21
|
});
|
|
6
|
-
exports
|
|
7
|
-
const matchedCacheableAry = [
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
22
|
+
module.exports = __toCommonJS(stdin_exports);
|
|
23
|
+
const matchedCacheableAry = [
|
|
24
|
+
[
|
|
25
|
+
{
|
|
26
|
+
requestOpt: {
|
|
27
|
+
url: "/level-one",
|
|
28
|
+
headers: {},
|
|
29
|
+
query: { name: "byted" }
|
|
30
|
+
},
|
|
31
|
+
cacheConfig: {
|
|
32
|
+
level: 1,
|
|
33
|
+
includes: { query: ["name"] },
|
|
34
|
+
matches: { query: { name: { weixin: "^byted" } } }
|
|
35
|
+
},
|
|
36
|
+
content: "level1"
|
|
19
37
|
},
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
content: 'level1'
|
|
29
|
-
}, {
|
|
30
|
-
url: '/level-one',
|
|
31
|
-
headers: {},
|
|
32
|
-
query: {
|
|
33
|
-
name: 'byted_likely'
|
|
34
|
-
}
|
|
35
|
-
}, {
|
|
36
|
-
url: '/level-one',
|
|
37
|
-
headers: {},
|
|
38
|
-
query: {
|
|
39
|
-
name: 'not_byted'
|
|
40
|
-
}
|
|
41
|
-
}], [{
|
|
42
|
-
requestOpt: {
|
|
43
|
-
url: '/level-two',
|
|
44
|
-
query: {},
|
|
45
|
-
headers: {
|
|
46
|
-
age: '17'
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
cacheConfig: {
|
|
50
|
-
level: 2,
|
|
51
|
-
includes: {
|
|
52
|
-
header: ['age']
|
|
38
|
+
{
|
|
39
|
+
url: "/level-one",
|
|
40
|
+
headers: {},
|
|
41
|
+
query: { name: "byted_likely" }
|
|
53
42
|
},
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
}
|
|
43
|
+
{
|
|
44
|
+
url: "/level-one",
|
|
45
|
+
headers: {},
|
|
46
|
+
query: { name: "not_byted" }
|
|
60
47
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}], [{
|
|
76
|
-
requestOpt: {
|
|
77
|
-
url: '/level-three',
|
|
78
|
-
headers: {
|
|
79
|
-
age: '17'
|
|
48
|
+
],
|
|
49
|
+
[
|
|
50
|
+
{
|
|
51
|
+
requestOpt: {
|
|
52
|
+
url: "/level-two",
|
|
53
|
+
query: {},
|
|
54
|
+
headers: { age: "17" }
|
|
55
|
+
},
|
|
56
|
+
cacheConfig: {
|
|
57
|
+
level: 2,
|
|
58
|
+
includes: { header: ["age"] },
|
|
59
|
+
matches: { header: { age: { one: "^1" } } }
|
|
60
|
+
},
|
|
61
|
+
content: "level2"
|
|
80
62
|
},
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
cacheConfig: {
|
|
86
|
-
level: 3,
|
|
87
|
-
includes: {
|
|
88
|
-
query: ['name'],
|
|
89
|
-
header: ['age']
|
|
63
|
+
{
|
|
64
|
+
url: "/level-two",
|
|
65
|
+
query: {},
|
|
66
|
+
headers: { age: "11" }
|
|
90
67
|
},
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
68
|
+
{
|
|
69
|
+
url: "/level-two",
|
|
70
|
+
query: {},
|
|
71
|
+
headers: { age: "22" }
|
|
72
|
+
}
|
|
73
|
+
],
|
|
74
|
+
[
|
|
75
|
+
{
|
|
76
|
+
requestOpt: {
|
|
77
|
+
url: "/level-three",
|
|
78
|
+
headers: { age: "17" },
|
|
79
|
+
query: { name: "byted" }
|
|
96
80
|
},
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
81
|
+
cacheConfig: {
|
|
82
|
+
level: 3,
|
|
83
|
+
includes: {
|
|
84
|
+
query: ["name"],
|
|
85
|
+
header: ["age"]
|
|
86
|
+
},
|
|
87
|
+
matches: {
|
|
88
|
+
query: { name: { weixin: "^byted" } },
|
|
89
|
+
header: { age: { one: "^1" } }
|
|
100
90
|
}
|
|
101
|
-
}
|
|
91
|
+
},
|
|
92
|
+
content: "level3"
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
url: "/level-three",
|
|
96
|
+
query: { name: "byted_likely" },
|
|
97
|
+
headers: { age: "19" }
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
url: "/level-three",
|
|
101
|
+
query: { name: "byted_likely" },
|
|
102
|
+
headers: {}
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
url: "/level-three",
|
|
106
|
+
query: { name: "not_byted" },
|
|
107
|
+
headers: { age: "19" }
|
|
102
108
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}, {
|
|
106
|
-
url: '/level-three',
|
|
107
|
-
query: {
|
|
108
|
-
name: 'byted_likely'
|
|
109
|
-
},
|
|
110
|
-
headers: {
|
|
111
|
-
age: '19'
|
|
112
|
-
}
|
|
113
|
-
}, {
|
|
114
|
-
url: '/level-three',
|
|
115
|
-
query: {
|
|
116
|
-
name: 'byted_likely'
|
|
117
|
-
},
|
|
118
|
-
headers: {}
|
|
119
|
-
}, {
|
|
120
|
-
url: '/level-three',
|
|
121
|
-
query: {
|
|
122
|
-
name: 'not_byted'
|
|
123
|
-
},
|
|
124
|
-
headers: {
|
|
125
|
-
age: '19'
|
|
126
|
-
}
|
|
127
|
-
}]];
|
|
128
|
-
exports.matchedCacheableAry = matchedCacheableAry;
|
|
109
|
+
]
|
|
110
|
+
];
|
|
@@ -1,88 +1,134 @@
|
|
|
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
|
+
default: () => cache_default
|
|
5
21
|
});
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
module.exports = __toCommonJS(stdin_exports);
|
|
23
|
+
var import_stream = require("stream");
|
|
24
|
+
var import_constants = require("../../../constants");
|
|
25
|
+
var import_spr = require("./spr");
|
|
26
|
+
var import_util = require("./util");
|
|
27
|
+
var __defProp2 = Object.defineProperty;
|
|
28
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
29
|
+
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
30
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
31
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
32
|
+
var __spreadValues = (a, b) => {
|
|
33
|
+
for (var prop in b || (b = {}))
|
|
34
|
+
if (__hasOwnProp2.call(b, prop))
|
|
35
|
+
__defNormalProp(a, prop, b[prop]);
|
|
36
|
+
if (__getOwnPropSymbols)
|
|
37
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
38
|
+
if (__propIsEnum.call(b, prop))
|
|
39
|
+
__defNormalProp(a, prop, b[prop]);
|
|
40
|
+
}
|
|
41
|
+
return a;
|
|
42
|
+
};
|
|
43
|
+
var __async = (__this, __arguments, generator) => {
|
|
44
|
+
return new Promise((resolve, reject) => {
|
|
45
|
+
var fulfilled = (value) => {
|
|
46
|
+
try {
|
|
47
|
+
step(generator.next(value));
|
|
48
|
+
} catch (e) {
|
|
49
|
+
reject(e);
|
|
25
50
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
write(chunk, _, callback) {
|
|
33
|
-
htmlForStream += chunk.toString();
|
|
34
|
-
this.push(chunk);
|
|
35
|
-
callback();
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
cacheStream.on('close', () => onAfterRender(htmlForStream));
|
|
39
|
-
return source(cacheStream);
|
|
51
|
+
};
|
|
52
|
+
var rejected = (value) => {
|
|
53
|
+
try {
|
|
54
|
+
step(generator.throw(value));
|
|
55
|
+
} catch (e) {
|
|
56
|
+
reject(e);
|
|
40
57
|
}
|
|
58
|
+
};
|
|
59
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
60
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
var cache_default = (renderFn, ctx) => {
|
|
64
|
+
const sprCache = (0, import_spr.createCache)();
|
|
65
|
+
const doRender = (context) => __async(void 0, null, function* () {
|
|
66
|
+
const cacheContext = __spreadValues({
|
|
67
|
+
entry: context.entryName
|
|
68
|
+
}, context.request);
|
|
69
|
+
const cacheFile = yield sprCache.get(cacheContext);
|
|
70
|
+
function afterRender(source, onAfterRender) {
|
|
71
|
+
return __async(this, null, function* () {
|
|
72
|
+
if (!source) {
|
|
73
|
+
return "";
|
|
74
|
+
}
|
|
75
|
+
if (typeof source === "string") {
|
|
76
|
+
yield onAfterRender(source);
|
|
77
|
+
return source;
|
|
78
|
+
} else {
|
|
79
|
+
let htmlForStream = "";
|
|
80
|
+
const cacheStream = new import_stream.Transform({
|
|
81
|
+
write(chunk, _, callback) {
|
|
82
|
+
htmlForStream += chunk.toString();
|
|
83
|
+
this.push(chunk);
|
|
84
|
+
callback();
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
cacheStream.on("close", () => onAfterRender(htmlForStream));
|
|
88
|
+
return source(cacheStream);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
41
91
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
cacheConfig
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
92
|
+
function saveHtmlIntoCache(html) {
|
|
93
|
+
return __async(this, null, function* () {
|
|
94
|
+
const { cacheConfig } = context;
|
|
95
|
+
if (html && cacheConfig) {
|
|
96
|
+
yield sprCache.set(cacheContext, html, cacheConfig);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
49
99
|
}
|
|
50
|
-
|
|
51
|
-
// no cache, render sync
|
|
52
100
|
if (!cacheFile) {
|
|
53
|
-
const renderResult =
|
|
101
|
+
const renderResult = yield renderFn(context);
|
|
54
102
|
return afterRender(renderResult, saveHtmlIntoCache);
|
|
55
103
|
}
|
|
56
|
-
const cacheHash = cacheFile
|
|
57
|
-
|
|
58
|
-
// completely expired
|
|
104
|
+
const cacheHash = cacheFile == null ? void 0 : cacheFile.hash;
|
|
59
105
|
if (cacheFile.isGarbage) {
|
|
60
|
-
const renderResult =
|
|
106
|
+
const renderResult = yield renderFn(context);
|
|
61
107
|
return afterRender(renderResult, saveHtmlIntoCache);
|
|
62
108
|
} else if (cacheFile.isStale) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
109
|
+
const render = (0, import_util.withCoalescedInvoke)(() => renderFn(context)).bind(
|
|
110
|
+
null,
|
|
111
|
+
(0, import_util.namespaceHash)("render", cacheFile.hash),
|
|
112
|
+
[]
|
|
113
|
+
);
|
|
114
|
+
render().then((res) => __async(void 0, null, function* () {
|
|
66
115
|
if (res.value && res.isOrigin) {
|
|
67
|
-
const {
|
|
68
|
-
cacheConfig
|
|
69
|
-
} = context;
|
|
116
|
+
const { cacheConfig } = context;
|
|
70
117
|
if (cacheConfig) {
|
|
71
|
-
afterRender(res.value,
|
|
118
|
+
afterRender(res.value, (html) => __async(void 0, null, function* () {
|
|
72
119
|
sprCache.set(cacheContext, html, cacheConfig);
|
|
73
|
-
});
|
|
120
|
+
}));
|
|
74
121
|
} else {
|
|
75
122
|
sprCache.del(cacheContext, cacheHash);
|
|
76
123
|
}
|
|
77
124
|
}
|
|
78
|
-
}).catch(e => {
|
|
125
|
+
})).catch((e) => {
|
|
79
126
|
sprCache.del(cacheContext, cacheHash);
|
|
80
|
-
ctx.error(
|
|
127
|
+
ctx.error(import_constants.ERROR_DIGEST.ERENDER, e);
|
|
81
128
|
});
|
|
82
129
|
}
|
|
83
|
-
ctx.res.setHeader(
|
|
130
|
+
ctx.res.setHeader("x-modern-spr", "1");
|
|
84
131
|
return cacheFile.content;
|
|
85
|
-
};
|
|
132
|
+
});
|
|
86
133
|
return doRender;
|
|
87
134
|
};
|
|
88
|
-
exports.default = _default;
|
|
@@ -1,15 +1,51 @@
|
|
|
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
|
+
createPageCaches: () => createPageCaches
|
|
5
21
|
});
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
22
|
+
module.exports = __toCommonJS(stdin_exports);
|
|
23
|
+
var import_lru = require("./lru");
|
|
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
|
+
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
|
+
}
|
|
@@ -1,18 +1,36 @@
|
|
|
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 stdin_exports = {};
|
|
25
|
+
__export(stdin_exports, {
|
|
26
|
+
LRUCaches: () => LRUCaches
|
|
5
27
|
});
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
8
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
-
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; }
|
|
28
|
+
module.exports = __toCommonJS(stdin_exports);
|
|
29
|
+
var import_lru_cache = __toESM(require("lru-cache"));
|
|
10
30
|
class LRUCaches {
|
|
11
31
|
constructor(options) {
|
|
12
|
-
_defineProperty(this, "caches", void 0);
|
|
13
|
-
_defineProperty(this, "max", void 0);
|
|
14
32
|
this.max = options.max;
|
|
15
|
-
this.caches = new
|
|
33
|
+
this.caches = new import_lru_cache.default(this.max);
|
|
16
34
|
}
|
|
17
35
|
init() {
|
|
18
36
|
return Promise.resolve();
|
|
@@ -34,4 +52,3 @@ class LRUCaches {
|
|
|
34
52
|
this.caches.del(key);
|
|
35
53
|
}
|
|
36
54
|
}
|
|
37
|
-
exports.LRUCaches = LRUCaches;
|