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