@modern-js/prod-server 2.9.1-alpha.0 → 2.11.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 +45 -0
- package/dist/cjs/libs/hook-api/index.js +7 -26
- package/dist/cjs/libs/render/index.js +2 -1
- package/dist/cjs/libs/render/ssr.js +7 -5
- package/dist/{js/node/libs/metrics.js → cjs/libs/render/utils.js} +25 -12
- package/dist/cjs/server/index.js +1 -1
- package/dist/cjs/server/modernServer.js +75 -80
- package/dist/esm/libs/hook-api/index.js +9 -37
- package/dist/esm/libs/render/index.js +2 -1
- package/dist/esm/libs/render/ssr.js +6 -4
- package/dist/esm/libs/render/utils.js +12 -0
- package/dist/esm/server/index.js +2 -2
- package/dist/esm/server/modernServer.js +108 -103
- package/dist/esm-node/libs/hook-api/index.js +7 -26
- package/dist/esm-node/libs/render/index.js +2 -1
- package/dist/esm-node/libs/render/ssr.js +7 -7
- package/dist/esm-node/libs/render/utils.js +23 -0
- package/dist/esm-node/server/index.js +1 -1
- package/dist/esm-node/server/modernServer.js +75 -80
- package/dist/types/libs/context/context.d.ts +1 -1
- package/dist/types/libs/render/utils.d.ts +5 -0
- package/dist/types/server/index.d.ts +2 -1
- package/dist/types/server/modernServer.d.ts +4 -4
- package/dist/types/type.d.ts +1 -1
- package/dist/types/utils.d.ts +1 -1
- package/package.json +9 -7
- package/dist/js/modern/constants.js +0 -35
- package/dist/js/modern/index.js +0 -18
- package/dist/js/modern/libs/context/context.js +0 -160
- package/dist/js/modern/libs/context/index.js +0 -6
- package/dist/js/modern/libs/hook-api/index.js +0 -134
- package/dist/js/modern/libs/hook-api/route.js +0 -20
- package/dist/js/modern/libs/hook-api/template.js +0 -73
- package/dist/js/modern/libs/loadConfig.js +0 -62
- package/dist/js/modern/libs/logger.js +0 -111
- package/dist/js/modern/libs/metrics.js +0 -11
- package/dist/js/modern/libs/proxy.js +0 -92
- package/dist/js/modern/libs/render/cache/__tests__/cache.fun.test.js +0 -114
- package/dist/js/modern/libs/render/cache/__tests__/cache.test.js +0 -254
- package/dist/js/modern/libs/render/cache/__tests__/cacheable.js +0 -47
- package/dist/js/modern/libs/render/cache/__tests__/error-configuration.js +0 -37
- package/dist/js/modern/libs/render/cache/__tests__/matched-cache.js +0 -91
- package/dist/js/modern/libs/render/cache/index.js +0 -115
- package/dist/js/modern/libs/render/cache/page-caches/index.js +0 -32
- package/dist/js/modern/libs/render/cache/page-caches/lru.js +0 -29
- package/dist/js/modern/libs/render/cache/spr.js +0 -248
- package/dist/js/modern/libs/render/cache/type.js +0 -0
- package/dist/js/modern/libs/render/cache/util.js +0 -102
- package/dist/js/modern/libs/render/index.js +0 -86
- package/dist/js/modern/libs/render/measure.js +0 -68
- package/dist/js/modern/libs/render/reader.js +0 -107
- package/dist/js/modern/libs/render/ssr.js +0 -100
- package/dist/js/modern/libs/render/static.js +0 -60
- package/dist/js/modern/libs/render/type.js +0 -9
- package/dist/js/modern/libs/route/index.js +0 -54
- package/dist/js/modern/libs/route/matcher.js +0 -87
- package/dist/js/modern/libs/route/route.js +0 -16
- package/dist/js/modern/libs/serve-file.js +0 -67
- package/dist/js/modern/server/index.js +0 -208
- package/dist/js/modern/server/modern-server-split.js +0 -74
- package/dist/js/modern/server/modern-server.js +0 -554
- package/dist/js/modern/type.js +0 -0
- package/dist/js/modern/utils.js +0 -136
- package/dist/js/modern/worker-server.js +0 -89
- package/dist/js/node/constants.js +0 -62
- package/dist/js/node/index.js +0 -44
- package/dist/js/node/libs/context/context.js +0 -189
- package/dist/js/node/libs/context/index.js +0 -30
- package/dist/js/node/libs/hook-api/index.js +0 -164
- package/dist/js/node/libs/hook-api/route.js +0 -43
- package/dist/js/node/libs/hook-api/template.js +0 -97
- package/dist/js/node/libs/loadConfig.js +0 -91
- package/dist/js/node/libs/logger.js +0 -133
- package/dist/js/node/libs/proxy.js +0 -114
- package/dist/js/node/libs/render/cache/__tests__/cache.fun.test.js +0 -115
- package/dist/js/node/libs/render/cache/__tests__/cache.test.js +0 -245
- package/dist/js/node/libs/render/cache/__tests__/cacheable.js +0 -70
- package/dist/js/node/libs/render/cache/__tests__/error-configuration.js +0 -60
- package/dist/js/node/libs/render/cache/__tests__/matched-cache.js +0 -114
- package/dist/js/node/libs/render/cache/index.js +0 -134
- package/dist/js/node/libs/render/cache/page-caches/index.js +0 -55
- package/dist/js/node/libs/render/cache/page-caches/lru.js +0 -58
- package/dist/js/node/libs/render/cache/spr.js +0 -270
- package/dist/js/node/libs/render/cache/type.js +0 -15
- package/dist/js/node/libs/render/cache/util.js +0 -138
- package/dist/js/node/libs/render/index.js +0 -115
- package/dist/js/node/libs/render/measure.js +0 -90
- package/dist/js/node/libs/render/reader.js +0 -140
- package/dist/js/node/libs/render/ssr.js +0 -123
- package/dist/js/node/libs/render/static.js +0 -89
- package/dist/js/node/libs/render/type.js +0 -32
- package/dist/js/node/libs/route/index.js +0 -78
- package/dist/js/node/libs/route/matcher.js +0 -106
- package/dist/js/node/libs/route/route.js +0 -39
- package/dist/js/node/libs/serve-file.js +0 -97
- package/dist/js/node/server/index.js +0 -219
- package/dist/js/node/server/modern-server-split.js +0 -97
- package/dist/js/node/server/modern-server.js +0 -559
- package/dist/js/node/type.js +0 -15
- package/dist/js/node/utils.js +0 -166
- package/dist/js/node/worker-server.js +0 -113
- package/dist/js/treeshaking/constants.js +0 -29
- package/dist/js/treeshaking/index.js +0 -13
- package/dist/js/treeshaking/libs/context/context.js +0 -274
- package/dist/js/treeshaking/libs/context/index.js +0 -5
- package/dist/js/treeshaking/libs/hook-api/index.js +0 -281
- package/dist/js/treeshaking/libs/hook-api/route.js +0 -68
- package/dist/js/treeshaking/libs/hook-api/template.js +0 -127
- package/dist/js/treeshaking/libs/loadConfig.js +0 -82
- package/dist/js/treeshaking/libs/logger.js +0 -205
- package/dist/js/treeshaking/libs/metrics.js +0 -6
- package/dist/js/treeshaking/libs/proxy.js +0 -244
- package/dist/js/treeshaking/libs/render/cache/__tests__/cache.fun.test.js +0 -291
- package/dist/js/treeshaking/libs/render/cache/__tests__/cache.test.js +0 -781
- package/dist/js/treeshaking/libs/render/cache/__tests__/cacheable.js +0 -67
- package/dist/js/treeshaking/libs/render/cache/__tests__/error-configuration.js +0 -45
- package/dist/js/treeshaking/libs/render/cache/__tests__/matched-cache.js +0 -147
- package/dist/js/treeshaking/libs/render/cache/index.js +0 -346
- package/dist/js/treeshaking/libs/render/cache/page-caches/index.js +0 -154
- package/dist/js/treeshaking/libs/render/cache/page-caches/lru.js +0 -84
- package/dist/js/treeshaking/libs/render/cache/spr.js +0 -492
- package/dist/js/treeshaking/libs/render/cache/type.js +0 -1
- package/dist/js/treeshaking/libs/render/cache/util.js +0 -280
- package/dist/js/treeshaking/libs/render/index.js +0 -234
- package/dist/js/treeshaking/libs/render/measure.js +0 -146
- package/dist/js/treeshaking/libs/render/reader.js +0 -339
- package/dist/js/treeshaking/libs/render/ssr.js +0 -223
- package/dist/js/treeshaking/libs/render/static.js +0 -216
- package/dist/js/treeshaking/libs/render/type.js +0 -7
- package/dist/js/treeshaking/libs/route/index.js +0 -130
- package/dist/js/treeshaking/libs/route/matcher.js +0 -143
- package/dist/js/treeshaking/libs/route/route.js +0 -40
- package/dist/js/treeshaking/libs/serve-file.js +0 -184
- package/dist/js/treeshaking/server/index.js +0 -505
- package/dist/js/treeshaking/server/modern-server-split.js +0 -360
- package/dist/js/treeshaking/server/modern-server.js +0 -1089
- package/dist/js/treeshaking/type.js +0 -1
- package/dist/js/treeshaking/utils.js +0 -147
- package/dist/js/treeshaking/worker-server.js +0 -233
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
var cacheabelAry = [
|
|
2
|
-
{
|
|
3
|
-
requestOpt: {
|
|
4
|
-
url: "/"
|
|
5
|
-
},
|
|
6
|
-
cacheConfig: {},
|
|
7
|
-
content: "level0"
|
|
8
|
-
},
|
|
9
|
-
{
|
|
10
|
-
requestOpt: {
|
|
11
|
-
url: "/level-one",
|
|
12
|
-
query: {
|
|
13
|
-
name: "modern"
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
cacheConfig: {
|
|
17
|
-
level: 1,
|
|
18
|
-
includes: {
|
|
19
|
-
query: [
|
|
20
|
-
"name"
|
|
21
|
-
]
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
content: "level1"
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
requestOpt: {
|
|
28
|
-
url: "/level-two",
|
|
29
|
-
headers: {
|
|
30
|
-
age: "18"
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
cacheConfig: {
|
|
34
|
-
level: 2,
|
|
35
|
-
includes: {
|
|
36
|
-
header: [
|
|
37
|
-
"age"
|
|
38
|
-
]
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
content: "level2"
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
requestOpt: {
|
|
45
|
-
url: "/level-three",
|
|
46
|
-
query: {
|
|
47
|
-
name: "modern"
|
|
48
|
-
},
|
|
49
|
-
headers: {
|
|
50
|
-
age: "18"
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
cacheConfig: {
|
|
54
|
-
level: 3,
|
|
55
|
-
includes: {
|
|
56
|
-
query: [
|
|
57
|
-
"name"
|
|
58
|
-
],
|
|
59
|
-
header: [
|
|
60
|
-
"age"
|
|
61
|
-
]
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
content: "level3"
|
|
65
|
-
}
|
|
66
|
-
];
|
|
67
|
-
export { cacheabelAry };
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
var errorConfiguration = [
|
|
2
|
-
{
|
|
3
|
-
level: 1
|
|
4
|
-
},
|
|
5
|
-
{
|
|
6
|
-
level: 1,
|
|
7
|
-
includes: {}
|
|
8
|
-
},
|
|
9
|
-
{
|
|
10
|
-
level: 1,
|
|
11
|
-
includes: {
|
|
12
|
-
query: []
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
level: 2,
|
|
17
|
-
includes: {}
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
level: 2,
|
|
21
|
-
includes: {
|
|
22
|
-
header: []
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
level: 3,
|
|
27
|
-
includes: {
|
|
28
|
-
header: []
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
level: 3,
|
|
33
|
-
includes: {
|
|
34
|
-
query: []
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
level: 3,
|
|
39
|
-
includes: {
|
|
40
|
-
query: [],
|
|
41
|
-
header: []
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
];
|
|
45
|
-
export { errorConfiguration };
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
var matchedCacheableAry = [
|
|
2
|
-
[
|
|
3
|
-
{
|
|
4
|
-
requestOpt: {
|
|
5
|
-
url: "/level-one",
|
|
6
|
-
headers: {},
|
|
7
|
-
query: {
|
|
8
|
-
name: "byted"
|
|
9
|
-
}
|
|
10
|
-
},
|
|
11
|
-
cacheConfig: {
|
|
12
|
-
level: 1,
|
|
13
|
-
includes: {
|
|
14
|
-
query: [
|
|
15
|
-
"name"
|
|
16
|
-
]
|
|
17
|
-
},
|
|
18
|
-
matches: {
|
|
19
|
-
query: {
|
|
20
|
-
name: {
|
|
21
|
-
weixin: "^byted"
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
content: "level1"
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
url: "/level-one",
|
|
30
|
-
headers: {},
|
|
31
|
-
query: {
|
|
32
|
-
name: "byted_likely"
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
url: "/level-one",
|
|
37
|
-
headers: {},
|
|
38
|
-
query: {
|
|
39
|
-
name: "not_byted"
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
],
|
|
43
|
-
[
|
|
44
|
-
{
|
|
45
|
-
requestOpt: {
|
|
46
|
-
url: "/level-two",
|
|
47
|
-
query: {},
|
|
48
|
-
headers: {
|
|
49
|
-
age: "17"
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
|
-
cacheConfig: {
|
|
53
|
-
level: 2,
|
|
54
|
-
includes: {
|
|
55
|
-
header: [
|
|
56
|
-
"age"
|
|
57
|
-
]
|
|
58
|
-
},
|
|
59
|
-
matches: {
|
|
60
|
-
header: {
|
|
61
|
-
age: {
|
|
62
|
-
one: "^1"
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
content: "level2"
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
url: "/level-two",
|
|
71
|
-
query: {},
|
|
72
|
-
headers: {
|
|
73
|
-
age: "11"
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
url: "/level-two",
|
|
78
|
-
query: {},
|
|
79
|
-
headers: {
|
|
80
|
-
age: "22"
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
],
|
|
84
|
-
[
|
|
85
|
-
{
|
|
86
|
-
requestOpt: {
|
|
87
|
-
url: "/level-three",
|
|
88
|
-
headers: {
|
|
89
|
-
age: "17"
|
|
90
|
-
},
|
|
91
|
-
query: {
|
|
92
|
-
name: "byted"
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
cacheConfig: {
|
|
96
|
-
level: 3,
|
|
97
|
-
includes: {
|
|
98
|
-
query: [
|
|
99
|
-
"name"
|
|
100
|
-
],
|
|
101
|
-
header: [
|
|
102
|
-
"age"
|
|
103
|
-
]
|
|
104
|
-
},
|
|
105
|
-
matches: {
|
|
106
|
-
query: {
|
|
107
|
-
name: {
|
|
108
|
-
weixin: "^byted"
|
|
109
|
-
}
|
|
110
|
-
},
|
|
111
|
-
header: {
|
|
112
|
-
age: {
|
|
113
|
-
one: "^1"
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
},
|
|
118
|
-
content: "level3"
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
url: "/level-three",
|
|
122
|
-
query: {
|
|
123
|
-
name: "byted_likely"
|
|
124
|
-
},
|
|
125
|
-
headers: {
|
|
126
|
-
age: "19"
|
|
127
|
-
}
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
url: "/level-three",
|
|
131
|
-
query: {
|
|
132
|
-
name: "byted_likely"
|
|
133
|
-
},
|
|
134
|
-
headers: {}
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
url: "/level-three",
|
|
138
|
-
query: {
|
|
139
|
-
name: "not_byted"
|
|
140
|
-
},
|
|
141
|
-
headers: {
|
|
142
|
-
age: "19"
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
]
|
|
146
|
-
];
|
|
147
|
-
export { matchedCacheableAry };
|
|
@@ -1,346 +0,0 @@
|
|
|
1
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
-
try {
|
|
3
|
-
var info = gen[key](arg);
|
|
4
|
-
var value = info.value;
|
|
5
|
-
} catch (error) {
|
|
6
|
-
reject(error);
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
if (info.done) {
|
|
10
|
-
resolve(value);
|
|
11
|
-
} else {
|
|
12
|
-
Promise.resolve(value).then(_next, _throw);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
function _asyncToGenerator(fn) {
|
|
16
|
-
return function() {
|
|
17
|
-
var self = this, args = arguments;
|
|
18
|
-
return new Promise(function(resolve, reject) {
|
|
19
|
-
var gen = fn.apply(self, args);
|
|
20
|
-
function _next(value) {
|
|
21
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
-
}
|
|
23
|
-
function _throw(err) {
|
|
24
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
-
}
|
|
26
|
-
_next(undefined);
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
function _defineProperty(obj, key, value) {
|
|
31
|
-
if (key in obj) {
|
|
32
|
-
Object.defineProperty(obj, key, {
|
|
33
|
-
value: value,
|
|
34
|
-
enumerable: true,
|
|
35
|
-
configurable: true,
|
|
36
|
-
writable: true
|
|
37
|
-
});
|
|
38
|
-
} else {
|
|
39
|
-
obj[key] = value;
|
|
40
|
-
}
|
|
41
|
-
return obj;
|
|
42
|
-
}
|
|
43
|
-
function _objectSpread(target) {
|
|
44
|
-
for(var i = 1; i < arguments.length; i++){
|
|
45
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
46
|
-
var ownKeys = Object.keys(source);
|
|
47
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
48
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
49
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
50
|
-
}));
|
|
51
|
-
}
|
|
52
|
-
ownKeys.forEach(function(key) {
|
|
53
|
-
_defineProperty(target, key, source[key]);
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
return target;
|
|
57
|
-
}
|
|
58
|
-
var __generator = this && this.__generator || function(thisArg, body) {
|
|
59
|
-
var f, y, t, g, _ = {
|
|
60
|
-
label: 0,
|
|
61
|
-
sent: function() {
|
|
62
|
-
if (t[0] & 1) throw t[1];
|
|
63
|
-
return t[1];
|
|
64
|
-
},
|
|
65
|
-
trys: [],
|
|
66
|
-
ops: []
|
|
67
|
-
};
|
|
68
|
-
return(g = {
|
|
69
|
-
next: verb(0),
|
|
70
|
-
"throw": verb(1),
|
|
71
|
-
"return": verb(2)
|
|
72
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
73
|
-
return this;
|
|
74
|
-
}), g);
|
|
75
|
-
function verb(n) {
|
|
76
|
-
return function(v) {
|
|
77
|
-
return step([
|
|
78
|
-
n,
|
|
79
|
-
v
|
|
80
|
-
]);
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
function step(op) {
|
|
84
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
85
|
-
while(_)try {
|
|
86
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
87
|
-
if (y = 0, t) op = [
|
|
88
|
-
op[0] & 2,
|
|
89
|
-
t.value
|
|
90
|
-
];
|
|
91
|
-
switch(op[0]){
|
|
92
|
-
case 0:
|
|
93
|
-
case 1:
|
|
94
|
-
t = op;
|
|
95
|
-
break;
|
|
96
|
-
case 4:
|
|
97
|
-
_.label++;
|
|
98
|
-
return {
|
|
99
|
-
value: op[1],
|
|
100
|
-
done: false
|
|
101
|
-
};
|
|
102
|
-
case 5:
|
|
103
|
-
_.label++;
|
|
104
|
-
y = op[1];
|
|
105
|
-
op = [
|
|
106
|
-
0
|
|
107
|
-
];
|
|
108
|
-
continue;
|
|
109
|
-
case 7:
|
|
110
|
-
op = _.ops.pop();
|
|
111
|
-
_.trys.pop();
|
|
112
|
-
continue;
|
|
113
|
-
default:
|
|
114
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
115
|
-
_ = 0;
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
119
|
-
_.label = op[1];
|
|
120
|
-
break;
|
|
121
|
-
}
|
|
122
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
123
|
-
_.label = t[1];
|
|
124
|
-
t = op;
|
|
125
|
-
break;
|
|
126
|
-
}
|
|
127
|
-
if (t && _.label < t[2]) {
|
|
128
|
-
_.label = t[2];
|
|
129
|
-
_.ops.push(op);
|
|
130
|
-
break;
|
|
131
|
-
}
|
|
132
|
-
if (t[2]) _.ops.pop();
|
|
133
|
-
_.trys.pop();
|
|
134
|
-
continue;
|
|
135
|
-
}
|
|
136
|
-
op = body.call(thisArg, _);
|
|
137
|
-
} catch (e) {
|
|
138
|
-
op = [
|
|
139
|
-
6,
|
|
140
|
-
e
|
|
141
|
-
];
|
|
142
|
-
y = 0;
|
|
143
|
-
} finally{
|
|
144
|
-
f = t = 0;
|
|
145
|
-
}
|
|
146
|
-
if (op[0] & 5) throw op[1];
|
|
147
|
-
return {
|
|
148
|
-
value: op[0] ? op[1] : void 0,
|
|
149
|
-
done: true
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
import { Transform } from "stream";
|
|
154
|
-
import { ERROR_DIGEST } from "../../../constants";
|
|
155
|
-
import { createCache } from "./spr";
|
|
156
|
-
import { namespaceHash, withCoalescedInvoke } from "./util";
|
|
157
|
-
var cache_default = function(renderFn, ctx) {
|
|
158
|
-
var sprCache = createCache();
|
|
159
|
-
var doRender = function() {
|
|
160
|
-
var _ref = _asyncToGenerator(function(context) {
|
|
161
|
-
var cacheContext, cacheFile, renderResult, cacheHash, renderResult1, render;
|
|
162
|
-
function afterRender(source, onAfterRender) {
|
|
163
|
-
return _afterRender.apply(this, arguments);
|
|
164
|
-
}
|
|
165
|
-
function _afterRender() {
|
|
166
|
-
_afterRender = _asyncToGenerator(function(source, onAfterRender) {
|
|
167
|
-
var htmlForStream, cacheStream;
|
|
168
|
-
return __generator(this, function(_state) {
|
|
169
|
-
switch(_state.label){
|
|
170
|
-
case 0:
|
|
171
|
-
if (!source) {
|
|
172
|
-
return [
|
|
173
|
-
2,
|
|
174
|
-
""
|
|
175
|
-
];
|
|
176
|
-
}
|
|
177
|
-
if (!(typeof source === "string")) return [
|
|
178
|
-
3,
|
|
179
|
-
2
|
|
180
|
-
];
|
|
181
|
-
return [
|
|
182
|
-
4,
|
|
183
|
-
onAfterRender(source)
|
|
184
|
-
];
|
|
185
|
-
case 1:
|
|
186
|
-
_state.sent();
|
|
187
|
-
return [
|
|
188
|
-
2,
|
|
189
|
-
source
|
|
190
|
-
];
|
|
191
|
-
case 2:
|
|
192
|
-
htmlForStream = "";
|
|
193
|
-
cacheStream = new Transform({
|
|
194
|
-
write: function write(chunk, _, callback) {
|
|
195
|
-
htmlForStream += chunk.toString();
|
|
196
|
-
this.push(chunk);
|
|
197
|
-
callback();
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
cacheStream.on("close", function() {
|
|
201
|
-
return onAfterRender(htmlForStream);
|
|
202
|
-
});
|
|
203
|
-
return [
|
|
204
|
-
2,
|
|
205
|
-
source(cacheStream)
|
|
206
|
-
];
|
|
207
|
-
case 3:
|
|
208
|
-
return [
|
|
209
|
-
2
|
|
210
|
-
];
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
});
|
|
214
|
-
return _afterRender.apply(this, arguments);
|
|
215
|
-
}
|
|
216
|
-
function saveHtmlIntoCache(html) {
|
|
217
|
-
return _saveHtmlIntoCache.apply(this, arguments);
|
|
218
|
-
}
|
|
219
|
-
function _saveHtmlIntoCache() {
|
|
220
|
-
_saveHtmlIntoCache = _asyncToGenerator(function(html) {
|
|
221
|
-
var cacheConfig;
|
|
222
|
-
return __generator(this, function(_state) {
|
|
223
|
-
switch(_state.label){
|
|
224
|
-
case 0:
|
|
225
|
-
cacheConfig = context.cacheConfig;
|
|
226
|
-
if (!(html && cacheConfig)) return [
|
|
227
|
-
3,
|
|
228
|
-
2
|
|
229
|
-
];
|
|
230
|
-
return [
|
|
231
|
-
4,
|
|
232
|
-
sprCache.set(cacheContext, html, cacheConfig)
|
|
233
|
-
];
|
|
234
|
-
case 1:
|
|
235
|
-
_state.sent();
|
|
236
|
-
_state.label = 2;
|
|
237
|
-
case 2:
|
|
238
|
-
return [
|
|
239
|
-
2
|
|
240
|
-
];
|
|
241
|
-
}
|
|
242
|
-
});
|
|
243
|
-
});
|
|
244
|
-
return _saveHtmlIntoCache.apply(this, arguments);
|
|
245
|
-
}
|
|
246
|
-
return __generator(this, function(_state) {
|
|
247
|
-
switch(_state.label){
|
|
248
|
-
case 0:
|
|
249
|
-
cacheContext = _objectSpread({
|
|
250
|
-
entry: context.entryName
|
|
251
|
-
}, context.request);
|
|
252
|
-
return [
|
|
253
|
-
4,
|
|
254
|
-
sprCache.get(cacheContext)
|
|
255
|
-
];
|
|
256
|
-
case 1:
|
|
257
|
-
cacheFile = _state.sent();
|
|
258
|
-
if (!!cacheFile) return [
|
|
259
|
-
3,
|
|
260
|
-
3
|
|
261
|
-
];
|
|
262
|
-
return [
|
|
263
|
-
4,
|
|
264
|
-
renderFn(context)
|
|
265
|
-
];
|
|
266
|
-
case 2:
|
|
267
|
-
renderResult = _state.sent();
|
|
268
|
-
return [
|
|
269
|
-
2,
|
|
270
|
-
afterRender(renderResult, saveHtmlIntoCache)
|
|
271
|
-
];
|
|
272
|
-
case 3:
|
|
273
|
-
cacheHash = cacheFile === null || cacheFile === void 0 ? void 0 : cacheFile.hash;
|
|
274
|
-
if (!cacheFile.isGarbage) return [
|
|
275
|
-
3,
|
|
276
|
-
5
|
|
277
|
-
];
|
|
278
|
-
return [
|
|
279
|
-
4,
|
|
280
|
-
renderFn(context)
|
|
281
|
-
];
|
|
282
|
-
case 4:
|
|
283
|
-
renderResult1 = _state.sent();
|
|
284
|
-
return [
|
|
285
|
-
2,
|
|
286
|
-
afterRender(renderResult1, saveHtmlIntoCache)
|
|
287
|
-
];
|
|
288
|
-
case 5:
|
|
289
|
-
if (cacheFile.isStale) {
|
|
290
|
-
render = withCoalescedInvoke(function() {
|
|
291
|
-
return renderFn(context);
|
|
292
|
-
}).bind(null, namespaceHash("render", cacheFile.hash), []);
|
|
293
|
-
render().then(function() {
|
|
294
|
-
var _ref = _asyncToGenerator(function(res) {
|
|
295
|
-
var cacheConfig;
|
|
296
|
-
return __generator(this, function(_state) {
|
|
297
|
-
if (res.value && res.isOrigin) {
|
|
298
|
-
cacheConfig = context.cacheConfig;
|
|
299
|
-
if (cacheConfig) {
|
|
300
|
-
afterRender(res.value, function() {
|
|
301
|
-
var _ref = _asyncToGenerator(function(html) {
|
|
302
|
-
return __generator(this, function(_state) {
|
|
303
|
-
sprCache.set(cacheContext, html, cacheConfig);
|
|
304
|
-
return [
|
|
305
|
-
2
|
|
306
|
-
];
|
|
307
|
-
});
|
|
308
|
-
});
|
|
309
|
-
return function(html) {
|
|
310
|
-
return _ref.apply(this, arguments);
|
|
311
|
-
};
|
|
312
|
-
}());
|
|
313
|
-
} else {
|
|
314
|
-
sprCache.del(cacheContext, cacheHash);
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
return [
|
|
318
|
-
2
|
|
319
|
-
];
|
|
320
|
-
});
|
|
321
|
-
});
|
|
322
|
-
return function(res) {
|
|
323
|
-
return _ref.apply(this, arguments);
|
|
324
|
-
};
|
|
325
|
-
}()).catch(function(e) {
|
|
326
|
-
sprCache.del(cacheContext, cacheHash);
|
|
327
|
-
ctx.error(ERROR_DIGEST.ERENDER, e);
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
_state.label = 6;
|
|
331
|
-
case 6:
|
|
332
|
-
ctx.res.setHeader("x-modern-spr", "1");
|
|
333
|
-
return [
|
|
334
|
-
2,
|
|
335
|
-
cacheFile.content
|
|
336
|
-
];
|
|
337
|
-
}
|
|
338
|
-
});
|
|
339
|
-
});
|
|
340
|
-
return function doRender(context) {
|
|
341
|
-
return _ref.apply(this, arguments);
|
|
342
|
-
};
|
|
343
|
-
}();
|
|
344
|
-
return doRender;
|
|
345
|
-
};
|
|
346
|
-
export { cache_default as default };
|