@modern-js/prod-server 2.4.0 → 2.5.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 +27 -0
- package/dist/{js/node → cjs}/constants.js +0 -0
- package/dist/{js/node → cjs}/index.js +0 -0
- package/dist/{js/node → cjs}/libs/context/context.js +0 -0
- package/dist/{js/node → cjs}/libs/context/index.js +0 -0
- package/dist/{js/node → cjs}/libs/hook-api/index.js +12 -25
- package/dist/{js/node → cjs}/libs/hook-api/route.js +0 -0
- package/dist/{js/node → cjs}/libs/hook-api/template.js +0 -0
- package/dist/{js/node → cjs}/libs/loadConfig.js +6 -21
- package/dist/cjs/libs/logger.js +122 -0
- package/dist/{js/node → cjs}/libs/metrics.js +0 -0
- package/dist/{js/node → cjs}/libs/proxy.js +6 -39
- package/dist/{js/node → cjs}/libs/render/cache/__tests__/cache.fun.test.js +12 -34
- package/dist/{js/node → cjs}/libs/render/cache/__tests__/cache.test.js +43 -78
- package/dist/{js/node → cjs}/libs/render/cache/__tests__/cacheable.js +0 -0
- package/dist/{js/node → cjs}/libs/render/cache/__tests__/error-configuration.js +0 -0
- package/dist/{js/node → cjs}/libs/render/cache/__tests__/matched-cache.js +0 -0
- package/dist/cjs/libs/render/cache/index.js +97 -0
- package/dist/cjs/libs/render/cache/page-caches/index.js +33 -0
- package/dist/{js/node → cjs}/libs/render/cache/page-caches/lru.js +0 -0
- package/dist/{js/node → cjs}/libs/render/cache/spr.js +69 -97
- package/dist/{js/node → cjs}/libs/render/cache/type.js +0 -0
- package/dist/{js/node → cjs}/libs/render/cache/util.js +19 -41
- package/dist/cjs/libs/render/index.js +93 -0
- package/dist/{js/node → cjs}/libs/render/measure.js +6 -21
- package/dist/{js/node → cjs}/libs/render/reader.js +24 -46
- package/dist/{js/node → cjs}/libs/render/ssr.js +3 -23
- package/dist/{js/node → cjs}/libs/render/static.js +22 -44
- package/dist/{js/node → cjs}/libs/render/type.js +0 -0
- package/dist/{js/node → cjs}/libs/route/index.js +0 -0
- package/dist/{js/node → cjs}/libs/route/matcher.js +0 -0
- package/dist/{js/node → cjs}/libs/route/route.js +0 -0
- package/dist/{js/node → cjs}/libs/serve-file.js +2 -22
- package/dist/{js/node → cjs}/server/index.js +56 -106
- package/dist/{js/node → cjs}/server/modern-server-split.js +9 -40
- package/dist/cjs/server/modern-server.js +490 -0
- package/dist/{js/node → cjs}/type.js +0 -0
- package/dist/{js/node → cjs}/utils.js +1 -15
- package/dist/{js/node → cjs}/worker-server.js +51 -35
- package/dist/{js/treeshaking → esm}/constants.js +0 -0
- package/dist/{js/treeshaking → esm}/index.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/context/context.js +2 -2
- package/dist/{js/treeshaking → esm}/libs/context/index.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/hook-api/index.js +1 -1
- package/dist/{js/treeshaking → esm}/libs/hook-api/route.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/hook-api/template.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/loadConfig.js +0 -0
- package/dist/esm/libs/logger.js +205 -0
- package/dist/{js/treeshaking → esm}/libs/metrics.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/proxy.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/render/cache/__tests__/cache.fun.test.js +3 -3
- package/dist/{js/treeshaking → esm}/libs/render/cache/__tests__/cache.test.js +2 -2
- package/dist/{js/treeshaking → esm}/libs/render/cache/__tests__/cacheable.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/render/cache/__tests__/error-configuration.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/render/cache/__tests__/matched-cache.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/render/cache/index.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/render/cache/page-caches/index.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/render/cache/page-caches/lru.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/render/cache/spr.js +8 -8
- package/dist/{js/treeshaking → esm}/libs/render/cache/type.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/render/cache/util.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/render/index.js +4 -3
- package/dist/{js/treeshaking → esm}/libs/render/measure.js +2 -2
- package/dist/{js/treeshaking → esm}/libs/render/reader.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/render/ssr.js +3 -3
- package/dist/{js/treeshaking → esm}/libs/render/static.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/render/type.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/route/index.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/route/matcher.js +2 -2
- package/dist/{js/treeshaking → esm}/libs/route/route.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/serve-file.js +2 -2
- package/dist/{js/treeshaking → esm}/server/index.js +3 -3
- package/dist/{js/treeshaking → esm}/server/modern-server-split.js +0 -0
- package/dist/{js/treeshaking → esm}/server/modern-server.js +21 -15
- package/dist/{js/treeshaking → esm}/type.js +0 -0
- package/dist/{js/treeshaking → esm}/utils.js +1 -1
- package/dist/{js/treeshaking → esm}/worker-server.js +64 -8
- package/dist/{js/modern → esm-node}/constants.js +0 -0
- package/dist/{js/modern → esm-node}/index.js +0 -0
- package/dist/{js/modern → esm-node}/libs/context/context.js +0 -0
- package/dist/{js/modern → esm-node}/libs/context/index.js +0 -0
- package/dist/{js/modern → esm-node}/libs/hook-api/index.js +12 -27
- package/dist/{js/modern → esm-node}/libs/hook-api/route.js +0 -0
- package/dist/{js/modern → esm-node}/libs/hook-api/template.js +0 -0
- package/dist/esm-node/libs/loadConfig.js +45 -0
- package/dist/esm-node/libs/logger.js +98 -0
- package/dist/{js/modern → esm-node}/libs/metrics.js +0 -0
- package/dist/{js/modern → esm-node}/libs/proxy.js +6 -41
- package/dist/esm-node/libs/render/cache/__tests__/cache.fun.test.js +83 -0
- package/dist/esm-node/libs/render/cache/__tests__/cache.test.js +210 -0
- package/dist/{js/modern → esm-node}/libs/render/cache/__tests__/cacheable.js +0 -0
- package/dist/{js/modern → esm-node}/libs/render/cache/__tests__/error-configuration.js +0 -0
- package/dist/{js/modern → esm-node}/libs/render/cache/__tests__/matched-cache.js +0 -0
- package/dist/esm-node/libs/render/cache/index.js +76 -0
- package/dist/esm-node/libs/render/cache/page-caches/index.js +10 -0
- package/dist/{js/modern → esm-node}/libs/render/cache/page-caches/lru.js +0 -0
- package/dist/{js/modern → esm-node}/libs/render/cache/spr.js +69 -97
- package/dist/{js/modern → esm-node}/libs/render/cache/type.js +0 -0
- package/dist/{js/modern → esm-node}/libs/render/cache/util.js +19 -41
- package/dist/esm-node/libs/render/index.js +64 -0
- package/dist/{js/modern → esm-node}/libs/render/measure.js +6 -23
- package/dist/esm-node/libs/render/reader.js +85 -0
- package/dist/{js/modern → esm-node}/libs/render/ssr.js +3 -23
- package/dist/esm-node/libs/render/static.js +38 -0
- package/dist/{js/modern → esm-node}/libs/render/type.js +0 -0
- package/dist/{js/modern → esm-node}/libs/route/index.js +0 -0
- package/dist/{js/modern → esm-node}/libs/route/matcher.js +0 -0
- package/dist/{js/modern → esm-node}/libs/route/route.js +0 -0
- package/dist/{js/modern → esm-node}/libs/serve-file.js +2 -22
- package/dist/esm-node/server/index.js +156 -0
- package/dist/esm-node/server/modern-server-split.js +43 -0
- package/dist/esm-node/server/modern-server.js +483 -0
- package/dist/{js/modern → esm-node}/type.js +0 -0
- package/dist/{js/modern → esm-node}/utils.js +1 -17
- package/dist/esm-node/worker-server.js +69 -0
- package/dist/types/libs/context/context.d.ts +1 -1
- package/dist/types/libs/logger.d.ts +63 -0
- package/dist/types/libs/render/index.d.ts +3 -1
- package/dist/types/utils.d.ts +1 -1
- package/dist/types/worker-server.d.ts +2 -1
- package/package.json +15 -16
- package/dist/js/modern/libs/loadConfig.js +0 -62
- 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/index.js +0 -115
- package/dist/js/modern/libs/render/cache/page-caches/index.js +0 -32
- package/dist/js/modern/libs/render/index.js +0 -84
- package/dist/js/modern/libs/render/reader.js +0 -107
- package/dist/js/modern/libs/render/static.js +0 -60
- 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 -548
- package/dist/js/modern/worker-server.js +0 -54
- 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/index.js +0 -113
- package/dist/js/node/server/modern-server.js +0 -553
|
@@ -1,55 +1,20 @@
|
|
|
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
1
|
var import_spr = require("../spr");
|
|
38
2
|
var import_error_configuration = require("./error-configuration");
|
|
39
3
|
var import_cacheable = require("./cacheable");
|
|
40
4
|
var import_matched_cache = require("./matched-cache");
|
|
41
|
-
const createCacheConfig = (config = {}) =>
|
|
5
|
+
const createCacheConfig = (config = {}) => ({
|
|
42
6
|
excludes: null,
|
|
43
7
|
includes: null,
|
|
44
8
|
interval: 10,
|
|
45
9
|
staleLimit: false,
|
|
46
10
|
level: 0,
|
|
47
11
|
fallback: false,
|
|
48
|
-
matches: null
|
|
49
|
-
|
|
12
|
+
matches: null,
|
|
13
|
+
...config
|
|
14
|
+
});
|
|
50
15
|
jest.setTimeout(6e4);
|
|
51
16
|
describe("cache", () => {
|
|
52
|
-
it("should cache correctly", () =>
|
|
17
|
+
it("should cache correctly", async () => {
|
|
53
18
|
(0, import_spr.destroyCache)();
|
|
54
19
|
const cache = (0, import_spr.createCache)();
|
|
55
20
|
const context = {
|
|
@@ -60,12 +25,12 @@ describe("cache", () => {
|
|
|
60
25
|
};
|
|
61
26
|
const content = "hello";
|
|
62
27
|
const cacheConfig = createCacheConfig();
|
|
63
|
-
|
|
64
|
-
const cacheResult =
|
|
28
|
+
await cache.set(context, content, cacheConfig, true);
|
|
29
|
+
const cacheResult = await cache.get(context);
|
|
65
30
|
expect(cacheResult).not.toBe(null);
|
|
66
31
|
expect(cacheResult == null ? void 0 : cacheResult.content).toBe("hello");
|
|
67
|
-
})
|
|
68
|
-
it("should ignore cache set when cache config not exist", () =>
|
|
32
|
+
});
|
|
33
|
+
it("should ignore cache set when cache config not exist", async () => {
|
|
69
34
|
(0, import_spr.destroyCache)();
|
|
70
35
|
(0, import_spr.destroyCache)();
|
|
71
36
|
const cache = (0, import_spr.createCache)();
|
|
@@ -76,10 +41,10 @@ describe("cache", () => {
|
|
|
76
41
|
headers: {}
|
|
77
42
|
};
|
|
78
43
|
const content = "hello";
|
|
79
|
-
const shouldCache =
|
|
44
|
+
const shouldCache = await cache.set(context, content, null, true);
|
|
80
45
|
expect(shouldCache).toBe(false);
|
|
81
|
-
})
|
|
82
|
-
it("should calcual cache key error", () =>
|
|
46
|
+
});
|
|
47
|
+
it("should calcual cache key error", async () => {
|
|
83
48
|
(0, import_spr.destroyCache)();
|
|
84
49
|
const cache = (0, import_spr.createCache)();
|
|
85
50
|
const content = "hello";
|
|
@@ -92,11 +57,11 @@ describe("cache", () => {
|
|
|
92
57
|
query: {},
|
|
93
58
|
headers: {}
|
|
94
59
|
};
|
|
95
|
-
const shouldCache =
|
|
60
|
+
const shouldCache = await cache.set(context, content, cacheConfig);
|
|
96
61
|
expect(shouldCache).toBe(false);
|
|
97
62
|
}
|
|
98
|
-
})
|
|
99
|
-
it("should get nothing for diff requestKey", () =>
|
|
63
|
+
});
|
|
64
|
+
it("should get nothing for diff requestKey", async () => {
|
|
100
65
|
(0, import_spr.destroyCache)();
|
|
101
66
|
const cache = (0, import_spr.createCache)();
|
|
102
67
|
const context = {
|
|
@@ -110,17 +75,17 @@ describe("cache", () => {
|
|
|
110
75
|
level: 1,
|
|
111
76
|
includes: { query: ["name"] }
|
|
112
77
|
});
|
|
113
|
-
|
|
78
|
+
await cache.set(context, content, cacheConfig, true);
|
|
114
79
|
const context_req = {
|
|
115
80
|
entry: "",
|
|
116
81
|
pathname: "/home",
|
|
117
82
|
query: {},
|
|
118
83
|
headers: {}
|
|
119
84
|
};
|
|
120
|
-
const cacheResult =
|
|
85
|
+
const cacheResult = await cache.get(context_req);
|
|
121
86
|
expect(cacheResult).toBe(null);
|
|
122
|
-
})
|
|
123
|
-
it("should get nothing for diff cacheHash", () =>
|
|
87
|
+
});
|
|
88
|
+
it("should get nothing for diff cacheHash", async () => {
|
|
124
89
|
(0, import_spr.destroyCache)();
|
|
125
90
|
const cache = (0, import_spr.createCache)();
|
|
126
91
|
const context = {
|
|
@@ -134,17 +99,17 @@ describe("cache", () => {
|
|
|
134
99
|
level: 1,
|
|
135
100
|
includes: { query: ["name"] }
|
|
136
101
|
});
|
|
137
|
-
|
|
102
|
+
await cache.set(context, content, cacheConfig, true);
|
|
138
103
|
const context_req = {
|
|
139
104
|
entry: "",
|
|
140
105
|
pathname: "",
|
|
141
106
|
query: { name: "zll" },
|
|
142
107
|
headers: {}
|
|
143
108
|
};
|
|
144
|
-
const cacheResult =
|
|
109
|
+
const cacheResult = await cache.get(context_req);
|
|
145
110
|
expect(cacheResult).toBe(null);
|
|
146
|
-
})
|
|
147
|
-
it("should get cache correctly", () =>
|
|
111
|
+
});
|
|
112
|
+
it("should get cache correctly", async () => {
|
|
148
113
|
(0, import_spr.destroyCache)();
|
|
149
114
|
const cache = (0, import_spr.createCache)();
|
|
150
115
|
for (const cacheable of import_cacheable.cacheabelAry) {
|
|
@@ -155,12 +120,12 @@ describe("cache", () => {
|
|
|
155
120
|
headers: cacheable.requestOpt.headers || {}
|
|
156
121
|
};
|
|
157
122
|
const cacheConfig = createCacheConfig(cacheable.cacheConfig || {});
|
|
158
|
-
|
|
159
|
-
const cacheResult =
|
|
123
|
+
await cache.set(context, cacheable.content, cacheConfig, true);
|
|
124
|
+
const cacheResult = await cache.get(context);
|
|
160
125
|
expect(cacheResult == null ? void 0 : cacheResult.content).toBe(cacheable.content);
|
|
161
126
|
}
|
|
162
|
-
})
|
|
163
|
-
it("should match cache correctly", () =>
|
|
127
|
+
});
|
|
128
|
+
it("should match cache correctly", async () => {
|
|
164
129
|
(0, import_spr.destroyCache)();
|
|
165
130
|
const cache = (0, import_spr.createCache)();
|
|
166
131
|
for (const cacheable of import_matched_cache.matchedCacheableAry) {
|
|
@@ -172,14 +137,14 @@ describe("cache", () => {
|
|
|
172
137
|
query: requestOpt.query,
|
|
173
138
|
headers: requestOpt.headers
|
|
174
139
|
};
|
|
175
|
-
|
|
140
|
+
await cache.set(context, content, createCacheConfig(cacheConfig), true);
|
|
176
141
|
const matchContext = {
|
|
177
142
|
entry: "",
|
|
178
143
|
pathname: matchOne.url,
|
|
179
144
|
query: matchOne.query,
|
|
180
145
|
headers: matchOne.headers
|
|
181
146
|
};
|
|
182
|
-
const cacheResult =
|
|
147
|
+
const cacheResult = await cache.get(matchContext);
|
|
183
148
|
expect(cacheResult == null ? void 0 : cacheResult.content).toBe(content);
|
|
184
149
|
for (const notMatch of other) {
|
|
185
150
|
const notMatchContext = {
|
|
@@ -188,12 +153,12 @@ describe("cache", () => {
|
|
|
188
153
|
query: notMatch.query,
|
|
189
154
|
headers: notMatch.headers
|
|
190
155
|
};
|
|
191
|
-
const nothing =
|
|
156
|
+
const nothing = await cache.get(notMatchContext);
|
|
192
157
|
expect(nothing).toBe(null);
|
|
193
158
|
}
|
|
194
159
|
}
|
|
195
|
-
})
|
|
196
|
-
it("should stale cache correctly", () =>
|
|
160
|
+
});
|
|
161
|
+
it("should stale cache correctly", async () => {
|
|
197
162
|
(0, import_spr.destroyCache)();
|
|
198
163
|
const cache = (0, import_spr.createCache)();
|
|
199
164
|
const context = {
|
|
@@ -204,19 +169,19 @@ describe("cache", () => {
|
|
|
204
169
|
};
|
|
205
170
|
const config = createCacheConfig({ interval: 5 });
|
|
206
171
|
const content = "hello";
|
|
207
|
-
const shouldCache =
|
|
172
|
+
const shouldCache = await cache.set(context, content, config, true);
|
|
208
173
|
expect(shouldCache.value).toBe(true);
|
|
209
|
-
const freshResult =
|
|
174
|
+
const freshResult = await cache.get(context);
|
|
210
175
|
expect(freshResult == null ? void 0 : freshResult.isStale).toBe(false);
|
|
211
|
-
|
|
176
|
+
await new Promise((resolve) => {
|
|
212
177
|
setTimeout(() => {
|
|
213
178
|
resolve();
|
|
214
179
|
}, 6e3);
|
|
215
180
|
});
|
|
216
|
-
const staleResult =
|
|
181
|
+
const staleResult = await cache.get(context);
|
|
217
182
|
expect(staleResult == null ? void 0 : staleResult.isStale).toBe(true);
|
|
218
|
-
})
|
|
219
|
-
it("should garbage cache correctly", () =>
|
|
183
|
+
});
|
|
184
|
+
it("should garbage cache correctly", async () => {
|
|
220
185
|
(0, import_spr.destroyCache)();
|
|
221
186
|
const cache = (0, import_spr.createCache)();
|
|
222
187
|
const context = {
|
|
@@ -230,16 +195,16 @@ describe("cache", () => {
|
|
|
230
195
|
staleLimit: 8
|
|
231
196
|
});
|
|
232
197
|
const content = "hello";
|
|
233
|
-
const shouldCache =
|
|
198
|
+
const shouldCache = await cache.set(context, content, config, true);
|
|
234
199
|
expect(shouldCache.value).toBe(true);
|
|
235
|
-
const freshResult =
|
|
200
|
+
const freshResult = await cache.get(context);
|
|
236
201
|
expect(freshResult == null ? void 0 : freshResult.isGarbage).toBe(false);
|
|
237
|
-
|
|
202
|
+
await new Promise((resolve) => {
|
|
238
203
|
setTimeout(() => {
|
|
239
204
|
resolve();
|
|
240
205
|
}, 1e4);
|
|
241
206
|
});
|
|
242
|
-
const staleResult =
|
|
207
|
+
const staleResult = await cache.get(context);
|
|
243
208
|
expect(staleResult == null ? void 0 : staleResult.isGarbage).toBe(true);
|
|
244
|
-
})
|
|
209
|
+
});
|
|
245
210
|
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,97 @@
|
|
|
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 cache_exports = {};
|
|
19
|
+
__export(cache_exports, {
|
|
20
|
+
default: () => cache_default
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(cache_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 cache_default = (renderFn, ctx) => {
|
|
28
|
+
const sprCache = (0, import_spr.createCache)();
|
|
29
|
+
const doRender = async (context) => {
|
|
30
|
+
const cacheContext = {
|
|
31
|
+
entry: context.entryName,
|
|
32
|
+
...context.request
|
|
33
|
+
};
|
|
34
|
+
const cacheFile = await sprCache.get(cacheContext);
|
|
35
|
+
async function afterRender(source, onAfterRender) {
|
|
36
|
+
if (!source) {
|
|
37
|
+
return "";
|
|
38
|
+
}
|
|
39
|
+
if (typeof source === "string") {
|
|
40
|
+
await onAfterRender(source);
|
|
41
|
+
return source;
|
|
42
|
+
} else {
|
|
43
|
+
let htmlForStream = "";
|
|
44
|
+
const cacheStream = new import_stream.Transform({
|
|
45
|
+
write(chunk, _, callback) {
|
|
46
|
+
htmlForStream += chunk.toString();
|
|
47
|
+
this.push(chunk);
|
|
48
|
+
callback();
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
cacheStream.on("close", () => onAfterRender(htmlForStream));
|
|
52
|
+
return source(cacheStream);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
async function saveHtmlIntoCache(html) {
|
|
56
|
+
const { cacheConfig } = context;
|
|
57
|
+
if (html && cacheConfig) {
|
|
58
|
+
await sprCache.set(cacheContext, html, cacheConfig);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (!cacheFile) {
|
|
62
|
+
const renderResult = await renderFn(context);
|
|
63
|
+
return afterRender(renderResult, saveHtmlIntoCache);
|
|
64
|
+
}
|
|
65
|
+
const cacheHash = cacheFile == null ? void 0 : cacheFile.hash;
|
|
66
|
+
if (cacheFile.isGarbage) {
|
|
67
|
+
const renderResult = await renderFn(context);
|
|
68
|
+
return afterRender(renderResult, saveHtmlIntoCache);
|
|
69
|
+
} else if (cacheFile.isStale) {
|
|
70
|
+
const render = (0, import_util.withCoalescedInvoke)(() => renderFn(context)).bind(
|
|
71
|
+
null,
|
|
72
|
+
(0, import_util.namespaceHash)("render", cacheFile.hash),
|
|
73
|
+
[]
|
|
74
|
+
);
|
|
75
|
+
render().then(async (res) => {
|
|
76
|
+
if (res.value && res.isOrigin) {
|
|
77
|
+
const { cacheConfig } = context;
|
|
78
|
+
if (cacheConfig) {
|
|
79
|
+
afterRender(res.value, async (html) => {
|
|
80
|
+
sprCache.set(cacheContext, html, cacheConfig);
|
|
81
|
+
});
|
|
82
|
+
} else {
|
|
83
|
+
sprCache.del(cacheContext, cacheHash);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}).catch((e) => {
|
|
87
|
+
sprCache.del(cacheContext, cacheHash);
|
|
88
|
+
ctx.error(import_constants.ERROR_DIGEST.ERENDER, e);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
ctx.res.setHeader("x-modern-spr", "1");
|
|
92
|
+
return cacheFile.content;
|
|
93
|
+
};
|
|
94
|
+
return doRender;
|
|
95
|
+
};
|
|
96
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
97
|
+
0 && (module.exports = {});
|
|
@@ -0,0 +1,33 @@
|
|
|
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 page_caches_exports = {};
|
|
19
|
+
__export(page_caches_exports, {
|
|
20
|
+
createPageCaches: () => createPageCaches
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(page_caches_exports);
|
|
23
|
+
var import_lru = require("./lru");
|
|
24
|
+
async function createPageCaches(max) {
|
|
25
|
+
const constructorOptions = { max };
|
|
26
|
+
const cacheInstance = new import_lru.LRUCaches(constructorOptions);
|
|
27
|
+
await cacheInstance.init();
|
|
28
|
+
return cacheInstance;
|
|
29
|
+
}
|
|
30
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
+
0 && (module.exports = {
|
|
32
|
+
createPageCaches
|
|
33
|
+
});
|
|
File without changes
|
|
@@ -21,26 +21,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
21
|
mod
|
|
22
22
|
));
|
|
23
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
24
|
var spr_exports = {};
|
|
45
25
|
__export(spr_exports, {
|
|
46
26
|
createCache: () => createCache,
|
|
@@ -159,15 +139,13 @@ class CacheManager {
|
|
|
159
139
|
const headerFactor = this.factor(headerKeys, requestHeader, headerMatches);
|
|
160
140
|
return headerFactor;
|
|
161
141
|
}
|
|
162
|
-
best(context, cacheKey, data) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
return data.caches.get(cacheHash);
|
|
170
|
-
});
|
|
142
|
+
async best(context, cacheKey, data) {
|
|
143
|
+
const { level } = data;
|
|
144
|
+
const cacheHash = this.find[(0, import_util.fname)(level)](context, cacheKey, data);
|
|
145
|
+
if (!cacheHash) {
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
return data.caches.get(cacheHash);
|
|
171
149
|
}
|
|
172
150
|
createCacheContent(config, caches) {
|
|
173
151
|
return {
|
|
@@ -179,77 +157,71 @@ class CacheManager {
|
|
|
179
157
|
caches
|
|
180
158
|
};
|
|
181
159
|
}
|
|
182
|
-
get(context) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
};
|
|
203
|
-
});
|
|
160
|
+
async get(context) {
|
|
161
|
+
const cacheKey = this.generateRequestKey(context);
|
|
162
|
+
const data = this.cache.get(cacheKey);
|
|
163
|
+
if (!data) {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
const dest = await this.best(context, cacheKey, data);
|
|
167
|
+
if (!dest) {
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
const { expireTime, limitTime, html, cacheHash } = dest;
|
|
171
|
+
const isStale = Date.now() - expireTime > 0;
|
|
172
|
+
const isGarbage = limitTime ? Date.now() - limitTime > 0 : false;
|
|
173
|
+
return {
|
|
174
|
+
content: html || "",
|
|
175
|
+
contentType: import_utils.mime.contentType("html"),
|
|
176
|
+
isStale,
|
|
177
|
+
isGarbage,
|
|
178
|
+
hash: cacheHash
|
|
179
|
+
};
|
|
204
180
|
}
|
|
205
|
-
set(context, html, cacheConfig, sync = false) {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
size
|
|
235
|
-
});
|
|
236
|
-
this.cache.set(cacheKey, next);
|
|
237
|
-
return true;
|
|
181
|
+
async set(context, html, cacheConfig, sync = false) {
|
|
182
|
+
if (!cacheConfig) {
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
const cacheKey = this.generateRequestKey(context);
|
|
186
|
+
let data = this.cache.get(cacheKey);
|
|
187
|
+
if (!data) {
|
|
188
|
+
const caches = await (0, import_page_caches.createPageCaches)(MAX_CACHE_EACH_REQ);
|
|
189
|
+
data = this.createCacheContent(cacheConfig, caches);
|
|
190
|
+
}
|
|
191
|
+
const cacheHash = this.find[(0, import_util.fname)(cacheConfig.level)](
|
|
192
|
+
context,
|
|
193
|
+
cacheKey,
|
|
194
|
+
data
|
|
195
|
+
);
|
|
196
|
+
if (!cacheHash) {
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
const cacheSyncOrAsync = async () => {
|
|
200
|
+
const next = data;
|
|
201
|
+
const limit = cacheConfig.staleLimit;
|
|
202
|
+
const storeHTML = (0, import_util.cacheAddition)(html, cacheHash);
|
|
203
|
+
const size = storeHTML.length;
|
|
204
|
+
await next.caches.set(cacheHash, {
|
|
205
|
+
expireTime: Date.now() + cacheConfig.interval * 1e3,
|
|
206
|
+
limitTime: typeof limit === "number" ? Date.now() + limit * 1e3 : null,
|
|
207
|
+
cacheHash,
|
|
208
|
+
html: storeHTML,
|
|
209
|
+
size
|
|
238
210
|
});
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
211
|
+
this.cache.set(cacheKey, next);
|
|
212
|
+
return true;
|
|
213
|
+
};
|
|
214
|
+
const doCache = (0, import_util.withCoalescedInvoke)(cacheSyncOrAsync).bind(
|
|
215
|
+
null,
|
|
216
|
+
(0, import_util.namespaceHash)("stream", cacheHash),
|
|
217
|
+
[]
|
|
218
|
+
);
|
|
219
|
+
return (0, import_util.maybeSync)(doCache)(sync);
|
|
246
220
|
}
|
|
247
|
-
del(context, cacheHash) {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
data == null ? void 0 : data.caches.del(cacheHash);
|
|
252
|
-
});
|
|
221
|
+
async del(context, cacheHash) {
|
|
222
|
+
const cacheKey = this.generateRequestKey(context);
|
|
223
|
+
const data = this.cache.get(cacheKey);
|
|
224
|
+
data == null ? void 0 : data.caches.del(cacheHash);
|
|
253
225
|
}
|
|
254
226
|
}
|
|
255
227
|
let manager;
|
|
File without changes
|
|
@@ -21,26 +21,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
21
|
mod
|
|
22
22
|
));
|
|
23
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
24
|
var util_exports = {};
|
|
45
25
|
__export(util_exports, {
|
|
46
26
|
cacheAddition: () => cacheAddition,
|
|
@@ -91,28 +71,26 @@ function cacheAddition(html, hash) {
|
|
|
91
71
|
}
|
|
92
72
|
const globalInvokeCache = /* @__PURE__ */ new Map();
|
|
93
73
|
function withCoalescedInvoke(func) {
|
|
94
|
-
return function(key, args) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
throw err;
|
|
112
|
-
});
|
|
113
|
-
globalInvokeCache.set(key, future);
|
|
114
|
-
return future;
|
|
74
|
+
return async function(key, args) {
|
|
75
|
+
const entry = globalInvokeCache.get(key);
|
|
76
|
+
if (entry) {
|
|
77
|
+
return entry.then((res) => ({
|
|
78
|
+
isOrigin: false,
|
|
79
|
+
value: res.value
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
function __wrapper() {
|
|
83
|
+
return func(...args);
|
|
84
|
+
}
|
|
85
|
+
const future = __wrapper().then((res) => {
|
|
86
|
+
globalInvokeCache.delete(key);
|
|
87
|
+
return { isOrigin: true, value: res };
|
|
88
|
+
}).catch((err) => {
|
|
89
|
+
globalInvokeCache.delete(key);
|
|
90
|
+
throw err;
|
|
115
91
|
});
|
|
92
|
+
globalInvokeCache.set(key, future);
|
|
93
|
+
return future;
|
|
116
94
|
};
|
|
117
95
|
}
|
|
118
96
|
function maybeSync(fn) {
|